Skip to content

Commit bd59c50

Browse files
authored
Add recentCombatants system
Makes the pvp center calculations ignore pvpers that aren't getting kills, etc Was just noticing that centers weren't following the actual pvp, this should help with that
1 parent fa3af08 commit bd59c50

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

lua/cfc_random_spawn/module/sv_player_spawning.lua

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ local CLOSENESS_LIMIT = CFCRandomSpawn.Config.CLOSENESS_LIMIT ^ 2
1313
local CENTER_UPDATE_INTERVAL = customSpawnConfigForMap.centerUpdateInterval or CFCRandomSpawn.Config.CENTER_UPDATE_INTERVAL
1414
local 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+
1618
local DYNAMIC_CENTER_MINSIZE = 2000 -- getDynamicPvpCenter starts at this radius
1719
local DYNAMIC_CENTER_MAXSIZE = 4000 -- no bigger than this radius
1820
local DYNAMIC_CENTER_MINSPAWNS = 10 -- getDynamicPvpCenter needs at least this many spawns inside the radius
1921
local DYNAMIC_CENTER_MAXSPAWNS = 35 -- max possible spawns
2022
local DYNAMIC_CENTER_SPAWNCOUNTMATCHPVPERS = true -- pvp center gets bigger when more people are pvping
2123
local 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+
2331
local function defaultPvpCenter()
2432
return pvpCenters[1]
2533
end
@@ -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
8999
end
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+
91120
local function getLivingPlayers()
92121
local livingPlayers = {}
93122
local humans = player.GetAll()
@@ -196,7 +225,7 @@ end
196225
local 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

Comments
 (0)