Skip to content

Commit

Permalink
Make it possible to add a message to donations (#1242)
Browse files Browse the repository at this point in the history
* add message param to donate

* Imrpove
  • Loading branch information
a-blob authored Nov 14, 2023
1 parent d0c053f commit f3c4eb1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mods/ctf/ctf_modebase/ranking_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,21 @@ end)

minetest.register_chatcommand("donate", {
description = "Donate your match score to your teammate\nCan be used only once in 10 minutes",
params = "<playername> <score>",
params = "<playername> <score> <message>",
func = function(name, param)
local current_mode = ctf_modebase:get_current_mode()
if not current_mode or not ctf_modebase.match_started then
return false, "The match hasn't started yet!"
end

local pname, score = string.match(param, "^(.*) (.*)$")
local pname, score, dmessage = string.match(param, "^(%S*) (%S*)(.*)$")

if ctf_core.to_number(pname) then
pname, score = score, pname
end

dmessage = (dmessage and dmessage ~= "") and (":" .. dmessage) or ""

if not pname then
return false, "You should provide the player name!"
end
Expand Down Expand Up @@ -163,7 +165,7 @@ minetest.register_chatcommand("donate", {
current_mode.recent_rankings.add(name, {score=-score}, true)

donate_timer[name] = os.time()
local donate_text = string.format("%s donated %s score to %s for their hard work", name, score, pname)
local donate_text = string.format("%s donated %s score to %s%s", name, score, pname, dmessage)
minetest.chat_send_all(minetest.colorize("#00EEFF", donate_text))
ctf_modebase.announce(donate_text)

Expand Down

0 comments on commit f3c4eb1

Please sign in to comment.