]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a parameter to the PlayerDamaged mutator hook to forbid logging damage
authorterencehill <piuntn@gmail.com>
Sat, 29 May 2021 13:04:03 +0000 (15:04 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 29 May 2021 13:04:03 +0000 (15:04 +0200)
qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc
qcsrc/common/gamemodes/gamemode/race/sv_race.qc
qcsrc/server/mutators/events.qh
qcsrc/server/player.qc

index 458465faaa260587a60563407fa72630d228c21e..00066180ffebad2ab8c4e26f6b4e809933e9c4c0 100644 (file)
@@ -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);
index ecfd3660588cf91275a71f079d9994aa1bf1ab0f..2709a3cc9311e5f604c8055ca8fe8963919993f6 100644 (file)
@@ -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);
index 35a8f6fd93b7f31900f8d8eb8341815c99f69e65..ea42b5da0b7352af582635a71fbbe43c219bc990 100644 (file)
@@ -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);
 
index bd1bc6d684f2636951cd313ca00cbacdc611fb06..aedbbae46a69168923d851f64eaf5dd73443a5ba 100644 (file)
@@ -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)
        {