From 52c5596d6f8a01deb8b2401753d735841ea154ee Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 29 May 2021 15:04:03 +0200 Subject: [PATCH] Add a parameter to the PlayerDamaged mutator hook to forbid logging damage --- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 7 +++++ .../common/gamemodes/gamemode/race/sv_race.qc | 7 +++++ qcsrc/server/mutators/events.qh | 1 + qcsrc/server/player.qc | 30 +++++++++---------- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 458465faa..00066180f 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -235,6 +235,13 @@ MUTATOR_HOOKFUNCTION(cts, PutClientInServer) } } +MUTATOR_HOOKFUNCTION(cts, PlayerDamaged) +{ + int frag_deathtype = M_ARGV(5, int); + if (frag_deathtype == DEATH_KILL.m_id) + M_ARGV(0, bool) = true; // forbid_damage_logging +} + MUTATOR_HOOKFUNCTION(cts, PlayerDies) { entity frag_target = M_ARGV(2, entity); diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index ecfd36605..2709a3cc9 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -285,6 +285,13 @@ MUTATOR_HOOKFUNCTION(rc, PutClientInServer) } } +MUTATOR_HOOKFUNCTION(rc, PlayerDamaged) +{ + int frag_deathtype = M_ARGV(5, int); + if (frag_deathtype == DEATH_KILL.m_id) + M_ARGV(0, bool) = true; // forbid_damage_logging +} + MUTATOR_HOOKFUNCTION(rc, PlayerDies) { entity frag_target = M_ARGV(2, entity); diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 35a8f6fd9..ea42b5da0 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -458,6 +458,7 @@ MUTATOR_HOOKABLE(Damage_Calculate, EV_Damage_Calculate); /** location */ i(vector, MUTATOR_ARGV_4_vector) \ /** deathtype */ i(int, MUTATOR_ARGV_5_int) \ /** potential_damage */ i(float, MUTATOR_ARGV_6_float) \ + /** forbid_damage_logging */ o(bool, MUTATOR_ARGV_0_bool) \ /**/ MUTATOR_HOOKABLE(PlayerDamaged, EV_PlayerDamaged); diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index bd1bc6d68..aedbbae46 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -387,21 +387,6 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake; this.v_angle_x = bound(-90, this.v_angle.x, 90); } - - float realdmg = damage - excess; - if ((this != attacker || deathtype == DEATH_KILL.m_id) && realdmg && !STAT(FROZEN, this) - && (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime)) - { - if (IS_PLAYER(attacker) && DIFF_TEAM(attacker, this) && deathtype != DEATH_KILL.m_id) { - GameRules_scoring_add(attacker, DMG, realdmg); - } - // don't count DEATH_KILL damage in game modes where suicide is for respawning - // TODO mutator hook? - if (deathtype != DEATH_KILL.m_id || !(IS_GAMETYPE(RACE) || IS_GAMETYPE(CTS))) - if (IS_PLAYER(this)) { - GameRules_scoring_add(this, DMGTAKEN, realdmg); - } - } } else this.max_armorvalue += (save + take); @@ -436,7 +421,22 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da); } + bool forbid_damage_logging = false; MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage); + forbid_damage_logging = M_ARGV(0, bool); + + if ((dh || da) && !forbid_damage_logging) + { + float realdmg = damage - excess; + if ((this != attacker || deathtype == DEATH_KILL.m_id) && realdmg && !STAT(FROZEN, this) + && (!(round_handler_IsActive() && !round_handler_IsRoundStarted()) && time >= game_starttime)) + { + if (IS_PLAYER(attacker) && DIFF_TEAM(attacker, this) && deathtype != DEATH_KILL.m_id) + GameRules_scoring_add(attacker, DMG, realdmg); + if (IS_PLAYER(this)) + GameRules_scoring_add(this, DMGTAKEN, realdmg); + } + } if (GetResource(this, RES_HEALTH) < 1) { -- 2.39.2