From a01635afdc63ba1fea8ad1e9bc5d3c889543be43 Mon Sep 17 00:00:00 2001 From: lazylier <80552599+lazylier@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:58:39 -0500 Subject: [PATCH] Allow donating maximum score by donating -1 or :max (#1350) * allow donating maximum score by donating 0 or less * allow using :max in donate command * break long line in donate description * Update ranking_commands.lua --------- Co-authored-by: LoneWolfHT --- mods/ctf/ctf_modebase/ranking_commands.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mods/ctf/ctf_modebase/ranking_commands.lua b/mods/ctf/ctf_modebase/ranking_commands.lua index ee79b59a18..44b5aae130 100644 --- a/mods/ctf/ctf_modebase/ranking_commands.lua +++ b/mods/ctf/ctf_modebase/ranking_commands.lua @@ -96,7 +96,8 @@ ctf_api.register_on_match_end(function() end) ctf_core.register_chatcommand_alias("donate", "d", { - description = "Donate your match score to your teammate\nCan be used only once in 2.5 minutes", + description = "Donate your match score to your teammate\nCan be used only once in 2.5 minutes".. + "\nReplace with :max or any negative number to donate the maximum amount", params = " [message]", func = function(name, param) local current_mode = ctf_modebase:get_current_mode() @@ -113,6 +114,8 @@ ctf_core.register_chatcommand_alias("donate", "d", { dmessage = dmessage .. " " .. p elseif ctf_core.to_number(p) and score == 0 then score = p + elseif p == ":max" and score == 0 then + score = -1 else local team = ctf_teams.get(p) if not team and pcount > 0 then @@ -151,15 +154,21 @@ ctf_core.register_chatcommand_alias("donate", "d", { end score = math.floor(score) + local cur_score = math.min( + current_mode.recent_rankings.get(name).score or 0, + (current_mode.rankings:get(name) or {}).score or 0 + ) + + if score < 0 then + score = math.floor(cur_score / 2 / pcount) + end + if score < 5 then return false, "You should donate at least 5 score!" end local scoretotal = score * pcount - local cur_score = math.min( - current_mode.recent_rankings.get(name).score or 0, - (current_mode.rankings:get(name) or {}).score or 0 - ) + if scoretotal > cur_score / 2 then return false, "You can donate only half of your match score!" end