Class.Team クラスは、Roblox 場プレースのファクションを表します。Teams サービスの唯一の親は、Class.Team サービスです。チームは、開発者を 2つのグループに分割できる 2つのグループに分割できます。チームは、開発者に使用している 2つのグループに分割できます。
- 「箱から出て」機能
- 開発者がゲームにプログラミングできる機能。
組み込みチーム動作 チームの次の機能は、デフォルトで存在し、開発者がカスタムビーハブをプログラミングする必要はありません。
- チームの一部であるとき、プレイヤーのキャラクターの上にある Model の名前は、Team.TeamColor にカラーされます。
- Class.Player.TeamColor を変更すると、Player.Team が対応する Team.TeamColor に切り替えます。
- デフォルトのプレイヤーリストを使用すると、ユーザーはチームとしてグループ化され、表示されます
- Class.Player.Neutral を設定すると、Player はチームとの関連を解除しますが、Player.Team または 1>Class.Player.TeamColor1> は変更されません。
- Class.Player がゲームに参加すると、Team.AutoAssignable を設定しているチームに割り当てられます。Player.Neutral が利用可能でない場合は、1>Class.Player.Neutral1> が設定されます。
- Class.SpawnLocation.Neutral が偽で設定されているとき、 Player.TeamColor が SpawnLocation.TeamColor と一致するプレイヤーのみが、その 1>Class.SpawnLocation1> に生成できます。
- Class.SpawnLocation.AllowTeamChangeOnTouch が Player.TeamColor を変更すると、プレイヤーの SpawnLocation.TeamColor は、そのキャラクターが 1>Class.SpawnLocation1> に触れると 4>Class.SpawnLocation.TeamColor4> に変更されます。
オプションの拡張チーム動作 多くの開発者が、自分のコードのチームに次の機能を追加することを選択しました。
- 武器コードにチェックを実装して、友好の火を防止します。
- ドアや他の機能を実装して、特定のチームだけが使用できるようにします
- チームを定期的に再割り当ててチームのバランスを維残高する
コードサンプル
This code sample includes a simple example of how to re-balance teams. When Team.AutoAssignable is set to true players will be added to Teams in a balanced fashion. However as Players leave the game this can lead to unbalanced teams as players are not reallocated. This code keeps track of the number of players in each team and, when players leave will check to see if the teams need re-balancing.
local Teams = game:GetService("Teams")
-- create two teams
local redTeam = Instance.new("Team")
redTeam.TeamColor = BrickColor.new("Bright red")
redTeam.AutoAssignable = true
redTeam.Name = "Red Team"
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.TeamColor = BrickColor.new("Bright blue")
blueTeam.AutoAssignable = true
blueTeam.Name = "Blue Team"
blueTeam.Parent = Teams
-- start counting the number of players on each team
local numberRed, numberBlue = 0, 0
local function playerAdded(team)
-- increase the team's count by 1
if team == redTeam then
numberRed = numberRed + 1
elseif team == blueTeam then
numberBlue = numberBlue + 1
end
end
local function playerRemoved(team)
-- decrease the team's count by 1
if team == redTeam then
numberRed = numberRed - 1
elseif team == blueTeam then
numberBlue = numberBlue - 1
end
-- check if the teams are unbalanced
local bigTeam, smallTeam = nil, nil
if (numberRed - numberBlue) > 2 then
bigTeam = redTeam
smallTeam = blueTeam
elseif (numberBlue - numberRed) > 2 then
bigTeam = blueTeam
smallTeam = redTeam
end
if bigTeam then
-- pick a random player
local playerList = bigTeam:GetPlayers()
local player = playerList[math.random(1, #playerList)]
-- check the player exists
if player then
-- change the player's team
player.TeamColor = smallTeam.TeamColor
-- respawn the player
player:LoadCharacter()
end
end
end
-- listen for players being added / removed
blueTeam.PlayerAdded:Connect(function(_player)
playerAdded(blueTeam)
end)
blueTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(blueTeam)
end)
redTeam.PlayerAdded:Connect(function(_player)
playerAdded(redTeam)
end)
redTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(redTeam)
end)
This code sample includes a quick function that can be added to weapons in a place to prevent them from team killing. It will return false when the two players are on different teams or if either of them is neutral.
local Players = game:GetService("Players")
function checkTeamKill(playerAttack, playerVictim)
if playerAttack.Team ~= playerVictim.Team or playerAttack.Neutral or playerVictim.Neutral then
return false
end
return true
end
local players = Players:GetPlayers()
checkTeamKill(players[1], players[2])
The following code sample will create a door in the Workspace that can only be walked through by Players on the Bright red team.
local Players = game:GetService("Players")
local door = Instance.new("Part")
door.Anchored = true
door.Size = Vector3.new(7, 10, 1)
door.Position = Vector3.new(0, 5, 0)
door.Parent = workspace
local debounce = false
door.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and player.TeamColor == BrickColor.new("Bright red") then
door.Transparency = 0.5
door.CanCollide = false
task.wait(3)
door.Transparency = 0
door.CanCollide = true
end
end
task.wait(0.5)
debounce = false
end
end)
概要
プロパティ
このプロパティは、Players が参加するときに自動的に Team に置かれるかどうかを決定します。如果複数のチームがこのプロパティを設定している場合、Roblox は、Players が追加されると、チームを自動的にグループ化します。
このプロパティは、Team の色を設定します。チームのメンバーのPlayer.TeamColor プロパティを決定します。また、プレイヤーリストとプレイヤーの頭上の色を決定します。
方法
イベント
Class.Player.Team に割り当てられた Team が、Player.Team と同等の 1>Class.Player.Team1> プロパティを持っている場合、プレイヤーは 4>Class.Player.Team4> に割り当てられたと見なされます。7>Class.Player.Neutral7> が
Class.Player が Team から削除されるときには、Player がゲームを終了するか、1>Class.Player.Neutral1> が 4>Class.Player4> に参加するように設定されている場合があります。
プロパティ
AutoAssignable
このプロパティは、Players が参加するときに自動的に Team に置かれるかどうかを決定します。如果複数のチームがこのプロパティを設定している場合、Roblox は、Players が追加されると、チームを自動的にグループ化します。
Class.Player がゲームに参加すると、Team に Team.AutoAssignable が設定され、最も少ないプレイヤーを持つことができます。如果そのようなチームが利用可能でない場合は、1>Class.Player.Neutral1> が設定されます。
このプロパティを使用すると、プレイヤーが追加されるときにチームを協力させることができます。プレイヤーが削除されるときには何も起きません。これは、開発者がチームバランシングシステムを実装することをお勧めします。
コードサンプル
This code sample includes a simple example of how to re-balance teams. When Team.AutoAssignable is set to true players will be added to Teams in a balanced fashion. However as Players leave the game this can lead to unbalanced teams as players are not reallocated. This code keeps track of the number of players in each team and, when players leave will check to see if the teams need re-balancing.
local Teams = game:GetService("Teams")
-- create two teams
local redTeam = Instance.new("Team")
redTeam.TeamColor = BrickColor.new("Bright red")
redTeam.AutoAssignable = true
redTeam.Name = "Red Team"
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.TeamColor = BrickColor.new("Bright blue")
blueTeam.AutoAssignable = true
blueTeam.Name = "Blue Team"
blueTeam.Parent = Teams
-- start counting the number of players on each team
local numberRed, numberBlue = 0, 0
local function playerAdded(team)
-- increase the team's count by 1
if team == redTeam then
numberRed = numberRed + 1
elseif team == blueTeam then
numberBlue = numberBlue + 1
end
end
local function playerRemoved(team)
-- decrease the team's count by 1
if team == redTeam then
numberRed = numberRed - 1
elseif team == blueTeam then
numberBlue = numberBlue - 1
end
-- check if the teams are unbalanced
local bigTeam, smallTeam = nil, nil
if (numberRed - numberBlue) > 2 then
bigTeam = redTeam
smallTeam = blueTeam
elseif (numberBlue - numberRed) > 2 then
bigTeam = blueTeam
smallTeam = redTeam
end
if bigTeam then
-- pick a random player
local playerList = bigTeam:GetPlayers()
local player = playerList[math.random(1, #playerList)]
-- check the player exists
if player then
-- change the player's team
player.TeamColor = smallTeam.TeamColor
-- respawn the player
player:LoadCharacter()
end
end
end
-- listen for players being added / removed
blueTeam.PlayerAdded:Connect(function(_player)
playerAdded(blueTeam)
end)
blueTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(blueTeam)
end)
redTeam.PlayerAdded:Connect(function(_player)
playerAdded(redTeam)
end)
redTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(redTeam)
end)
TeamColor
このプロパティは、Team の色を設定します。チームのメンバーの Player.TeamColor を決定します。
Roblox(ロブロックス)oblox のデフォルトチーム機能の多くは、チームの名前やオブジェクトではなく、チームの色に基づいています。たとえば、SpawnLocations は、SpawnLocation.TeamColor を通じてチームに割り当てることができます。これは、理由の 1つであり、
チームの一部であるプレイヤーは、チームの TeamColor プロパティに名前の色が変更されます。また、プレイヤーリストのチームヘッドの下に置かれます。
コードサンプル
The following code sample will create a door in the Workspace that can only be walked through by Players on the Bright red team.
local Players = game:GetService("Players")
local door = Instance.new("Part")
door.Anchored = true
door.Size = Vector3.new(7, 10, 1)
door.Position = Vector3.new(0, 5, 0)
door.Parent = workspace
local debounce = false
door.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and player.TeamColor == BrickColor.new("Bright red") then
door.Transparency = 0.5
door.CanCollide = false
task.wait(3)
door.Transparency = 0
door.CanCollide = true
end
end
task.wait(0.5)
debounce = false
end
end)
方法
GetPlayers
Class.Player|Players を Team に割り当てるリストを返します。Player は、1>Class.Player.Team1> プロパティと 4>Class.Player4> のプロパティが等しいときに割り当てられます。7>Class.Player.
この関数には、Team のプレイヤー数をカウントするか、Player をTeam に配置するなど、多くの潜在的な使用があります。
戻り値
Class.Player|Players のアレイを Team に置きます。
コードサンプル
The example below prints the number of players on each Team.
local Teams = game:GetService("Teams")
local teams = Teams:GetTeams()
for _, team in pairs(teams) do
local players = team:GetPlayers()
print("Team", team.Name, "has", #players, "players")
end
イベント
PlayerAdded
Class.Player.Team に割り当てられた Team が、Player.Team と同等の 1>Class.Player.Team1> プロパティを持っている場合、プレイヤーは 4>Class.Player.Team4> に割り当てられたと見なされます。7>Class.Player.Neutral7> が
このイベントはチーム固有であり、特定の Player が特定の Team に参加するときにのみ発動します。このイベントに関連する任意の機能は、Player がチームに参加したプレイヤーの 2>Class.Team2> オブジェクトを通過することです。たとえば:
Team.PlayerAdded:Connect(プレイヤーunction(player) print(プレイヤーlayer.Name.." がチームに参加しました") 終了nd)
パラメータ
コードサンプル
This code sample includes a simple example of how to re-balance teams. When Team.AutoAssignable is set to true players will be added to Teams in a balanced fashion. However as Players leave the game this can lead to unbalanced teams as players are not reallocated. This code keeps track of the number of players in each team and, when players leave will check to see if the teams need re-balancing.
local Teams = game:GetService("Teams")
-- create two teams
local redTeam = Instance.new("Team")
redTeam.TeamColor = BrickColor.new("Bright red")
redTeam.AutoAssignable = true
redTeam.Name = "Red Team"
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.TeamColor = BrickColor.new("Bright blue")
blueTeam.AutoAssignable = true
blueTeam.Name = "Blue Team"
blueTeam.Parent = Teams
-- start counting the number of players on each team
local numberRed, numberBlue = 0, 0
local function playerAdded(team)
-- increase the team's count by 1
if team == redTeam then
numberRed = numberRed + 1
elseif team == blueTeam then
numberBlue = numberBlue + 1
end
end
local function playerRemoved(team)
-- decrease the team's count by 1
if team == redTeam then
numberRed = numberRed - 1
elseif team == blueTeam then
numberBlue = numberBlue - 1
end
-- check if the teams are unbalanced
local bigTeam, smallTeam = nil, nil
if (numberRed - numberBlue) > 2 then
bigTeam = redTeam
smallTeam = blueTeam
elseif (numberBlue - numberRed) > 2 then
bigTeam = blueTeam
smallTeam = redTeam
end
if bigTeam then
-- pick a random player
local playerList = bigTeam:GetPlayers()
local player = playerList[math.random(1, #playerList)]
-- check the player exists
if player then
-- change the player's team
player.TeamColor = smallTeam.TeamColor
-- respawn the player
player:LoadCharacter()
end
end
end
-- listen for players being added / removed
blueTeam.PlayerAdded:Connect(function(_player)
playerAdded(blueTeam)
end)
blueTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(blueTeam)
end)
redTeam.PlayerAdded:Connect(function(_player)
playerAdded(redTeam)
end)
redTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(redTeam)
end)
PlayerRemoved
Class.Player が Team から削除されるときには、Player がゲームを終了するか、1>Class.Player.Neutral1> が 4>Class.Player4> に参加するように設定されている場合があります。
このイベントはチーム固有であり、Player が特定の Team から去るとのみ発動します。このイベントに関連する任意の関数は、チームから去ったプレイヤーの Player オブジェクトを通過します。たとえば:
Team.PlayerRemoved:Connect(プレイヤーunction(player) print(プレイヤーlayer.Name.." がチームを離れました") 終了nd)
パラメータ
Class.Player が削除されました。
コードサンプル
This code sample includes a simple example of how to re-balance teams. When Team.AutoAssignable is set to true players will be added to Teams in a balanced fashion. However as Players leave the game this can lead to unbalanced teams as players are not reallocated. This code keeps track of the number of players in each team and, when players leave will check to see if the teams need re-balancing.
local Teams = game:GetService("Teams")
-- create two teams
local redTeam = Instance.new("Team")
redTeam.TeamColor = BrickColor.new("Bright red")
redTeam.AutoAssignable = true
redTeam.Name = "Red Team"
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.TeamColor = BrickColor.new("Bright blue")
blueTeam.AutoAssignable = true
blueTeam.Name = "Blue Team"
blueTeam.Parent = Teams
-- start counting the number of players on each team
local numberRed, numberBlue = 0, 0
local function playerAdded(team)
-- increase the team's count by 1
if team == redTeam then
numberRed = numberRed + 1
elseif team == blueTeam then
numberBlue = numberBlue + 1
end
end
local function playerRemoved(team)
-- decrease the team's count by 1
if team == redTeam then
numberRed = numberRed - 1
elseif team == blueTeam then
numberBlue = numberBlue - 1
end
-- check if the teams are unbalanced
local bigTeam, smallTeam = nil, nil
if (numberRed - numberBlue) > 2 then
bigTeam = redTeam
smallTeam = blueTeam
elseif (numberBlue - numberRed) > 2 then
bigTeam = blueTeam
smallTeam = redTeam
end
if bigTeam then
-- pick a random player
local playerList = bigTeam:GetPlayers()
local player = playerList[math.random(1, #playerList)]
-- check the player exists
if player then
-- change the player's team
player.TeamColor = smallTeam.TeamColor
-- respawn the player
player:LoadCharacter()
end
end
end
-- listen for players being added / removed
blueTeam.PlayerAdded:Connect(function(_player)
playerAdded(blueTeam)
end)
blueTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(blueTeam)
end)
redTeam.PlayerAdded:Connect(function(_player)
playerAdded(redTeam)
end)
redTeam.PlayerRemoved:Connect(function(_player)
playerRemoved(redTeam)
end)