Menu
CoddyTech

무작위 재난

Coddy의 Roblox 게임: 재난 생존 코스 레슨. 18개 중 13번째.

무슨 일이 일어날지 알고 있으면 게임이 지루해집니다. 새로운 재난을 테스트할 때 유용하도록 Settings.Disaster에 재난 이름을 지정하지 않는 한, 매 라운드마다 재난을 무작위로 선택해야 합니다.

무작위로 선택하려면 테이블의 키를 나열하고 위치를 하나 고릅니다. for name in Disasters do는 정해진 순서 없이 키를 방문하므로, 먼저 목록을 정렬합니다. 그러면 같은 난수를 사용할 때 항상 같은 재난이 선택되어 게임을 테스트하기가 더 쉬워집니다.

local names = {}
for name in Disasters do
	table.insert(names, name)
end
table.sort(names)
local pick = names[math.random(1, #names)]

플레이어가 무엇에 당했는지 알아야 하므로 카운트다운에 재난 이름을 표시합니다: Flood! Time left: 15.

challenge icon

챌린지

중급

매 라운드마다 재난을 선택하세요:

  1. pickDisaster()를 작성하세요. Settings.Disaster가 설정되어 있으면 반환하고, 그렇지 않으면 Disasters 테이블 키의 정렬된 목록에서 임의의 이름을 반환하세요.
  2. 라운드에서 local disaster = pickDisaster()를 사용한 다음 Disasters[disaster](map)을 호출하세요.
  3. 카운트다운이 재난 이름을 먼저 표시하여 Flood! Time left: 15로 나타나게 하세요.

이 레슨의 설정에서는 Disaster가 비어 있습니다. 몇 라운드 동안 Play를 누른 다음 Check를 누르세요.

직접 해보기

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
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

local function defeat(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- 이름별 재난 목록
local Disasters = {}

function Disasters.Flood(map)
	local base = map.Base
	local water = Instance.new("Part")
	water.Name = "Water"
	water.Anchored = true
	water.CanCollide = false
	water.Transparency = 0.3
	water.Color = Color3.fromRGB(40, 120, 255)
	water.Size = Vector3.new(base.Size.X + 10, 1, base.Size.Z + 10)
	water.Position = base.Position - Vector3.new(0, 2, 0)
	water.Parent = map
	water.Touched:Connect(defeat)

	local rise = TweenInfo.new(Settings.RoundLength * 0.8, Enum.EasingStyle.Linear)
	TweenService:Create(water, rise, { Position = water.Position + Vector3.new(0, 8, 0) }):Play()
end

function Disasters.Meteors(map)
	local base = map.Base
	task.spawn(function()
		while map.Parent do
			local meteor = Instance.new("Part")
			meteor.Name = "Meteor"
			meteor.Shape = Enum.PartType.Ball
			meteor.Size = Vector3.new(3, 3, 3)
			meteor.Color = Color3.fromRGB(255, 120, 30)
			meteor.Material = Enum.Material.Neon
			local x = base.Position.X + math.random(-15, 15)
			local z = base.Position.Z + math.random(-15, 15)
			meteor.Position = Vector3.new(x, 40, z)
			meteor.Parent = map
			meteor.Touched:Connect(defeat)
			Debris:AddItem(meteor, 4)
			task.wait(0.5)
		end
	end)
end

function Disasters.Shrink(map)
	local base = map.Base
	local shrink = TweenInfo.new(Settings.RoundLength * 0.7, Enum.EasingStyle.Linear)
	TweenService:Create(base, shrink, { Size = Vector3.new(6, base.Size.Y, 6) }):Play()
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

	Disasters[Settings.Disaster](map)
	for seconds = Settings.RoundLength, 1, -1 do
		setStatus("Time left: " .. seconds)
		task.wait(1)
	end

	local names = {}
	for player in survivors do
		player.leaderstats.Wins.Value += 1
		teleport(player, lobbySpawn)
		table.insert(names, player.Name)
	end
	map:Destroy()
	if #names > 0 then
		setStatus("Winners: " .. table.concat(names, ", "))
	else
		setStatus("Nobody survived!")
	end
	task.wait(3)
end
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Roblox 게임: 재난 생존의 모든 레슨