Files
Hunter/scripts/ModeRuntime/PlayerRoundState.luau
T

54 lines
2.0 KiB
Luau

--!strict
local RoundState = {}
type Movement = {humanoid: Humanoid, root: BasePart, walk: number, jumpHeight: number, jumpPower: number, wasAnchored: boolean}
local frozen: {[Player]: Movement} = {}
function RoundState.thaw(player: Player)
local old = frozen[player]
if not old then return end
frozen[player] = nil
old.root.Anchored = old.wasAnchored
if old.humanoid.WalkSpeed == 0 then old.humanoid.WalkSpeed = old.walk end
if old.humanoid.JumpHeight == 0 then old.humanoid.JumpHeight = old.jumpHeight end
if old.humanoid.JumpPower == 0 then old.humanoid.JumpPower = old.jumpPower end
end
function RoundState.freeze(player: Player, character: Model, humanoid: Humanoid)
local root = character:FindFirstChild("HumanoidRootPart")
if not root or not root:IsA("BasePart") then return end
if frozen[player] and frozen[player].root == root then return end
RoundState.thaw(player)
frozen[player] = {humanoid = humanoid, root = root, walk = humanoid.WalkSpeed,
jumpHeight = humanoid.JumpHeight, jumpPower = humanoid.JumpPower, wasAnchored = root.Anchored}
root.AssemblyLinearVelocity = Vector3.zero
root.AssemblyAngularVelocity = Vector3.zero
root.Anchored = true
humanoid.WalkSpeed = 0
humanoid.JumpHeight = 0
humanoid.JumpPower = 0
end
function RoundState.clearShield(player: Player)
player:SetAttribute("SpawnShield", nil)
local character = player.Character
local old = character and character:FindFirstChild("RoundSpawnShield")
if old then old:Destroy() end
end
function RoundState.shield(player: Player, character: Model, seconds: number)
RoundState.clearShield(player)
if seconds <= 0 then return end
local untilAt = workspace:GetServerTimeNow() + seconds
local field = Instance.new("ForceField")
field.Name = "RoundSpawnShield"
field.Visible = false
field.Parent = character
player:SetAttribute("SpawnShield", untilAt)
task.delay(seconds, function()
field:Destroy()
if player:GetAttribute("SpawnShield") == untilAt then player:SetAttribute("SpawnShield", nil) end
end)
end
return RoundState