From d7dbab28da0f09fd11017c3e9c3d7d7dfa857867 Mon Sep 17 00:00:00 2001 From: drjaska Date: Sun, 25 Apr 2021 08:14:28 +0300 Subject: [PATCH] added friendly fire and self damage handling to dmg2score some players might try to cheese or avoid giving other players score and thus suicide or do self damage, they are now punished for it but they are not punished while having a logged attacker so getting pushed into a void doesn't punish the dying player as long as pusher is given score. I assume DEATH_FIRE is an environmental hazard but I don't know any maps which'd have it for testing though if it's a weapon effect which registers an attacker it's irrelevant except for being unused code. --- .../gamemodes/gamemode/mayhem/sv_mayhem.qc | 21 +++++++++++++++++++ .../gamemodes/gamemode/tmayhem/sv_tmayhem.qc | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc index 8122aed7c..fffd16820 100644 --- a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc @@ -82,6 +82,7 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor) if(autocvar_g_mayhem_damage2score){ entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); + float frag_deathtype = M_ARGV(6, float); float frag_damage = M_ARGV(7, float); float damage_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH)); float damage_save = bound(0, M_ARGV(5, float), GetResource(frag_target, RES_ARMOR)); @@ -90,6 +91,26 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor) if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_mayhem_damage2score_multiplier); + + if (frag_target == frag_attacker && IS_PLAYER(frag_attacker)) + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_damage2score_multiplier); + + //campcheck deals damage with 8194 ID while DEATH_CAMP has 390 ID and DEATH_SELF_CAMP has 0 ID, idk why + if (!IS_PLAYER(frag_attacker) && ( + frag_deathtype == DEATH_DROWN.m_id || + frag_deathtype == DEATH_HURTTRIGGER.m_id || + frag_deathtype == DEATH_FIRE.m_id || + frag_deathtype == 8194.000000 || + frag_deathtype == DEATH_LAVA.m_id || + frag_deathtype == DEATH_SLIME.m_id)) + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_damage2score_multiplier); + + //autocvar_g_mayhem_frags2score is checked to avoid punishing twice for a suicide + //when hp and armor values are checked when suiciding for some reason they are 0.9 hp and 0 armor regardless that player suicided with 200+200 + //AFAIK dynamic hp value checking is not possible, hardcoded start hp and armor + //FIXME: ^ , might require fixing hp+a check for suicides as a whole + if (frag_deathtype == DEATH_KILL.m_id && !autocvar_g_mayhem_frags2score) + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (start_health + start_armorvalue)) * autocvar_g_mayhem_damage2score_multiplier); } } diff --git a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc index 3554f5a3b..c317b6769 100644 --- a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc @@ -140,6 +140,7 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) if(autocvar_g_tmayhem_damage2score){ entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); + float frag_deathtype = M_ARGV(6, float); float frag_damage = M_ARGV(7, float); float damage_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH)); float damage_save = bound(0, M_ARGV(5, float), GetResource(frag_target, RES_ARMOR)); @@ -148,6 +149,26 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) if (frag_target != frag_attacker && IS_PLAYER(frag_attacker) && DIFF_TEAM(frag_target, frag_attacker)) GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_tmayhem_damage2score_multiplier); + + if (frag_target == frag_attacker && IS_PLAYER(frag_attacker) || SAME_TEAM(frag_target, frag_attacker)) + GameRules_scoring_add_team(frag_attacker, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_tmayhem_damage2score_multiplier); + + //campcheck deals damage with 8194 ID while DEATH_CAMP has 390 ID and DEATH_SELF_CAMP has 0 ID, idk why + if (!IS_PLAYER(frag_attacker) && ( + frag_deathtype == DEATH_DROWN.m_id || + frag_deathtype == DEATH_HURTTRIGGER.m_id || + frag_deathtype == DEATH_FIRE.m_id || + frag_deathtype == 8194.000000 || + frag_deathtype == DEATH_LAVA.m_id || + frag_deathtype == DEATH_SLIME.m_id)) + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_tmayhem_damage2score_multiplier); + + //autocvar_g_tmayhem_frags2score is checked to avoid punishing twice for a suicide + //when hp and armor values are checked when suiciding for some reason they are 0.9 hp and 0 armor regardless that player suicided with 200+200 + //AFAIK dynamic hp value checking is not possible, hardcoded start hp and armor + //FIXME: ^ , might require fixing hp+a check for suicides as a whole + if (frag_deathtype == DEATH_KILL.m_id && !autocvar_g_tmayhem_frags2score) + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (start_health + start_armorvalue)) * autocvar_g_tmayhem_damage2score_multiplier); } } -- 2.39.2