From 615d4369f641f236b254865a16fdfd1822fe631e Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 9 Feb 2021 16:10:53 -0800 Subject: [PATCH 1/3] Improve kill assist mod --- mods/pvp/kill_assist/init.lua | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/mods/pvp/kill_assist/init.lua b/mods/pvp/kill_assist/init.lua index 7cabbb0..3701dfa 100644 --- a/mods/pvp/kill_assist/init.lua +++ b/mods/pvp/kill_assist/init.lua @@ -11,45 +11,37 @@ function kill_assist.clear_assists(player) end function kill_assist.add_assist(victim, attacker, damage) + if victim == attacker then return end + if not kill_assists[victim] then - kill_assists[victim] = {} + kill_assists[victim] = { + players = {}, + hp_offset = 0 + } end - kill_assists[victim][attacker] = (kill_assists[victim][attacker] or 0) + damage + kill_assists[victim].players[attacker] = (kill_assists[victim].players[attacker] or 0) + damage end function kill_assist.add_heal_assist(victim, healed_hp) if not kill_assists[victim] then return end - for name, damage in pairs(kill_assists[victim]) do - kill_assists[victim][name] = math.max(damage - healed_hp, 0) - end + -- Player names can't contain '!' so it's safe to use here + kill_assists[victim].hp_offset = kill_assists[victim].hp_offset + healed_hp end function kill_assist.reward_assists(victim, killer, reward) if not kill_assists[victim] then return end - for name, damage in pairs(kill_assists[victim]) do - if minetest.get_player_by_name(name) and name ~= victim then - local standard = 0 + for name, damage in pairs(kill_assists[victim].players) do + if name ~= "!offset" and minetest.get_player_by_name(name) then local max_hp = minetest.get_player_by_name(victim):get_properties().max_hp or 20 - local help_percent = damage / max_hp + local help_percent = damage / (max_hp + kill_assists[victim].hp_offset) local main, match = ctf_stats.player(name) local color = "0x00FFFF" - if name ~= killer then - standard = 0.3 - help_percent = math.min(help_percent, 0.75) - else - help_percent = math.min(help_percent, 1) - end - - if help_percent >= standard then - reward = math.floor((reward * help_percent)*100)/100 - end - - if reward < 1 then - reward = 1 + if name == killer or help_percent >= 0.33 then + reward = math.min(math.floor((reward * help_percent)*100)/100, 1) end match.score = match.score + reward From fdfad82844eaaa30b03de4aab3a948ddeeb09492 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 9 Feb 2021 19:11:19 -0800 Subject: [PATCH 2/3] Fix incorrect usage of math.min --- mods/pvp/kill_assist/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/pvp/kill_assist/init.lua b/mods/pvp/kill_assist/init.lua index 3701dfa..8e48655 100644 --- a/mods/pvp/kill_assist/init.lua +++ b/mods/pvp/kill_assist/init.lua @@ -41,7 +41,7 @@ function kill_assist.reward_assists(victim, killer, reward) local color = "0x00FFFF" if name == killer or help_percent >= 0.33 then - reward = math.min(math.floor((reward * help_percent)*100)/100, 1) + reward = math.max(math.floor((reward * help_percent)*100)/100, 0) end match.score = match.score + reward From c703733e6f6ea77a96654521958a231a69662d12 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 9 Feb 2021 19:15:36 -0800 Subject: [PATCH 3/3] Clean up kill assist code --- mods/pvp/kill_assist/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/pvp/kill_assist/init.lua b/mods/pvp/kill_assist/init.lua index 8e48655..ff0fafa 100644 --- a/mods/pvp/kill_assist/init.lua +++ b/mods/pvp/kill_assist/init.lua @@ -26,7 +26,6 @@ end function kill_assist.add_heal_assist(victim, healed_hp) if not kill_assists[victim] then return end - -- Player names can't contain '!' so it's safe to use here kill_assists[victim].hp_offset = kill_assists[victim].hp_offset + healed_hp end @@ -41,7 +40,7 @@ function kill_assist.reward_assists(victim, killer, reward) local color = "0x00FFFF" if name == killer or help_percent >= 0.33 then - reward = math.max(math.floor((reward * help_percent)*100)/100, 0) + reward = math.max(math.floor((reward * help_percent)*100)/100, 1) end match.score = match.score + reward