Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite duration on first spawn #41

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lua/autorun/server/sv_spawn_protection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ local spawnDecayPrefix = "cfc_spawn_decay_timer-"

local delayedRemovalPrefix = "cfc_spawn_removal_timer-"

-- players that have gotten a one time "infinite length" spawn protection
local doneInfiniteLength = {}

-- Table of key enums which are disallowed in spawn protection
local movementKeys = {
[IN_MOVELEFT] = true,
Expand Down Expand Up @@ -105,6 +108,9 @@ end

-- Creates a decay timer which will expire after spawnProtectionDecayTime
local function createDecayTimer( ply )
-- infinite spawn protection duration for first spawns
if not doneInfiniteLength[ply] then doneInfiniteLength[ply] = true return end

local playerIdentifer = playerDecayTimerIdentifier( ply )
timer.Create( playerIdentifer, spawnProtectionDecayTime, 1, function()
local printMessage = "You've lost your default spawn protection"
Expand Down Expand Up @@ -254,6 +260,16 @@ end )
-- PlayerSetModel runs after PlayerLoadout, so we can use it to set spawn protection
hook.Add( "PlayerSetModel", "CFCsetSpawnProtection", setSpawnProtectionForPvpSpawn, HOOK_HIGH )

-- Properly handle spawning in players
hook.Add( "PlayerFullLoad", "CFCResetInfiniteSpawnProtection", function( ply )
doneInfiniteLength[ply] = nil
setSpawnProtectionForPvpSpawn( ply )
end, HOOK_LOW )

StrawWagen marked this conversation as resolved.
Show resolved Hide resolved
hook.Add( "PlayerDisconnected", "CFC_SpawnProtection_Cleanup", function( ply )
doneInfiniteLength[ply] = nil
end )

-- Trigger spawn protection removal on player KeyPress
hook.Add( "KeyPress", "CFCspawnProtectionKeyPressCheck", spawnProtectionKeyPressCheck )

Expand Down