팀 서비스에는 게임의 Team 개체가 있습니다. Team 개체는 팀 서비스에 부모로 지정해야 합니다.
팀은 개발자에게 유용한 범위의 기능을 제공합니다. 이것은 상자에서 작동하는 기능 및 개발자가 게임에 프로그래밍할 수 있는 기능으로 나뉩니다.
내장 팀 동작 팀 기능은 기본적으로 제공되며 개발자가 사용자 지정 동작을 프로그래밍할 필요는 없습니다.
- 팀의 일부인 경우, 플레이어의 캐릭터 위에 있는 이름 Model 이 색상으로 채색됩니다.
- Class.Player.TeamColor를 변경하면 Player.Team 스위치를 해당 Team.TeamColor로 전환합니다.
- 기본 플레이어 목록을 사용할 때 사용자는 팀별로 그룹화되고 표시됩니다.
- 설정 Player.Neutral 을 참조하십시오. 진실로 설정하면 Player 는 팀과 연관되지 않지만 Player.Team 또는 1> Class.Player.Neutral1> 을 변경하지 않습니다.
- 게임에 Player 가 참여하면 그들은 Team.AutoAssignable 로 설정된 진정한 팀에 할당됩니다. 자동 할당 팀이 없으면 Player.Neutral 이 진정한 팀으로 설정됩니다.
- Class.SpawnLocation.Neutral 이 false로 설정되면 Player.TeamColor 가 SpawnLocation.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.
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)
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)
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])
요약
메서드
속성
메서드
GetTeams
GetTeam 함수는 게임의 Team 개체를 포함하는 테이블을 반환합니다.
이 옵션은 직접 Teams 옵션. 이 때문에 개발자는 다른 Class.Instance|Instances (또는 서로 다른 사용자) 에 팀 개체를 부모로 지정하는 것이 좋습니다.
반환
게임에서 Teams의 배열.
코드 샘플
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