This commit is contained in:
Leshyi committed 2026-11-02 16:13:44 +03:00
commit a213656689
27 files changed
+7056

No files matched your search

+337
View File
@@ -0,0 +1,337 @@
-- Заставка загрузки (ReplicatedFirst — запускается раньше всего остального).
-- Показывается при входе в игру, после возрождения и при каждом переходе между зонами (по сигналу сервера, см. Loading):
-- полоса прогресса с процентами, этап загрузки и советы. Пока она на экране, управление персонажем выключено.
-- Уходит, только когда вокруг подгружены земля, детали, текстуры и свет, а сервер отпустил персонажа, —
-- после этого управление и камера возвращаются полностью.
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local BG = Color3.fromRGB(16, 12, 9)
local BG2 = Color3.fromRGB(58, 36, 20)
local ORANGE = Color3.fromRGB(230, 130, 40)
local HAZARD = Color3.fromRGB(220, 175, 40)
local TEXT = Color3.fromRGB(235, 220, 200)
local MUTED = Color3.fromRGB(170, 150, 130)
local TRACK = Color3.fromRGB(52, 40, 30)
local PRELOAD_RADIUS = 220
local MIN_TIME = 1.5 -- даже если всё уже загружено: даём движку обновить свет и тени
local MAX_TIME = 10
local BAR_W = 440
local TIPS = {
"R — перевернуть багги. Застрял на крыше — через 5 секунд она встанет сама.",
"Бронелисты держат пули: попадание в броню не ранит водителя.",
"Колесо фортуны в ангаре можно крутить раз в 4 часа.",
"Детали в гараже перетаскиваются в слот своего цвета.",
"На карту выезжают только командой — через круги лобби в ангаре.",
"Гусеницы цепче колёс, но медленнее.",
"Взрывающиеся бочки — отличная ловушка для врага.",
}
-- ===== Заставка =====
local gui = Instance.new("ScreenGui")
gui.Name = "LoadingScreen"
gui.ResetOnSpawn = false
gui.IgnoreGuiInset = true
gui.DisplayOrder = 1000
gui.Parent = player:WaitForChild("PlayerGui")
-- CanvasGroup — чтобы плавно гасить всю заставку разом.
local cover = Instance.new("CanvasGroup")
cover.Size = UDim2.fromScale(1, 1)
cover.BackgroundColor3 = BG
cover.BorderSizePixel = 0
cover.Active = true -- клики не проходят сквозь заставку
cover.Parent = gui
-- Фон отдельной рамкой: градиент на самой CanvasGroup перекрасил бы и текст.
local background = Instance.new("Frame")
background.Size = UDim2.fromScale(1, 1)
background.BackgroundColor3 = Color3.new(1, 1, 1)
background.BorderSizePixel = 0
background.Parent = cover
local gradient = Instance.new("UIGradient")
gradient.Color = ColorSequence.new(BG, BG2)
gradient.Rotation = 115
gradient.Parent = background
local function text(props): TextLabel
local l = Instance.new("TextLabel")
l.AnchorPoint = Vector2.new(0.5, 0.5)
l.BackgroundTransparency = 1
l.TextWrapped = true
for k, v in props do
l[k] = v
end
l.Parent = cover
return l
end
text({ Position = UDim2.fromScale(0.5, 0.3), Size = UDim2.fromOffset(600, 24), Font = Enum.Font.GothamBlack, TextSize = 18, TextColor3 = MUTED, Text = "APOCALYPSE BUGGY" })
local title = text({ Position = UDim2.fromScale(0.5, 0.4), Size = UDim2.new(1, -40, 0, 56), Font = Enum.Font.GothamBlack, TextSize = 52, TextColor3 = ORANGE, Text = "ЗАГРУЗКА" })
-- Жёлто-чёрная полоса под названием зоны
local stripe = Instance.new("Frame")
stripe.AnchorPoint = Vector2.new(0.5, 0.5)
stripe.Position = UDim2.new(0.5, 0, 0.4, 40)
stripe.Size = UDim2.fromOffset(BAR_W, 6)
stripe.BackgroundColor3 = HAZARD
stripe.BorderSizePixel = 0
stripe.ClipsDescendants = true
stripe.Parent = cover
for i = 0, BAR_W / 24 - 1 do
local dash = Instance.new("Frame")
dash.Position = UDim2.fromOffset(i * 24 + 12, 0)
dash.Size = UDim2.fromOffset(12, 6)
dash.BackgroundColor3 = BG
dash.BorderSizePixel = 0
dash.Parent = stripe
end
-- Полоса загрузки с процентами
local track = Instance.new("Frame")
track.AnchorPoint = Vector2.new(0.5, 0.5)
track.Position = UDim2.new(0.5, 0, 0.4, 104)
track.Size = UDim2.fromOffset(BAR_W, 14)
track.BackgroundColor3 = TRACK
track.BorderSizePixel = 0
track.Parent = cover
Instance.new("UICorner", track).CornerRadius = UDim.new(1, 0)
local trackStroke = Instance.new("UIStroke", track)
trackStroke.Color = Color3.fromRGB(90, 66, 44)
trackStroke.Thickness = 1
local bar = Instance.new("Frame")
bar.Size = UDim2.fromScale(0, 1)
bar.BackgroundColor3 = ORANGE
bar.BorderSizePixel = 0
bar.Parent = track
Instance.new("UICorner", bar).CornerRadius = UDim.new(1, 0)
local barGradient = Instance.new("UIGradient", bar)
barGradient.Color = ColorSequence.new(HAZARD, ORANGE)
local stage = text({ Position = UDim2.new(0.5, -BAR_W / 2, 0.4, 78), AnchorPoint = Vector2.new(0, 0.5), Size = UDim2.fromOffset(BAR_W - 60, 20), Font = Enum.Font.GothamMedium, TextSize = 15, TextColor3 = TEXT, TextXAlignment = Enum.TextXAlignment.Left, Text = "" })
local percent = text({ Position = UDim2.new(0.5, BAR_W / 2, 0.4, 78), AnchorPoint = Vector2.new(1, 0.5), Size = UDim2.fromOffset(60, 20), Font = Enum.Font.GothamBlack, TextSize = 15, TextColor3 = ORANGE, TextXAlignment = Enum.TextXAlignment.Right, Text = "0%" })
local tip = text({ Position = UDim2.new(0.5, 0, 1, -60), Size = UDim2.new(1, -60, 0, 44), Font = Enum.Font.GothamMedium, TextSize = 16, TextColor3 = MUTED, Text = "" })
local fadeInfo = TweenInfo.new(0.35, Enum.EasingStyle.Quad)
local shown = false
local function setStage(label: string, value: number)
stage.Text = label
percent.Text = ("%d%%"):format(math.floor(math.clamp(value, 0, 1) * 100 + 0.5))
TweenService:Create(bar, TweenInfo.new(0.25), { Size = UDim2.fromScale(math.clamp(value, 0, 1), 1) }):Play()
end
local function randomTip()
tip.Text = "💡 " .. TIPS[math.random(1, #TIPS)]
end
-- Советы меняются, пока заставка на экране.
task.spawn(function()
while true do
task.wait(4)
if shown then
randomTip()
end
end
end)
-- ===== Управление персонажем =====
local controls = nil
local controlsWanted = true
-- Модуль управления появляется не сразу (ReplicatedFirst запускается раньше PlayerScripts).
local function applyControls()
if not controls then
pcall(function()
local scripts = player:WaitForChild("PlayerScripts", 10)
local module = scripts and scripts:WaitForChild("PlayerModule", 10)
controls = module and require(module):GetControls()
end)
end
if controls then
if controlsWanted then
controls:Enable()
else
controls:Disable()
end
end
end
local function setControls(enabled: boolean)
controlsWanted = enabled
task.spawn(applyControls)
end
-- Вернуть персонажу управление и обычную камеру (меню гаража само переключит камеру, если оно открыто).
local function restoreControl()
setControls(true)
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local camera = workspace.CurrentCamera
if humanoid then
camera.CameraSubject = humanoid
end
if camera.CameraType ~= Enum.CameraType.Custom and not player:GetAttribute("InGarage") then
camera.CameraType = Enum.CameraType.Custom
end
end
-- ===== Показ и скрытие =====
local busy = 0 -- номер текущей загрузки: новая отменяет скрытие старой
local function show(zone: string, instant: boolean?): number
busy += 1
shown = true
setControls(false)
title.Text = string.upper(zone)
setStage("Переезжаем…", 0)
randomTip()
gui.Enabled = true
if instant then
cover.GroupTransparency = 0
else
local tween = TweenService:Create(cover, fadeInfo, { GroupTransparency = 0 })
tween:Play()
tween.Completed:Wait()
end
return busy
end
local function reveal(id: number)
if busy ~= id then
return -- уже началась следующая загрузка
end
setStage("Готово", 1)
restoreControl()
task.wait(0.25)
if busy ~= id then
return
end
shown = false
local tween = TweenService:Create(cover, fadeInfo, { GroupTransparency = 1 })
tween:Play()
tween.Completed:Wait()
if busy == id then
gui.Enabled = false
end
end
-- ===== Подгрузка сцены =====
local function rootPart(): BasePart?
local character = player.Character
return character and character:FindFirstChild("HumanoidRootPart") :: BasePart?
end
-- Ждём землю под ногами (при StreamingEnabled она может прийти позже), грузим ассеты деталей вокруг,
-- даём устояться свету.
local function preloadAround(position: Vector3)
local started = os.clock()
local deadline = started + MAX_TIME
setStage("Подгружаем местность…", 0.08)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = { player.Character }
while os.clock() < deadline do
if workspace:Raycast(position + Vector3.new(0, 4, 0), Vector3.new(0, -60, 0), params) then
break
end
task.wait(0.1)
end
setStage("Текстуры и объекты…", 0.25)
local parts = workspace:GetPartBoundsInRadius(position, PRELOAD_RADIUS)
local total = math.max(#parts, 1)
local done = 0
local finished = false
task.spawn(function()
pcall(function()
ContentProvider:PreloadAsync(parts, function()
done += 1
if done % 20 == 0 then
setStage("Текстуры и объекты…", 0.25 + 0.55 * done / total)
end
end)
end)
finished = true
end)
while not finished and os.clock() < deadline do
task.wait(0.05)
end
setStage("Освещение…", 0.85)
task.wait(math.max(0.4, MIN_TIME - (os.clock() - started)))
end
-- Сервер держит персонажа на месте, пока идёт загрузка, — ждём, когда отпустит.
local function waitReleased()
setStage("Почти готово…", 0.95)
local deadline = os.clock() + 4
local root = rootPart()
while root and root.Anchored and os.clock() < deadline do
task.wait(0.05)
end
end
-- ===== Вход в игру и возрождение =====
local function loadCharacterArea(zone: string, instant: boolean)
local id = show(zone, instant)
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("HumanoidRootPart", MAX_TIME)
local root = rootPart()
if root then
preloadAround(root.Position)
end
reveal(id)
end
task.spawn(function()
show("Ангар", true)
pcall(function()
ReplicatedFirst:RemoveDefaultLoadingScreen()
end)
setStage("Соединение с сервером…", 0.02)
if not game:IsLoaded() then
game.Loaded:Wait()
end
loadCharacterArea("Ангар", true)
end)
-- После возрождения персонаж появляется в ангаре — та же заставка.
local firstCharacter = player.Character == nil
player.CharacterAdded:Connect(function()
if firstCharacter then
firstCharacter = false
return
end
loadCharacterArea("Ангар", true)
end)
-- ===== Переходы по сигналу сервера =====
local Remote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("Loading")
Remote.OnClientEvent:Connect(function(step, token, value)
if step == "show" then
show(tostring(value or ""), false)
Remote:FireServer("ready", token)
elseif step == "arrived" then
local id = busy
preloadAround(value)
Remote:FireServer("loaded", token)
waitReleased()
reveal(id)
end
end)