From 15de3514379ef0c72b8dff0b9ac6e9aba1891491 Mon Sep 17 00:00:00 2001 From: drjaska Date: Fri, 23 Apr 2021 00:01:47 +0300 Subject: [PATCH] Added cvars to support changing how score is calculated added a cvar for toggling if frags give 1 score or not, added a cvar for toggling if damage gives score or not and added a cvar for changing how much score damage gives --- gamemodes-server.cfg | 6 ++++ .../gamemodes/gamemode/mayhem/sv_mayhem.qc | 29 ++++++++++++++++++- .../gamemodes/gamemode/tmayhem/sv_tmayhem.qc | 29 ++++++++++++++++++- qcsrc/server/world.qc | 6 ++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/gamemodes-server.cfg b/gamemodes-server.cfg index 8f4303f2b..f2b342285 100644 --- a/gamemodes-server.cfg +++ b/gamemodes-server.cfg @@ -583,6 +583,9 @@ set g_mayhem_regenerate 0 "allow players to regenerate hp. rates controlled by h set g_mayhem_weaponarena "most_available" "starting weapons - takes the same options as g_weaponarena" set g_mayhem_powerups 1 "Allow powerups in mayhem. Only checked if g_powerups is -1 therefore this will be overridden by g_powerups 1 or 0" set g_mayhem_selfdamage 0 "0 = disable selfdamage in mayhem, 1 = enable selfdamage in mayhem" +set g_mayhem_frags2score 1 "enable frags counting towards score" +set g_mayhem_damage2score 0 "enable damage counting towards score" +set g_mayhem_damage2score_multiplier 0.0025 "how much score is given for damage dealt. 0.01 -> 1k dmg = 10 score, 0.001 1k dmg = 1 score, 0.0025 400 dmg = 1 score" set g_tmayhem 0 "Team Mayhem: the team with the most frags in total mayhem wins" set g_tmayhem_teams 2 "how many teams are in team mayhem (set by mapinfo)" @@ -594,3 +597,6 @@ set g_tmayhem_weaponarena "most_available" "starting weapons - takes the same op set g_tmayhem_powerups 1 "Allow powerups in team mayhem. Only checked if g_powerups is -1 therefore this will be overridden by g_powerups 1 or 0" set g_tmayhem_regenerate 0 "allow players to regenerate hp. rates controlled by hp regeneration and rotting cvars" set g_tmayhem_selfdamage 0 "0 = disable selfdamage in tmayhem, 1 = enable selfdamage in tmayhem" +set g_tmayhem_frags2score 1 "enable frags counting towards score" +set g_tmayhem_damage2score 0 "enable damage counting towards score" +set g_tmayhem_damage2score_multiplier 0.0025 "how much score is given for damage dealt. 0.01 -> 1k dmg = 10 score, 0.001 1k dmg = 1 score, 0.0025 400 dmg = 1 score" diff --git a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc index 76939a32e..8122aed7c 100644 --- a/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc @@ -4,6 +4,9 @@ bool autocvar_g_mayhem_regenerate; string autocvar_g_mayhem_weaponarena; bool autocvar_g_mayhem_powerups; bool autocvar_g_mayhem_selfdamage; +bool autocvar_g_mayhem_frags2score; +bool autocvar_g_mayhem_damage2score; +float autocvar_g_mayhem_damage2score_multiplier; MUTATOR_HOOKFUNCTION(mayhem, Scores_CountFragsRemaining) { @@ -72,4 +75,28 @@ MUTATOR_HOOKFUNCTION(mayhem, Damage_Calculate) frag_damage = 0; M_ARGV(4, float) = frag_damage; -} \ No newline at end of file +} + +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_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)); + + float excess = max(0, frag_damage - damage_take - damage_save); + + if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) + GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_mayhem_damage2score_multiplier); + } +} + +MUTATOR_HOOKFUNCTION(mayhem, GiveFragsForKill, CBC_ORDER_FIRST) +{ + if(!autocvar_g_mayhem_frags2score){ + M_ARGV(2, float) = 0; + return true; + } +} diff --git a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc index dd5c6b81e..3554f5a3b 100644 --- a/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc +++ b/qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc @@ -8,6 +8,9 @@ bool autocvar_g_tmayhem_regenerate; string autocvar_g_tmayhem_weaponarena; bool autocvar_g_tmayhem_powerups; bool autocvar_g_tmayhem_selfdamage; +bool autocvar_g_tmayhem_frags2score; +bool autocvar_g_tmayhem_damage2score; +float autocvar_g_tmayhem_damage2score_multiplier; // code from here on is just to support maps that don't have team entities void tmayhem_SpawnTeam (string teamname, int teamcolor) @@ -130,4 +133,28 @@ MUTATOR_HOOKFUNCTION(tmayhem, Damage_Calculate) M_ARGV(4, float) = frag_damage; M_ARGV(5, float) = frag_mirrordamage; -} \ No newline at end of file +} + +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_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)); + + float excess = max(0, frag_damage - damage_take - damage_save); + + 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); + } +} + +MUTATOR_HOOKFUNCTION(tmayhem, GiveFragsForKill, CBC_ORDER_FIRST) +{ + if(!autocvar_g_tmayhem_frags2score){ + M_ARGV(2, float) = 0; + return true; + } +} diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 6e21db8a9..3f4445d08 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -382,6 +382,12 @@ void cvar_changes_init() BADCVAR("g_tmayhem_point_limit"); BADCVAR("leadlimit_and_fraglimit"); BADCVAR("leadlimit_override"); + BADCVAR("g_mayhem_frags2score"); + BADCVAR("g_mayhem_damage2score"); + BADCVAR("g_mayhem_damage2score_multiplier"); + BADCVAR("g_tmayhem_frags2score"); + BADCVAR("g_tmayhem_damage2score"); + BADCVAR("g_tmayhem_damage2score_multiplier"); BADCVAR("pausable"); BADCVAR("sv_announcer"); BADCVAR("sv_checkforpacketsduringsleep"); -- 2.39.2