Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow donating maximum score by donating 0 or less #1350

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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