Menu
CoddyTech

עפרת זהב

שיעור 5 מתוך 22 בקורס משחק Roblox: איל מפעל של Coddy.

קצת מזל גורם לשחקנים להמשיך לצפות במסוע: חלק מהעפרה היא זהב, ושוויה פי חמישה. math.random() ללא ארגומנטים מחזירה מספר מ-0 ועד (לא כולל) 1, כך שפעם אחת מתוך עשר היא קטנה מ-0.1:

if math.random() < Settings.GoldChance then
	-- זה זהב
end

עפרת זהב זוהרת (Neon) ושווה Settings.OreValue * 5.

חלק מהעפרה תיפול מהמסוע במהלך המשחק. Debris:AddItem(ore, 20) מסירה כל עפרה לאחר 20 שניות, בכל מקום שבו היא נמצאת, כדי שהעולם לעולם לא יתמלא בחלקים תועים.

challenge icon

אתגר

קל

הפוך עפרה אחת מכל עשר לעפרת זהב, ונקה עפרות שנשארו.

  1. ב־dropOre, אם math.random() < Settings.GoldChance: צבע את העפרה ב־Color3.fromRGB(255, 200, 40), קבע לה את החומר Neon, והגדר את הערך שלה ל־Settings.OreValue * 5.
  2. אחרי הגדרת ההורה של העפרה, קרא ל־Debris:AddItem(ore, 20).

לחץ על „שחק”: מדי פעם עפרת זהב זוהרת תנוע על המסוע ותעניק 50. לאחר מכן לחץ על „בדיקה”.

נסו בעצמכם

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

local tycoon = workspace.Tycoon

print("Ore is worth " .. Settings.OreValue .. " Cash")

-- כל שחקן מקבל Cash בלוח המובילים
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats
end)

-- Ore: חלק קטן ששווה Cash, שנופל מתחת למתקן ההפלה
local function dropOre(dropper)
	local ore = Instance.new("Part")
	ore.Name = "Ore"
	ore.Size = Vector3.new(1, 1, 1)
	ore.Color = Color3.fromRGB(150, 150, 160)
	ore.Position = dropper.Position - Vector3.new(0, 2.5, 0)
	ore:SetAttribute("Value", Settings.OreValue)
	-- שיעור 5: Gold Ore נכנס כאן
	ore.Parent = workspace
end

local function startDropper(dropper)
	task.spawn(function()
		while dropper:IsDescendantOf(workspace) do
			dropOre(dropper)
			task.wait(Settings.DropInterval)
		end
	end)
end

startDropper(tycoon.Dropper)

-- המסוע מעביר את כל מה שמונח עליו
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)

-- האוסף הופך Ore ל-Cash
tycoon.Collector.Touched:Connect(function(hit)
	if hit.Name == "Ore" then
		local value = hit:GetAttribute("Value")
		hit:Destroy()
		for _, player in Players:GetPlayers() do
			player.leaderstats.Cash.Value += value
		end
	end
end)

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

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