Team

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

Class.Team 클래스는 Roblox 플레이스분파를 나타냅니다. 팀의 유일한 유효한 부모는 Teams 서비스에 있습니다. 팀은 개발자를 두 개의 주요 그룹으로 나눌 수 있는 다양한 기능을 제공합니다.

  • 상자에서 작동하지 않는 기능
  • 개발자는 게임에 프로그래밍할 수 있습니다.

내장 팀 동작 팀의 다음 기능은 기본적으로 존재하며 개발자가 사용자 지정 동작을 프로그래밍할 필요가 없습니다.

  • 팀의 일부인 경우, 플레이어의 캐릭터 위에 있는 이름 Model 이 색상으로 채색됩니다.
  • Class.Player.TeamColor를 변경하면 Player.Team이 해당 Team.TeamColor와 함께 팀으로 전환합니다.
  • 기본 플레이어 목록을 사용할 때 사용자는 팀으로 그룹화되고 표시됩니다.
  • 설정 Player.Neutral 을 참조하십시오. 진실로 설정하면 Player 는 팀과 연관되지 않지만 변경하지는 않습니다. Player.Team 또는 1> Class.Player.TeamColor1>
  • 게임에 Player 가 참여하면 그들은 Team.AutoAssignable 로 설정된 진정한 팀에 할당됩니다. 자동 할당 팀이 없으면 Player.Neutral 이 진정한 팀으로 설정됩니다.
  • Class.SpawnLocation.Neutral 이 false로 설정되면 Player.TeamColorSpawnLocation.TeamColor 와 일치하는 플레이어만 1>Class.SpawnLocation1>에 생성할 수 있습니다.
  • Class.SpawnLocation.AllowTeamChangeOnTouch 가 진실로 설정되면, 플레이어의 Player.TeamColor 는 플레이어가 캐릭터를 만질 때 SpawnLocation.TeamColor 로 변경됩니다.

옵션 확장 팀 동작 많은 개발자가 팀에 다음과 같은 기능을 추가하기로 선택했습니다.

  • 친밀한 불을 예방하기 위해 무기 코드에 검사를 구현하십시오.
  • 특정 팀만 사용할 수 있는 문이나 기타 기능에 검사를 구현
  • 팀 잔액유지하기 위해 팀을 정기적으로 재할당합니다.

코드 샘플

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.

Simple Team Rebalance

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.

Team Kill Check

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.

Team Only Door

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 속성을 결정합니다. 또한 플레이어 목록과 플레이어 머리 위에 표시되는 색을 결정합니다.

메서드

  • GetPlayers():Instances
    병렬 쓰기

    Class.Player|Players 가 Team 에 할당된 것을 나타내는 목록을 반환합니다. Player 는 그들의 1>Class.Player.Team1> 속성이 4>Class.Team4> 와 동일하고 7>Class.Player.Neutral7>

이벤트

  • 클래스 Class.Player 는 클래스 Class.Team 에 할당되면 발생합니다. 플레이어는 클래스 Class.Player.Team 속성이 Class.Team 와 동일하면 할당된 것으로 간주됩니다. 클래스 Class.Player 는 클래스 Class.Team 와 중복되지 않아야 합니다. 클래스 Class.Player 는 중복

  • Class.Player 가 Team 에서 제거되면 마이크로서비스 콘텐츠를 보려면 화이트리스트를 업데이트해야 합니다. 이 경우 Player 가 게임을 떠나거나 1>Class.Player.Neutral1> 이 설정되면 트루로 설정

속성

AutoAssignable

병렬 읽기

이 속성은 Players 가 자동으로 Team 에 배치되는지 여부를 결정합니다. 여러 팀이 이 속성을 설정하면 Roblox는 팀이 추가될 때 Players 을 포함하여 팀을 시도합니다.

게임에 Player가 참여하면 TeamTeam.AutoAssignable 설정이 진행되어 가장 적은 플레이어에게 할당됩니다. 이렇게 할 팀이 없으면 2>Class.Player2>가 진행됩니다.

이 속성을 사용할 때 플레이어가 추가될 때 팀이 균형을 맞출 수 있도록 하는 것이 좋습니다. 플레이어가 제거될 때는 아무 것도 하지 않습니다. 이 때문에 개발자는 팀 균형 시스템을 구현할 수 있습니다.

코드 샘플

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.

Simple Team Rebalance

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의 기본 팀 기능은 이름이나 개체가 아닌 팀 색상에 기초합니다. 예를 들어, SpawnLocations 은 팀에 할당될 수 있습니다 SpawnLocation.TeamColor 을 통해. 이 때문에 개발자는 각 Team

팀의 일부인 플레이어는 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.

Team Only Door

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

Instances
병렬 쓰기

Class.Player|Players 가 Team 에 할당된 것을 나타내는 목록을 반환합니다. Player 는 그들의 1>Class.Player.Team1> 속성이 4>Class.Team4> 와 동일하고 7>Class.Player.Neutral7>

이 함수는 Team 에 플레이어 수를 계산하거나 PlayerTeam 을 제공하는 등의 여러 가지 사용 사례가 있습니다.


반환

Instances

Class.Team 내의 배열 Team 에 대한 액세스.

코드 샘플

The example below prints the number of players on each Team.

Teams GetTeams

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 는 클래스 Class.Team 에 할당되면 발생합니다. 플레이어는 클래스 Class.Player.Team 속성이 Class.Team 와 동일하면 할당된 것으로 간주됩니다. 클래스 Class.Player 는 클래스 Class.Team 와 중복되지 않아야 합니다. 클래스 Class.Player 는 중복

이 이벤트는 팀 별로 발생하며, 특정 Player 가 특정 Team 에 합류할 때만 발생합니다. 이 이벤트에 연결된 모든 함수는 플레이어가 팀에 합류한 플레이어의 Player 개체를 통해 전달됩니다. 예를 들어:

Team.PlayerAdded:Connect(function(플레이어) print(플레이어.Name.." 가 팀에 합류했습니다") 종료)

매개 변수

player: Player

추가된 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.

Simple Team Rebalance

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> 이 설정되면 트루로 설정

이 이벤트는 팀 전용이며 특정 Player 가 팀을 떠날 때만 발생합니다. 이 이벤트에 연결된 모든 함수는 플레이어가 팀을 떠난 플레이어의 Team 개체를 통해 전달됩니다. 예를 들어:

Team.PlayerRemoved: Connect(function(플레이어) print(플레이어.Name.." 팀에서 떠났습니다") 종료)

매개 변수

player: Player

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.

Simple Team Rebalance

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)