Skip to content

Commit

Permalink
Simplify suicide logic (#798)
Browse files Browse the repository at this point in the history
Refactor suicide logic to be simpler.
  • Loading branch information
nickdnk authored Jul 29, 2022
1 parent 79ac2d7 commit 121b6a0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripting/get5/stats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ public Action Stats_PlayerDeathEvent(Event event, const char[] name, bool dontBr
// fall damage is weapon id 0, attacker 0, weapon "worldspawn"
// falling from vertigo is attacker 0, weapon id 0, weapon "trigger_hurt"
// c4 is attacker 0, weapon id 0, weapon planted_c4
// with those in mind, we can determine suicide from this:
bool killedByBomb = StrEqual("planted_c4", weapon, true);
// Unfortunately molotovs are also weapon id 0, so we have to *not* consider that a suicide unless attacker == victim.
bool killedByMolotov = StrEqual("inferno", weapon, true);
bool isSuicide = !killedByBomb && (attacker == victim || (view_as<int>(weaponId) == 0 && !killedByMolotov));
// killing self with weapons is attacker == victim
// some weapons, such as unsilenced USP or M4A1S and molotov fire are also weapon 0, so weapon ID is unreliable.
// with those in mind, we can determine that suicide must be true if attacker is 0 or attacker == victim and it was **not** the bomb.
bool killedByBomb = StrEqual("planted_c4", weapon);
bool isSuicide = (!validAttacker || attacker == victim) && !killedByBomb;

IncrementPlayerStat(victim, STAT_DEATHS);
// used for calculating round KAST
Expand All @@ -727,7 +727,7 @@ public Action Stats_PlayerDeathEvent(Event event, const char[] name, bool dontBr

if (isSuicide) {
IncrementPlayerStat(victim, STAT_SUICIDES);
} else if (!killedByBomb && validAttacker) {
} else if (!killedByBomb) {
if (attackerTeam == victimTeam) {
IncrementPlayerStat(attacker, STAT_TEAMKILLS);
} else {
Expand Down

0 comments on commit 121b6a0

Please sign in to comment.