Skip to content

Commit

Permalink
Allow donating maximum score by donating -1 or :max (#1350)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lazylier and LoneWolfHT authored Nov 10, 2024
1 parent e207edf commit a01635a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions mods/ctf/ctf_modebase/ranking_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <score> with :max or any negative number to donate the maximum amount",
params = "<name [name2 name3 ...]> <score> [message]",
func = function(name, param)
local current_mode = ctf_modebase:get_current_mode()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a01635a

Please sign in to comment.