Menu
CoddyTech

מים שמביסים

שיעור 10 מתוך 20 בקורס משחק Roblox: הישרדות באסונות של Coddy.

הגיע הזמן לאסון הראשון. במשחק יהיו כמה אסונות, ולכן הם יישמרו בטבלה אחת, כל אחד כפונקציה שמקבלת את המפה. קוראים לפונקציה ששמורה בטבלה כמו לכל פונקציה אחרת:

local Disasters = {}

function Disasters.Flood(map)
	-- צור את המים
end

Disasters.Flood(map)

השיטפון מתחיל כחלק כחול ורחב מתחת לאי. אסור שהוא יחזיק את השחקנים, לכן CanCollide הוא false (האירוע Touched עדיין מופעל), והוא נשאר Anchored. כל אסון יכניע את מי שהוא נוגע בו, ולכן נגדיר פונקציה לשם כך:

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

lava.Touched:Connect(defeat)

hit הוא החלק שנגע, למשל כף רגל; ה-Parent שלו הוא הדמות. קבעו את המים כצאצא של המפה, כך שכשתשמידו את המפה בסוף הסיבוב, המים ייעלמו איתה.

challenge icon

אתגר

בינוני

הוסף את האסון הראשון: מים שמביסים.

  1. כתוב defeat(hit): אם יש ל־hit.Parent Humanoid, הגדר את Health שלו ל־0.
  2. צור local Disasters = {} ואת Disasters.Flood(map): חלק בשם Water בתוך המפה, מעוגן, עם CanCollide false, רחב וארוך ב־10 studs מ־map.Base, 2 studs מתחתיו, ו־Touched מחובר ל־defeat.
  3. קרא ל־Disasters.Flood(map) אחרי הטלפורט.

לחץ על "שחק" ורד מהאי: המים שמתחתיו יביסו אותך. אחר כך לחץ על "בדיקה".

נסו בעצמכם

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

-- שיעור 10: מים שמביסים יופיע כאן

-- לולאת הסיבובים
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 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

כל השיעורים ביחידה משחק Roblox: הישרדות באסונות

תרגלו בעצמכם: Roblox אונליין