From 6655ec22529cebd3aea76606867347b17aebd175 Mon Sep 17 00:00:00 2001 From: drjaska Date: Fri, 3 Dec 2021 06:59:22 +0200 Subject: [PATCH] fixed friendly fire giving score, added cvars for dmg&frags scoring method for how much score dmg and frags give --- gamemodes-server.cfg | 8 +- .../gamemodes/gamemode/mayhem/sv_mayhem.qc | 83 +++++++++++----- .../gamemodes/gamemode/mayhem/sv_mayhem.qh | 5 +- .../gamemodes/gamemode/tmayhem/sv_tmayhem.qc | 95 +++++++++++++------ .../gamemodes/gamemode/tmayhem/sv_tmayhem.qh | 7 +- qcsrc/server/world.qc | 4 + 6 files changed, 139 insertions(+), 63 deletions(-) diff --git a/gamemodes-server.cfg b/gamemodes-server.cfg index 4ad27e58f..e00eae6ff 100644 --- a/gamemodes-server.cfg +++ b/gamemodes-server.cfg @@ -584,8 +584,12 @@ set g_duel_not_dm_maps 0 "when this is set, DM maps will NOT be listed in duel" set g_mayhem 0 "Mayhem: Compete for the most damage dealt and frags in this chaotic mayhem!" set g_tmayhem 0 "Team Mayhem: Compete with your team for the most damage dealt and frags in this chaotic mayhem!" -set g_mayhem_scoringmethod 1 "1: 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage." -set g_tmayhem_scoringmethod 1 "1: 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage." +set g_mayhem_scoringmethod 1 "1: By default 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage." +set g_tmayhem_scoringmethod 1 "1: By default 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage." +set g_mayhem_scoringmethod_damage_weight 0.75 "for the first scoring method how much is damage equal to player's spawning health worth in score" +set g_tmayhem_scoringmethod_damage_weight 0.75 "for the first scoring method how much is damage equal to player's spawning health worth in score" +set g_mayhem_scoringmethod_frag_weight 0.25 "for the first scoring method how much is a frag worth in score" +set g_tmayhem_scoringmethod_frag_weight 0.25 "for the first scoring method how much is a frag worth in score" set g_mayhem_fraglimit 30 "Team Mayhem basis for how many frags until the match ends, edit this over point_limit preferably" set g_tmayhem_fraglimit 50 "Team Mayhem basis for how many frags until the match ends, edit this over point_limit preferably" diff --git a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc index 4fb6f9ed0..1e2d801ed 100644 --- a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc @@ -1,10 +1,16 @@ #include "sv_mayhem.qh" +float autocvar_g_mayhem_fraglimit; +float autocvar_g_mayhem_visual_score_limit; +float mayhempointmultiplier; + bool autocvar_g_mayhem_regenerate; string autocvar_g_mayhem_weaponarena; bool autocvar_g_mayhem_powerups; bool autocvar_g_mayhem_selfdamage; int autocvar_g_mayhem_scoringmethod; +float autocvar_g_mayhem_scoringmethod_damage_weight; +float autocvar_g_mayhem_scoringmethod_frag_weight; bool autocvar_g_mayhem_pickup_items; bool autocvar_g_mayhem_pickup_items_remove_weapons_and_ammo; bool autocvar_g_mayhem_unlimited_ammo; @@ -180,11 +186,11 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor) //non-friendly fire if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) - GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue))); + GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue))); //friendly fire aka self damage if (frag_target == frag_attacker && IS_PLAYER(frag_attacker)) - GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue))); + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue))); //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded //deathtypes: @@ -199,7 +205,7 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor) frag_deathtype == DEATH_LAVA.m_id || frag_deathtype == DEATH_SLIME.m_id || frag_deathtype == DEATH_SWAMP.m_id)) - GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue))); + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue))); return; } } @@ -207,29 +213,60 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor) MUTATOR_HOOKFUNCTION(mayhem, GiveFragsForKill, CBC_ORDER_FIRST) { - switch(autocvar_g_mayhem_scoringmethod) - { - //frags only - case 2: - { - //fix 999 score from 30 kills for example - M_ARGV(2, float) = 1 * mayhempointmultiplier * 1.0001; - return true; - } - - //damage only - case 3: + entity frag_attacker = M_ARGV(0, entity); + entity frag_target = M_ARGV(1, entity); + + if(frag_target == frag_attacker){ + switch(autocvar_g_mayhem_scoringmethod) { - M_ARGV(2, float) = 0; - return true; + //frags only + case 2: + { + //fix 999 score from 30 kills for example + M_ARGV(2, float) = -1 * mayhempointmultiplier * 1.0001; + return true; + } + + //damage only + case 3: + { + M_ARGV(2, float) = 0; + return true; + } + + //combined damage and frags + default: + case 1: + { + M_ARGV(2, float) = -autocvar_g_mayhem_scoringmethod_frag_weight * mayhempointmultiplier * 1.0001; + return true; + } } - - //combined damage and frags - default: - case 1: + } else { + switch(autocvar_g_mayhem_scoringmethod) { - M_ARGV(2, float) = 0.25 * mayhempointmultiplier * 1.0001; - return true; + //frags only + case 2: + { + //fix 999 score from 30 kills for example + M_ARGV(2, float) = 1 * mayhempointmultiplier * 1.0001; + return true; + } + + //damage only + case 3: + { + M_ARGV(2, float) = 0; + return true; + } + + //combined damage and frags + default: + case 1: + { + M_ARGV(2, float) = autocvar_g_mayhem_scoringmethod_frag_weight * mayhempointmultiplier * 1.0001; + return true; + } } } } diff --git a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qh b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qh index 9393b311f..69b2878df 100644 --- a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qh +++ b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qh @@ -1,10 +1,7 @@ #pragma once #include -//someone who understands numbers better check if 2 following floats can be ints without imprecision, I'm scared of spaghettimonsters -float autocvar_g_mayhem_fraglimit; -float autocvar_g_mayhem_visual_score_limit; -float mayhempointmultiplier = 1000/30; + void mayhem_Initialize(); REGISTER_MUTATOR(mayhem, false) diff --git a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc index 36db8b91c..198bc587c 100644 --- a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc @@ -1,5 +1,11 @@ #include "sv_tmayhem.qh" +float autocvar_g_tmayhem_fraglimit; +float autocvar_g_tmayhem_visual_score_limit; +float autocvar_g_tmayhem_score_leadlimit; +bool autocvar_g_tmayhem_team_spawns; +float tmayhempointmultiplier; + // TODO? rename to teammayhem? requires checking alias and other string lengths int autocvar_g_tmayhem_teams; int autocvar_g_tmayhem_teams_override; @@ -9,6 +15,8 @@ string autocvar_g_tmayhem_weaponarena; bool autocvar_g_tmayhem_powerups; bool autocvar_g_tmayhem_selfdamage; int autocvar_g_tmayhem_scoringmethod; +float autocvar_g_tmayhem_scoringmethod_damage_weight; +float autocvar_g_tmayhem_scoringmethod_frag_weight; bool autocvar_g_tmayhem_pickup_items; bool autocvar_g_tmayhem_pickup_items_remove_weapons_and_ammo; bool autocvar_g_tmayhem_unlimited_ammo; @@ -189,11 +197,11 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) float excess = max(0, frag_damage - damage_take - damage_save); //non-friendly fire - if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) + if (IS_PLAYER(frag_attacker) && !SAME_TEAM(frag_target, frag_attacker)) GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); //friendly fire or self damage - if (frag_target == frag_attacker && IS_PLAYER(frag_attacker)) + if (frag_target == frag_attacker && IS_PLAYER(frag_attacker) || SAME_TEAM(frag_target, frag_attacker)) GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded @@ -208,7 +216,7 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) frag_deathtype == DEATH_CAMP.m_id || frag_deathtype == DEATH_LAVA.m_id || frag_deathtype == DEATH_SLIME.m_id)) - GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); return; } @@ -226,12 +234,12 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) float excess = max(0, frag_damage - damage_take - damage_save); //non-friendly fire - if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) - GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); + if (IS_PLAYER(frag_attacker) && !SAME_TEAM(frag_target, frag_attacker)) + GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_tmayhem_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); //friendly fire or self damage - if (frag_target == frag_attacker && IS_PLAYER(frag_attacker)) - GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); + 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_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded //deathtypes: @@ -245,7 +253,7 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) frag_deathtype == DEATH_CAMP.m_id || frag_deathtype == DEATH_LAVA.m_id || frag_deathtype == DEATH_SLIME.m_id)) - GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); + GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_tmayhem_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue))); return; } } @@ -253,29 +261,60 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor) MUTATOR_HOOKFUNCTION(tmayhem, GiveFragsForKill, CBC_ORDER_FIRST) { - switch(autocvar_g_tmayhem_scoringmethod) - { - //frags only - case 2: - { - //fix 999 score from 30 kills for example - M_ARGV(2, float) = 1 * tmayhempointmultiplier * 1.0001; - return true; - } - - //damage only - case 3: + entity frag_attacker = M_ARGV(0, entity); + entity frag_target = M_ARGV(1, entity); + + if(SAME_TEAM(frag_target, frag_attacker)){ + switch(autocvar_g_tmayhem_scoringmethod) { - M_ARGV(2, float) = 0; - return true; + //frags only + case 2: + { + //fix 999 score from 30 kills for example + M_ARGV(2, float) = -1 * tmayhempointmultiplier * 1.0001; + return true; + } + + //damage only + case 3: + { + M_ARGV(2, float) = 0; + return true; + } + + //combined damage and frags + default: + case 1: + { + M_ARGV(2, float) = -autocvar_g_tmayhem_scoringmethod_frag_weight * tmayhempointmultiplier * 1.0001; + return true; + } } - - //combined damage and frags - default: - case 1: + } else { + switch(autocvar_g_tmayhem_scoringmethod) { - M_ARGV(2, float) = 0.25 * tmayhempointmultiplier * 1.0001; - return true; + //frags only + case 2: + { + //fix 999 score from 30 kills for example + M_ARGV(2, float) = 1 * tmayhempointmultiplier * 1.0001; + return true; + } + + //damage only + case 3: + { + M_ARGV(2, float) = 0; + return true; + } + + //combined damage and frags + default: + case 1: + { + M_ARGV(2, float) = autocvar_g_tmayhem_scoringmethod_frag_weight * tmayhempointmultiplier * 1.0001; + return true; + } } } } diff --git a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qh b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qh index d8dbcdf76..c31967fad 100644 --- a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qh +++ b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qh @@ -1,12 +1,7 @@ #pragma once #include -//someone who understands numbers better check if 2 following floats can be ints without imprecision, I'm scared of spaghettimonsters -float autocvar_g_tmayhem_fraglimit; -float autocvar_g_tmayhem_visual_score_limit; -float autocvar_g_tmayhem_score_leadlimit; -bool autocvar_g_tmayhem_team_spawns; -float tmayhempointmultiplier = 1000/50; + void tmayhem_Initialize(); REGISTER_MUTATOR(tmayhem, false) diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 279bb7d53..e59d0c9d8 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -388,7 +388,11 @@ void cvar_changes_init() BADCVAR("leadlimit_and_fraglimit"); BADCVAR("leadlimit_override"); BADCVAR("g_mayhem_scoringmethod"); + BADCVAR("g_mayhem_scoringmethod_damage_weight"); + BADCVAR("g_mayhem_scoringmethod_frag_weight"); BADCVAR("g_tmayhem_scoringmethod"); + BADCVAR("g_tmayhem_scoringmethod_damage_weight"); + BADCVAR("g_tmayhem_scoringmethod_frag_weight"); BADCVAR("pausable"); BADCVAR("sv_announcer"); BADCVAR("sv_checkforpacketsduringsleep"); -- 2.39.2