From 753a1825febed369f11840cf33573d47daf09f9a Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:12:26 -0700 Subject: [PATCH 1/4] Resurrect #96 --- .../module/sv_player_spawning.lua | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lua/cfc_random_spawn/module/sv_player_spawning.lua b/lua/cfc_random_spawn/module/sv_player_spawning.lua index f4d5175..1569216 100755 --- a/lua/cfc_random_spawn/module/sv_player_spawning.lua +++ b/lua/cfc_random_spawn/module/sv_player_spawning.lua @@ -13,6 +13,8 @@ local CLOSENESS_LIMIT = CFCRandomSpawn.Config.CLOSENESS_LIMIT ^ 2 local CENTER_UPDATE_INTERVAL = customSpawnConfigForMap.centerUpdateInterval or CFCRandomSpawn.Config.CENTER_UPDATE_INTERVAL local IGNORE_BUILDERS = CFCRandomSpawn.Config.IGNORE_BUILDERS +local ACTIVE_PLAYER_TIMEOUT = 120 -- players who haven't died/killed anyone in this many seconds aren't 'pvping' and won't influence the pvp center, etc + local DYNAMIC_CENTER_MINSIZE = 2000 -- getDynamicPvpCenter starts at this radius local DYNAMIC_CENTER_MAXSIZE = 4000 -- no bigger than this radius local DYNAMIC_CENTER_MINSPAWNS = 10 -- getDynamicPvpCenter needs at least this many spawns inside the radius @@ -20,6 +22,12 @@ local DYNAMIC_CENTER_MAXSPAWNS = 35 -- max possible spawns local DYNAMIC_CENTER_SPAWNCOUNTMATCHPVPERS = true -- pvp center gets bigger when more people are pvping local DYNAMIC_CENTER_IMPERFECT = true -- throw a bit of randomness in, makes pvp less stiff. +CFCRandomSpawn.recentCombatants = CFCRandomSpawn.recentCombatants or {} +local recentCombatants = CFCRandomSpawn.recentCombatants + +local CurTime = CurTime +local Vector = Vector + local function defaultPvpCenter() return pvpCenters[1] end @@ -79,8 +87,10 @@ local function getMeasurablePlayers() local measurablePlayers = {} local humans = IGNORE_BUILDERS and getPvpers() or player.GetAll() + local cur = CurTime() + for _, ply in pairs( humans ) do - if ply:Alive() then + if ply:Alive() and recentCombatants[ply] > cur then table.insert( measurablePlayers, ply ) end end @@ -88,6 +98,25 @@ local function getMeasurablePlayers() return measurablePlayers end +local function countAsCombatting( ply ) + local cur = CurTime() + recentCombatants[ply] = math.max( cur + ACTIVE_PLAYER_TIMEOUT, recentCombatants[ply] + ACTIVE_PLAYER_TIMEOUT / 2 ) +end + +hook.Add( "PlayerInitialSpawn", "cfc_randomspawn_firstspawn", function( ply ) + recentCombatants[ply] = 0 +end ) + +hook.Add( "PlayerDeath", "cfc_randomspawn_trackrecentcombatants", function( died, _inflictor, attacker ) + countAsCombatting( died ) + if not attacker:IsPlayer() then return end + countAsCombatting( attacker ) +end ) + +hook.Add( "PlayerDisconnected", "cfc_randomspawn_cleanuprecentcombatants", function( ply ) + recentCombatants[ply] = nil +end ) + local function getLivingPlayers() local livingPlayers = {} local humans = player.GetAll() @@ -196,9 +225,11 @@ end local function getPlyAvg( plys, centerPos ) if not plys or not plys[1] then return centerPos or Vector() end - local avgSum = Vector() + local avgSum = plys[1]:GetPos() + if #plys == 1 then return avgSum end - for _, ply in ipairs( plys ) do + for i = 2, #plys do + local ply = plys[i] avgSum = avgSum + ply:GetPos() end From 3aafa4966a59be7e733858a5c36afd10094c4b03 Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:15:13 -0700 Subject: [PATCH 2/4] Simplify --- lua/cfc_random_spawn/module/sv_player_spawning.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/cfc_random_spawn/module/sv_player_spawning.lua b/lua/cfc_random_spawn/module/sv_player_spawning.lua index 1569216..ed2afda 100755 --- a/lua/cfc_random_spawn/module/sv_player_spawning.lua +++ b/lua/cfc_random_spawn/module/sv_player_spawning.lua @@ -100,7 +100,7 @@ end local function countAsCombatting( ply ) local cur = CurTime() - recentCombatants[ply] = math.max( cur + ACTIVE_PLAYER_TIMEOUT, recentCombatants[ply] + ACTIVE_PLAYER_TIMEOUT / 2 ) + recentCombatants[ply] = cur + ACTIVE_PLAYER_TIMEOUT end hook.Add( "PlayerInitialSpawn", "cfc_randomspawn_firstspawn", function( ply ) @@ -108,8 +108,8 @@ hook.Add( "PlayerInitialSpawn", "cfc_randomspawn_firstspawn", function( ply ) end ) hook.Add( "PlayerDeath", "cfc_randomspawn_trackrecentcombatants", function( died, _inflictor, attacker ) - countAsCombatting( died ) if not attacker:IsPlayer() then return end + countAsCombatting( died ) countAsCombatting( attacker ) end ) From aa7ca0d6a043a2f8052f2222e67daee6ca823e87 Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Sun, 8 Feb 2026 14:21:55 -0700 Subject: [PATCH 3/4] That wasnt doing anything --- lua/cfc_random_spawn/module/sv_player_spawning.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/cfc_random_spawn/module/sv_player_spawning.lua b/lua/cfc_random_spawn/module/sv_player_spawning.lua index ed2afda..f528a2b 100755 --- a/lua/cfc_random_spawn/module/sv_player_spawning.lua +++ b/lua/cfc_random_spawn/module/sv_player_spawning.lua @@ -225,11 +225,9 @@ end local function getPlyAvg( plys, centerPos ) if not plys or not plys[1] then return centerPos or Vector() end - local avgSum = plys[1]:GetPos() - if #plys == 1 then return avgSum end + local avgSum = Vector() - for i = 2, #plys do - local ply = plys[i] + for _, ply in ipairs( plys ) do avgSum = avgSum + ply:GetPos() end From c76dd35a278e8a4e0fe522147e81ab1a589a0627 Mon Sep 17 00:00:00 2001 From: StrawWagen <64710817+StrawWagen@users.noreply.github.com> Date: Sun, 8 Feb 2026 14:22:23 -0700 Subject: [PATCH 4/4] Explicitly state the vector is 0 0 0 --- lua/cfc_random_spawn/module/sv_player_spawning.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/cfc_random_spawn/module/sv_player_spawning.lua b/lua/cfc_random_spawn/module/sv_player_spawning.lua index f528a2b..608d90b 100755 --- a/lua/cfc_random_spawn/module/sv_player_spawning.lua +++ b/lua/cfc_random_spawn/module/sv_player_spawning.lua @@ -225,7 +225,7 @@ end local function getPlyAvg( plys, centerPos ) if not plys or not plys[1] then return centerPos or Vector() end - local avgSum = Vector() + local avgSum = Vector( 0, 0, 0 ) for _, ply in ipairs( plys ) do avgSum = avgSum + ply:GetPos()