@@ -13,13 +13,21 @@ local CLOSENESS_LIMIT = CFCRandomSpawn.Config.CLOSENESS_LIMIT ^ 2
1313local CENTER_UPDATE_INTERVAL = customSpawnConfigForMap .centerUpdateInterval or CFCRandomSpawn .Config .CENTER_UPDATE_INTERVAL
1414local IGNORE_BUILDERS = CFCRandomSpawn .Config .IGNORE_BUILDERS
1515
16+ 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
17+
1618local DYNAMIC_CENTER_MINSIZE = 2000 -- getDynamicPvpCenter starts at this radius
1719local DYNAMIC_CENTER_MAXSIZE = 4000 -- no bigger than this radius
1820local DYNAMIC_CENTER_MINSPAWNS = 10 -- getDynamicPvpCenter needs at least this many spawns inside the radius
1921local DYNAMIC_CENTER_MAXSPAWNS = 35 -- max possible spawns
2022local DYNAMIC_CENTER_SPAWNCOUNTMATCHPVPERS = true -- pvp center gets bigger when more people are pvping
2123local DYNAMIC_CENTER_IMPERFECT = true -- throw a bit of randomness in, makes pvp less stiff.
2224
25+ CFCRandomSpawn .recentCombatants = CFCRandomSpawn .recentCombatants or {}
26+ local recentCombatants = CFCRandomSpawn .recentCombatants
27+
28+ local CurTime = CurTime
29+ local Vector = Vector
30+
2331local function defaultPvpCenter ()
2432 return pvpCenters [1 ]
2533end
@@ -79,15 +87,36 @@ local function getMeasurablePlayers()
7987 local measurablePlayers = {}
8088 local humans = IGNORE_BUILDERS and getPvpers () or player .GetAll ()
8189
90+ local cur = CurTime ()
91+
8292 for _ , ply in pairs ( humans ) do
83- if ply :Alive () then
93+ if ply :Alive () and recentCombatants [ ply ] > cur then
8494 table.insert ( measurablePlayers , ply )
8595 end
8696 end
8797
8898 return measurablePlayers
8999end
90100
101+ local function countAsCombatting ( ply )
102+ local cur = CurTime ()
103+ recentCombatants [ply ] = cur + ACTIVE_PLAYER_TIMEOUT
104+ end
105+
106+ hook .Add ( " PlayerInitialSpawn" , " cfc_randomspawn_firstspawn" , function ( ply )
107+ recentCombatants [ply ] = 0
108+ end )
109+
110+ hook .Add ( " PlayerDeath" , " cfc_randomspawn_trackrecentcombatants" , function ( died , _inflictor , attacker )
111+ if not attacker :IsPlayer () then return end
112+ countAsCombatting ( died )
113+ countAsCombatting ( attacker )
114+ end )
115+
116+ hook .Add ( " PlayerDisconnected" , " cfc_randomspawn_cleanuprecentcombatants" , function ( ply )
117+ recentCombatants [ply ] = nil
118+ end )
119+
91120local function getLivingPlayers ()
92121 local livingPlayers = {}
93122 local humans = player .GetAll ()
196225local function getPlyAvg ( plys , centerPos )
197226 if not plys or not plys [1 ] then return centerPos or Vector () end
198227
199- local avgSum = Vector ()
228+ local avgSum = Vector ( 0 , 0 , 0 )
200229
201230 for _ , ply in ipairs ( plys ) do
202231 avgSum = avgSum + ply :GetPos ()
0 commit comments