]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
added friendly fire and self damage handling to dmg2score
authordrjaska <drjaska83@gmail.com>
Sun, 25 Apr 2021 05:14:28 +0000 (08:14 +0300)
committerdrjaska <drjaska83@gmail.com>
Sun, 25 Apr 2021 05:14:28 +0000 (08:14 +0300)
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.

qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc
qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc

index 8122aed7cbc91598842567a21b0f3c22fff24936..fffd1682037f6c242a7fe234aea990c50a687c35 100644 (file)
@@ -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);
        }
 }
 
index 3554f5a3b0a4cc7a8d66b8c14df90a268f300863..c317b6769f6d674ab8b3e449118a551e34316873 100644 (file)
@@ -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);
        }
 }