نقل اللاعبين آنيًا
الدرس 6 من 18 في دورة لعبة Roblox: النجاة من الكوارث على Coddy.
الجزيرة التي لا يقف عليها أحد ليست لعبة. عندما تبدأ الجولة، ينتقل كل لاعب إلى Spawn في الخريطة، وعندما تنتهي، يعود إلى الردهة.
تعرض Players:GetPlayers() قائمة بكل اللاعبين في اللعبة، وجسم اللاعب هو player.Character، وهو Model. تنقل Model:PivotTo(cframe) نموذجًا كاملًا دفعة واحدة، مع احتفاظ كل جزء بمكانه. إن CFrame هو موضع بالإضافة إلى دوران، وإضافة Vector3 إليه تحرّكه:
local function teleport(player, target)
local character = player.Character
if character then
character:PivotTo(target.CFrame + Vector3.new(0, 4, 0))
end
endتُسقط الـ4 ستودات إلى الأعلى اللاعبَ قليلًا فوق الهدف بدلًا من داخله. تكون player.Character بقيمة nil للحظة بعد الانضمام أو الموت، ومن هنا يأتي استخدام if.
التحدي
متوسطانقل اللاعبين:
- بالقرب من الأعلى، أبقِ نقطة ظهور الردهة:
local lobbySpawn = workspace.LobbySpawn. - اكتب
teleport(player, target)كما في الدرس. - مباشرةً بعد تحميل الخريطة، انقل كل لاعب إلى
map.Spawn. - عند انتهاء العد التنازلي للجولة، انقل كل لاعب إلى
lobbySpawn، قبل تدمير الخريطة.
اضغط Play ورافق اللاعبين، ثم اضغط Check.
جرّب بنفسك
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)
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
-- حلقة الجولة
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
for seconds = Settings.RoundLength, 1, -1 do
setStatus("Time left: " .. seconds)
task.wait(1)
end
map:Destroy()
end
يتضمن هذا الدرس اختبارًا قصيرًا. ابدأ الدرس للإجابة عليه وتتبّع تقدمك.