SpawnLocation

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

重生位置或“重生”决定死亡时 Player 重生在哪里。它们可以配置为只允许特定玩家使用每个重生点,使用 Teams 。它们还控制新生玩家的配置方式 ForceFields

SpawnLocations可以用作检查点,例如在障碍赛中,使用 SpawnLocation.AllowTeamChangeOnTouch 属性,当玩家触碰它时,它们将更换队伍为 SpawnLocation 的团队。在这种情况下,只有第一个 Team 应将 Team.AutoAssignable 设置为真,否则玩家将无法在第一个检查点开始。

注意,如果将 SpawnLocation 添加到 Studio 的 Workspace 中,将 SpawnLocation.Neutral 设置为 false,将创建相应于 SpawnLocation.TeamColor 的团队,如果它还不存在。当在游戏中使用 Script 创建生成时,或者已添加 SpawnLocation 的属性后更改时,此行为不会发生。建议开发人员始终手动设置他们的团队,而不要依赖此行为。

生成规则

当玩家重生时,有几个规则会发挥作用给定的 SpawnLocation:

还见:

  • 如果你想配置玩家重生所需的时间,看看 RespawnTime 属性

代码示例

This sample demonstrates how SpawnLocations can be used to make a checkpoint system. Typically this would be done Studio and not in Lua, but this example serves as a comprehensive example of what Team and SpawnLocation properties need to be used to achieve this setup.

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- position spawns
startSpawn.CFrame = CFrame.new(0, 0.5, 0)
team1Spawn.CFrame = CFrame.new(10, 0.5, 0)
team2Spawn.CFrame = CFrame.new(20, 0.5, 0)
team3Spawn.CFrame = CFrame.new(30, 0.5, 0)

概要

属性

继承自Part属性继承自BasePart属性继承自PVInstance属性

方法

继承自BasePart方法继承自PVInstance方法
  • 写入并联

    获取 PVInstance 的枢轴。

  • PivotTo(targetCFrame : CFrame):()

    将 以及所有其子孙 转换为位于指定 的位置,使旋转点现在位于指定的 。

活动

继承自BasePart活动

属性

AllowTeamChangeOnTouch

读取并联

允许一个 Player 通过触碰 SpawnLocation 加入团队。当设置为真时,如果 Player 角色与 SpawnLocation 接触,玩家的 Player.TeamColor 将设置为 SpawnLocation.TeamColor .Player.Neutral 也将在联系时设置为SpawnLocation.Neutral,这意味着玩家也可以通过触摸生成位置变得中立。

SpawnLocation.Enabled 设置为 false 时,将无法运行。

制定检查点

此功能经常用于在障碍赛或类似游戏中制定检查点。

代码示例

This sample demonstrates how SpawnLocations can be used to make a checkpoint system. Typically this would be done Studio and not in Lua, but this example serves as a comprehensive example of what Team and SpawnLocation properties need to be used to achieve this setup.

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- position spawns
startSpawn.CFrame = CFrame.new(0, 0.5, 0)
team1Spawn.CFrame = CFrame.new(10, 0.5, 0)
team2Spawn.CFrame = CFrame.new(20, 0.5, 0)
team3Spawn.CFrame = CFrame.new(30, 0.5, 0)

Duration

读取并联

在秒内,一个 ForceField 将被应用到在这个 Player 中生成的角色上,一个 SpawnLocation 角色。如果持续时间为零,ForceField 将永远不会创建,也不会触发 Instance.DescendantAddedInstance.ChildAdded 事件。

此属性的默认值为 10 秒。

持续时间功能允许开发人员轻松提供Players保护,这可能是玩家感到挫折的经历。注意, 只会保护用户免受 和使用 来造成伤害或其他检查的武器。

代码示例

This sample will create a neutral SpawnLocation in the Workspace that'll give players spawning a ForceField for 20 seconds.

SpawnLocation ForceField

local spawnLocation = Instance.new("SpawnLocation")
spawnLocation.Anchored = true
spawnLocation.Size = Vector3.new(5, 1, 5)
spawnLocation.Neutral = true -- anyone can spawn here
spawnLocation.Duration = 20
spawnLocation.Parent = workspace

Enabled

读取并联

设置是否启用 SpawnLocation 。禁用玩家时无法在 SpawnLocation 生成,并且 SpawnLocation.AllowTeamChangeOnTouch 功能被禁用。

该属性提供了最方便的方法来防止 Players 在生重生点中生成。

注意,尽管在触摸时使用 SpawnLocation.AllowTeamChangeOnTouch 更改团队时已禁用,其他使用 BasePart.Touched 的触摸事件仍会发触发。

代码示例

The following sample will create a SpawnLocation in the Workspace that will become semi-transparent when it is disabled.

SpawnLocation Enabled

local spawnLocation = Instance.new("SpawnLocation")
spawnLocation.Anchored = true
spawnLocation.Size = Vector3.new(5, 1, 5)
spawnLocation.Neutral = true -- anyone can spawn here
spawnLocation.Enabled = true
spawnLocation.Parent = workspace
local function onEnabledChanged()
spawnLocation.Transparency = spawnLocation.Enabled and 0 or 0.5
end
spawnLocation:GetPropertyChangedSignal("Enabled"):Connect(onEnabledChanged)
task.wait(5)
spawnLocation.Enabled = false -- transparency = 0.5

Neutral

读取并联

是否生成是否与特定团队相关。这意味着任何 Player , 任何 Team , 如果此属性设置为真,都可以在上面生成 if this property is set to true。

如果中立设置为 false,只有那些玩家的 Player.TeamColorSpawnLocation.TeamColor 相等的玩家才能使用 SpawnLocation

如果 SpawnLocation.AllowTeamChangeOnTouch 是真的,Player.Neutral 将在与生成联系时设置为此属性。

代码示例

This sample demonstrates how SpawnLocations can be used to make a checkpoint system. Typically this would be done Studio and not in Lua, but this example serves as a comprehensive example of what Team and SpawnLocation properties need to be used to achieve this setup.

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- position spawns
startSpawn.CFrame = CFrame.new(0, 0.5, 0)
team1Spawn.CFrame = CFrame.new(10, 0.5, 0)
team2Spawn.CFrame = CFrame.new(20, 0.5, 0)
team3Spawn.CFrame = CFrame.new(30, 0.5, 0)

TeamColor

读取并联

团队颜色属性设置 SpawnLocation 是哪个团队附属。如果 SpawnLocation.Neutral 属性为 false,只有 Players 与重生点的团队颜色相同的 Player.TeamColor 才能在那里生成。

如果 SpawnLocation.AllowTeamChangeOnTouch 是真的,Player.Neutral 将在与生成联系时设置为此属性。

代码示例

This sample demonstrates how SpawnLocations can be used to make a checkpoint system. Typically this would be done Studio and not in Lua, but this example serves as a comprehensive example of what Team and SpawnLocation properties need to be used to achieve this setup.

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- position spawns
startSpawn.CFrame = CFrame.new(0, 0.5, 0)
team1Spawn.CFrame = CFrame.new(10, 0.5, 0)
team2Spawn.CFrame = CFrame.new(20, 0.5, 0)
team3Spawn.CFrame = CFrame.new(30, 0.5, 0)

方法

活动