Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- --------------------------------------------------
- -- НАСТРОЙКИ
- --------------------------------------------------
- local WALK_SPEED = 8
- local POINT_REACHED_DISTANCE = 2.5
- local MOVE_TIMEOUT = 20
- local MOVE_REFRESH_INTERVAL = 2
- local ESCAPE_TIMER_DURATION =
- 7 * 60
- --------------------------------------------------
- -- PrisonIntro
- --------------------------------------------------
- local prisonIntro =
- workspace:WaitForChild(
- "PrisonIntro"
- )
- --------------------------------------------------
- -- GUARD
- --------------------------------------------------
- local guard =
- prisonIntro:WaitForChild(
- "Guard"
- )
- local humanoid =
- guard:WaitForChild(
- "Humanoid"
- )
- local rootPart =
- guard:WaitForChild(
- "HumanoidRootPart"
- )
- --------------------------------------------------
- -- DIALOG
- --------------------------------------------------
- local dialog =
- guard:WaitForChild(
- "Head"
- ):WaitForChild(
- "Dialog"
- )
- --------------------------------------------------
- -- ТОЧКИ
- --------------------------------------------------
- local guardSpawn =
- prisonIntro:WaitForChild(
- "GuardSpawn"
- )
- local doorway =
- prisonIntro:WaitForChild(
- "Doorway"
- )
- local guardStop =
- prisonIntro:WaitForChild(
- "GuardStop"
- )
- local doorWay =
- prisonIntro:WaitForChild(
- "DoorWay"
- )
- local guardExit =
- prisonIntro:WaitForChild(
- "GuardExit"
- )
- --------------------------------------------------
- -- REMOTE EVENTS
- --------------------------------------------------
- local startGuardDeparture =
- ReplicatedStorage:WaitForChild(
- "StartGuardDeparture"
- )
- local showEscapeNotice =
- ReplicatedStorage:WaitForChild(
- "ShowEscapeNotice"
- )
- local startEscapeTimer =
- ReplicatedStorage:WaitForChild(
- "StartEscapeTimer"
- )
- --------------------------------------------------
- -- СОСТОЯНИЕ
- --------------------------------------------------
- local guardArrived = false
- local departureStarted = false
- local guardGone = false
- local noticePlayer = nil
- local escapeTimers = {}
- --------------------------------------------------
- -- HUMANOID
- --------------------------------------------------
- humanoid.WalkSpeed =
- WALK_SPEED
- humanoid.AutoRotate =
- true
- humanoid.AutoJumpEnabled =
- false
- --------------------------------------------------
- -- GUARD НЕ ANCHORED
- --------------------------------------------------
- for _, object in ipairs(
- guard:GetDescendants()
- ) do
- if object:IsA("BasePart") then
- object.Anchored = false
- end
- end
- --------------------------------------------------
- -- RootPart
- --------------------------------------------------
- rootPart.CanCollide = false
- --------------------------------------------------
- -- Сетевое владение
- --------------------------------------------------
- pcall(function()
- rootPart:SetNetworkOwner(nil)
- end)
- --------------------------------------------------
- -- DIALOG READY
- --------------------------------------------------
- dialog:SetAttribute(
- "Ready",
- false
- )
- --------------------------------------------------
- --================================================
- -- WALK ANIMATION
- --================================================
- --
- -- Используем существующую:
- --
- -- Guard
- -- └── Animate
- -- └── walk
- -- └── WalkAnim
- --================================================
- --------------------------------------------------
- local animate =
- guard:WaitForChild(
- "Animate"
- )
- local walkFolder =
- animate:WaitForChild(
- "walk"
- )
- local walkAnimation =
- walkFolder:WaitForChild(
- "WalkAnim"
- )
- print("========================================")
- print("[GUARD] WalkAnim найдена")
- print(
- "[GUARD] AnimationId:",
- walkAnimation.AnimationId
- )
- print("========================================")
- --------------------------------------------------
- -- Animator
- --------------------------------------------------
- local animator =
- humanoid:FindFirstChildOfClass(
- "Animator"
- )
- if not animator then
- animator =
- Instance.new("Animator")
- animator.Parent =
- humanoid
- end
- --------------------------------------------------
- -- Загружаем WalkAnim
- --------------------------------------------------
- local walkTrack
- local animationSuccess, animationResult =
- pcall(function()
- return animator:LoadAnimation(
- walkAnimation
- )
- end)
- if animationSuccess then
- walkTrack =
- animationResult
- walkTrack.Looped =
- true
- walkTrack.Priority =
- Enum.AnimationPriority.Movement
- print(
- "[GUARD] WalkAnim успешно загружена"
- )
- else
- warn(
- "[GUARD] Не удалось загрузить WalkAnim:",
- animationResult
- )
- end
- --------------------------------------------------
- -- Запуск ходьбы
- --------------------------------------------------
- local function startWalking()
- if not walkTrack then
- return
- end
- if not walkTrack.IsPlaying then
- print(
- "[GUARD] Запускаю WalkAnim"
- )
- walkTrack:Play(
- 0.15,
- 1,
- 1
- )
- end
- end
- --------------------------------------------------
- -- Остановка ходьбы
- --------------------------------------------------
- local function stopWalking()
- if not walkTrack then
- return
- end
- if walkTrack.IsPlaying then
- walkTrack:Stop(
- 0.15
- )
- end
- end
- --------------------------------------------------
- -- Полная остановка Guard
- --------------------------------------------------
- local function stopGuard()
- humanoid:MoveTo(
- rootPart.Position
- )
- stopWalking()
- end
- --------------------------------------------------
- -- Расстояние до точки
- --------------------------------------------------
- local function getDistanceTo(
- targetPosition
- )
- local current =
- Vector3.new(
- rootPart.Position.X,
- 0,
- rootPart.Position.Z
- )
- local target =
- Vector3.new(
- targetPosition.X,
- 0,
- targetPosition.Z
- )
- return (
- current - target
- ).Magnitude
- end
- --------------------------------------------------
- --================================================
- -- ДВИЖЕНИЕ К ОДНОЙ ТОЧКЕ
- --================================================
- --------------------------------------------------
- local function moveToPoint(point)
- if guardGone then
- return false
- end
- print("========================================")
- print(
- "[GUARD] ИДУ К:",
- point.Name
- )
- print("========================================")
- --------------------------------------------------
- -- Цель
- --------------------------------------------------
- local targetPosition =
- Vector3.new(
- point.Position.X,
- rootPart.Position.Y,
- point.Position.Z
- )
- --------------------------------------------------
- -- Уже достаточно близко
- --------------------------------------------------
- if getDistanceTo(
- targetPosition
- ) <= POINT_REACHED_DISTANCE then
- print(
- "[GUARD] Уже возле:",
- point.Name
- )
- return true
- end
- --------------------------------------------------
- -- Начинаем ходьбу
- --------------------------------------------------
- startWalking()
- --------------------------------------------------
- -- Таймер
- --------------------------------------------------
- local startTime =
- os.clock()
- local lastMoveCommand =
- 0
- --------------------------------------------------
- -- Первичная команда
- --------------------------------------------------
- humanoid:MoveTo(
- targetPosition
- )
- lastMoveCommand =
- os.clock()
- --------------------------------------------------
- -- Ожидание
- --------------------------------------------------
- while true do
- if guardGone then
- stopGuard()
- return false
- end
- --------------------------------------------------
- -- Проверяем расстояние
- --------------------------------------------------
- local distance =
- getDistanceTo(
- targetPosition
- )
- --------------------------------------------------
- -- Пришли
- --------------------------------------------------
- if distance <=
- POINT_REACHED_DISTANCE then
- print(
- "[GUARD] ДОСТИГ:",
- point.Name
- )
- return true
- end
- --------------------------------------------------
- -- Тайм-аут
- --------------------------------------------------
- if
- os.clock() - startTime
- >= MOVE_TIMEOUT
- then
- warn("========================================")
- warn(
- "[GUARD] НЕ ДОШЁЛ ДО:",
- point.Name
- )
- warn(
- "[GUARD] Текущая позиция:",
- rootPart.Position
- )
- warn(
- "[GUARD] Позиция точки:",
- point.Position
- )
- warn("========================================")
- stopGuard()
- return false
- end
- --------------------------------------------------
- -- Повторяем MoveTo
- --------------------------------------------------
- if
- os.clock() - lastMoveCommand
- >= MOVE_REFRESH_INTERVAL
- then
- humanoid:MoveTo(
- targetPosition
- )
- lastMoveCommand =
- os.clock()
- end
- task.wait(0.1)
- end
- end
- --------------------------------------------------
- --================================================
- -- ПРИХОД GUARD
- --
- -- GuardSpawn → Doorway → GuardStop
- --================================================
- --------------------------------------------------
- local function makeGuardArrive()
- print("")
- print("========================================")
- print("[GUARD] НАЧИНАЮ ПРИХОД")
- print("========================================")
- --------------------------------------------------
- -- Ставим Guard точно в GuardSpawn
- --------------------------------------------------
- guard:PivotTo(
- guardSpawn.CFrame
- )
- --------------------------------------------------
- -- GuardSpawn уже является исходной позицией.
- --
- -- Идём к Doorway.
- --------------------------------------------------
- local reachedDoorway =
- moveToPoint(
- doorway
- )
- if not reachedDoorway then
- warn(
- "[GUARD] Не дошёл до Doorway"
- )
- return
- end
- --------------------------------------------------
- -- Doorway → GuardStop
- --------------------------------------------------
- local reachedGuardStop =
- moveToPoint(
- guardStop
- )
- if not reachedGuardStop then
- warn(
- "[GUARD] Не дошёл до GuardStop"
- )
- return
- end
- --------------------------------------------------
- -- Остановились
- --------------------------------------------------
- stopGuard()
- --------------------------------------------------
- -- Guard готов к диалогу
- --------------------------------------------------
- guardArrived =
- true
- dialog:SetAttribute(
- "Ready",
- true
- )
- print("")
- print("========================================")
- print("[GUARD] GUARD ПРИШЁЛ")
- print("[GUARD] GUARDSTOP ДОСТИГНУТ")
- print("[GUARD] DIALOG ГОТОВ")
- print("========================================")
- end
- --------------------------------------------------
- --================================================
- -- УХОД GUARD
- --
- -- GuardStop → DoorWay → GuardExit
- --================================================
- --------------------------------------------------
- local function makeGuardLeave()
- if departureStarted then
- return
- end
- if guardGone then
- return
- end
- departureStarted =
- true
- --------------------------------------------------
- -- Закрываем возможность нового выбора
- --------------------------------------------------
- dialog:SetAttribute(
- "Ready",
- false
- )
- print("")
- print("========================================")
- print("[GUARD] НАЧИНАЮ УХОД")
- print("========================================")
- --------------------------------------------------
- -- GuardStop → DoorWay
- --------------------------------------------------
- local reachedDoorWay =
- moveToPoint(
- doorWay
- )
- if not reachedDoorWay then
- warn(
- "[GUARD] Не дошёл до DoorWay"
- )
- departureStarted =
- false
- dialog:SetAttribute(
- "Ready",
- true
- )
- return
- end
- --------------------------------------------------
- -- DoorWay → GuardExit
- --------------------------------------------------
- local reachedGuardExit =
- moveToPoint(
- guardExit
- )
- if not reachedGuardExit then
- warn(
- "[GUARD] Не дошёл до GuardExit"
- )
- departureStarted =
- false
- return
- end
- --------------------------------------------------
- -- Guard успешно вышел
- --------------------------------------------------
- stopGuard()
- guardGone =
- true
- print("")
- print("========================================")
- print("[GUARD] GUARDEXIT ДОСТИГНУТ")
- print("[GUARD] GUARD ВЫШЕЛ")
- print("========================================")
- --------------------------------------------------
- -- Удаляем Guard
- --------------------------------------------------
- if guard.Parent then
- guard:Destroy()
- end
- --------------------------------------------------
- -- Показываем сообщение игроку
- --------------------------------------------------
- if noticePlayer then
- print(
- "[ESCAPE] Показываю сообщение:",
- noticePlayer.Name
- )
- showEscapeNotice:FireClient(
- noticePlayer
- )
- end
- end
- --------------------------------------------------
- --================================================
- -- ИГРОК ВЫБРАЛ DIALOGCHOICE
- --================================================
- --------------------------------------------------
- startGuardDeparture.OnServerEvent:Connect(
- function(player)
- print(
- "[DIALOG SERVER] GuardChoice выбран:",
- player.Name
- )
- --------------------------------------------------
- -- Guard должен стоять на GuardStop
- --------------------------------------------------
- if not guardArrived then
- warn(
- "[DIALOG SERVER] Guard ещё не пришёл"
- )
- return
- end
- --------------------------------------------------
- -- Нельзя выбрать после начала ухода
- --------------------------------------------------
- if departureStarted then
- return
- end
- if guardGone then
- return
- end
- --------------------------------------------------
- -- Запоминаем игрока
- --------------------------------------------------
- noticePlayer =
- player
- --------------------------------------------------
- -- Уходим
- --------------------------------------------------
- task.spawn(
- function()
- makeGuardLeave()
- end
- )
- end)
- --------------------------------------------------
- --================================================
- -- НАЖАТА КНОПКА "ПОНЯТНО"
- --================================================
- --------------------------------------------------
- startEscapeTimer.OnServerEvent:Connect(
- function(player)
- print(
- "[ESCAPE TIMER] Запрос:",
- player.Name
- )
- --------------------------------------------------
- -- Guard должен уже уйти
- --------------------------------------------------
- if not guardGone then
- warn(
- "[ESCAPE TIMER] Guard ещё не ушёл"
- )
- return
- end
- --------------------------------------------------
- -- Только тот игрок, который получил табличку
- --------------------------------------------------
- if player ~= noticePlayer then
- warn(
- "[ESCAPE TIMER] Этот игрок не получал",
- "табличку"
- )
- return
- end
- --------------------------------------------------
- -- Таймер уже запущен
- --------------------------------------------------
- if escapeTimers[player.UserId] then
- warn(
- "[ESCAPE TIMER] Таймер уже запущен"
- )
- return
- end
- --------------------------------------------------
- -- Конечное серверное время
- --------------------------------------------------
- local endTime =
- workspace:GetServerTimeNow()
- +
- ESCAPE_TIMER_DURATION
- escapeTimers[player.UserId] =
- endTime
- print("========================================")
- print("[ESCAPE TIMER] ТАЙМЕР ЗАПУЩЕН")
- print("[ESCAPE TIMER] Игрок:", player.Name)
- print("[ESCAPE TIMER] 7 минут")
- print("========================================")
- --------------------------------------------------
- -- Отправляем конечное время клиенту
- --------------------------------------------------
- startEscapeTimer:FireClient(
- player,
- endTime
- )
- end)
- --------------------------------------------------
- -- Очистка
- --------------------------------------------------
- Players.PlayerRemoving:Connect(
- function(player)
- escapeTimers[player.UserId] =
- nil
- if noticePlayer == player then
- noticePlayer =
- nil
- end
- end
- )
- --------------------------------------------------
- -- ЗАПУСК
- --------------------------------------------------
- task.wait(1)
- task.spawn(
- function()
- makeGuardArrive()
- end
- )
- --------------------------------------------------
- -- Готовность
- --------------------------------------------------
- print("")
- print("========================================")
- print("[PRISON INTRO] СИСТЕМА ЗАПУЩЕНА")
- print("[PRISON INTRO] Приход:")
- print("GuardSpawn → Doorway → GuardStop")
- print("[PRISON INTRO] Уход:")
- print("GuardStop → DoorWay → GuardExit")
- print("[PRISON INTRO] Таймер: 7 минут")
- print("========================================")
Advertisement
Add Comment
Please, Sign In to add comment