From 4e1a627f50d52c1bc2708afb88102eb2c3d97584 Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:06:47 -0700 Subject: [PATCH 1/3] Infinite duration on first spawn Infinite spawn protection duration for first time spawns --- lua/autorun/server/sv_spawn_protection.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/autorun/server/sv_spawn_protection.lua b/lua/autorun/server/sv_spawn_protection.lua index e378f31..ea5ff9c 100644 --- a/lua/autorun/server/sv_spawn_protection.lua +++ b/lua/autorun/server/sv_spawn_protection.lua @@ -103,8 +103,13 @@ local function removeSpawnProtection( ply, printMessage ) ply:SetNWBool( "HasSpawnProtection", false ) end +local doneInfiniteLength = {} + -- 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" From 1eee2ea66d675ad606b97512eb32ea6a3b9235b5 Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:36:38 -0700 Subject: [PATCH 2/3] Properly handle spawning in players --- lua/autorun/server/sv_spawn_protection.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/autorun/server/sv_spawn_protection.lua b/lua/autorun/server/sv_spawn_protection.lua index ea5ff9c..dae0dbf 100644 --- a/lua/autorun/server/sv_spawn_protection.lua +++ b/lua/autorun/server/sv_spawn_protection.lua @@ -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, @@ -103,8 +106,6 @@ local function removeSpawnProtection( ply, printMessage ) ply:SetNWBool( "HasSpawnProtection", false ) end -local doneInfiniteLength = {} - -- Creates a decay timer which will expire after spawnProtectionDecayTime local function createDecayTimer( ply ) -- infinite spawn protection duration for first spawns @@ -259,6 +260,12 @@ 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 ) + -- Trigger spawn protection removal on player KeyPress hook.Add( "KeyPress", "CFCspawnProtectionKeyPressCheck", spawnProtectionKeyPressCheck ) From 1b9b80aab693ca19ddf14687bcd1eca89ccc8d0f Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:01:44 -0700 Subject: [PATCH 3/3] Update lua/autorun/server/sv_spawn_protection.lua Co-authored-by: Brandon Sturgeon --- lua/autorun/server/sv_spawn_protection.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/autorun/server/sv_spawn_protection.lua b/lua/autorun/server/sv_spawn_protection.lua index dae0dbf..ec980ed 100644 --- a/lua/autorun/server/sv_spawn_protection.lua +++ b/lua/autorun/server/sv_spawn_protection.lua @@ -266,6 +266,10 @@ hook.Add( "PlayerFullLoad", "CFCResetInfiniteSpawnProtection", function( ply ) setSpawnProtectionForPvpSpawn( ply ) end, HOOK_LOW ) +hook.Add( "PlayerDisconnected", "CFC_SpawnProtection_Cleanup", function( ply ) + doneInfiniteLength[ply] = nil +end ) + -- Trigger spawn protection removal on player KeyPress hook.Add( "KeyPress", "CFCspawnProtectionKeyPressCheck", spawnProtectionKeyPressCheck )