获胜者
Coddy Roblox 游戏:灾难生存 课程的第 8 课,共 20 课。
在一轮中存活下来就能获得一次胜利。回合结束时,仍在 survivors 中的每位玩家都会获得一次胜利:
for player in survivors do
player.leaderstats.Wins.Value += 1
end+= 会直接将值增加。要判断是否有人存活,next(survivors) 会返回表中的第一个键;如果表为空,则返回 nil。
玩家需要一点时间查看结果,然后大厅倒计时才会重新接管记分板,所以回合会以 task.wait(3) 结束。
挑战
中等给每位幸存者加 1 胜。
- 回合结束时,给每位幸存者的
Wins加 1,而不是统计幸存者人数。 - 地图销毁后,如果有人幸存,就显示
Survivors win!;否则显示Nobody survived! - 然后运行
task.wait(3),再开始下一轮大厅倒计时。
按“开始”并在一回合中存活下来:Wins 会增加到 1,状态板会显示 Survivors win。然后按“检查”。
亲手试试
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)
local lobbySpawn = workspace.LobbySpawn
print("Rounds last " .. Settings.RoundLength .. " seconds")
-- 每位玩家的排行榜上都有 Wins
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
end)
-- 大厅里的状态板
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard
local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui
local function setStatus(text)
status.Text = text
end
local function teleport(player, target)
local character = player.Character
if character then
character:PivotTo(target.CFrame + Vector3.new(0, 4, 0))
end
end
-- 回合循环
while true do
for seconds = Settings.Intermission, 1, -1 do
setStatus("Intermission: " .. seconds)
task.wait(1)
end
local map = ServerStorage.Maps.Island:Clone()
map.Name = "Map"
map.Parent = workspace
local survivors = {}
for _, player in Players:GetPlayers() do
local character = player.Character
if character and character.Humanoid.Health > 0 then
teleport(player, map.Spawn)
survivors[player] = true
character.Humanoid.Died:Connect(function()
survivors[player] = nil
end)
end
end
for seconds = Settings.RoundLength, 1, -1 do
setStatus("Time left: " .. seconds)
task.wait(1)
end
local count = 0
for player in survivors do
count += 1
teleport(player, lobbySpawn)
end
map:Destroy()
-- 第 8 课:Winners 写在这里
print("Survivors: " .. count)
end
Roblox 游戏:灾难生存中的所有课
自己练习: Roblox 在线编辑器