Add the donate command to donate your match score to your teammate
This commit is contained in:
parent
8a896e5b77
commit
c6a2603f19
@ -58,6 +58,77 @@ ctf_core.register_chatcommand_alias("rank", "r", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local donate_timer = {}
|
||||||
|
|
||||||
|
ctf_api.register_on_match_end(function()
|
||||||
|
donate_timer = {}
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_chatcommand("donate", {
|
||||||
|
description = "Donate your match score to your teammate\nCan be used only once in 10 minutes",
|
||||||
|
params = "<playername> <score>",
|
||||||
|
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, "^(.*) (.*)$")
|
||||||
|
|
||||||
|
if not pname then
|
||||||
|
return false, "You should provide the player name!"
|
||||||
|
end
|
||||||
|
|
||||||
|
score = tonumber(score)
|
||||||
|
if not score then
|
||||||
|
return false, "You should provide score amount!"
|
||||||
|
end
|
||||||
|
|
||||||
|
if score < 1 then
|
||||||
|
return false, "You should donate at least 1 score!"
|
||||||
|
end
|
||||||
|
|
||||||
|
if pname == name then
|
||||||
|
return false, 'You cannot donate to yourself!'
|
||||||
|
end
|
||||||
|
|
||||||
|
local team = ctf_teams.get(pname)
|
||||||
|
|
||||||
|
if not team then
|
||||||
|
return false, string.format("Player %s is not online!", pname)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ctf_teams.get(pname) ~= ctf_teams.get(name) then
|
||||||
|
return false, string.format("Player %s is not on your team!", pname)
|
||||||
|
end
|
||||||
|
|
||||||
|
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 > cur_score / 2 then
|
||||||
|
return false, "You can donate only half of your match score!"
|
||||||
|
end
|
||||||
|
|
||||||
|
if donate_timer[name] and donate_timer[name] + 600 > os.time() then
|
||||||
|
return false, "You can donate only once in 10 minutes!"
|
||||||
|
end
|
||||||
|
|
||||||
|
current_mode.recent_rankings.add(pname, {score=score}, true)
|
||||||
|
current_mode.recent_rankings.add(name, {score=-score}, true)
|
||||||
|
|
||||||
|
donate_timer[name] = os.time()
|
||||||
|
|
||||||
|
minetest.chat_send_all(minetest.colorize("#00EEFF",
|
||||||
|
string.format("%s donated %s score to %s for their hard work", name, score, pname)
|
||||||
|
))
|
||||||
|
minetest.log("action", string.format(
|
||||||
|
"Player '%s' donated %s score to player '%s'", name, score, pname
|
||||||
|
))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
local allow_reset = {}
|
local allow_reset = {}
|
||||||
minetest.register_chatcommand("reset_rankings", {
|
minetest.register_chatcommand("reset_rankings", {
|
||||||
description = minetest.colorize("red", "Resets rankings of you or another player to nothing"),
|
description = minetest.colorize("red", "Resets rankings of you or another player to nothing"),
|
||||||
@ -75,7 +146,7 @@ minetest.register_chatcommand("reset_rankings", {
|
|||||||
minetest.log("action", string.format(
|
minetest.log("action", string.format(
|
||||||
"[ctf_admin] %s reset rankings for player '%s' in mode %s", name, pname, mode_name
|
"[ctf_admin] %s reset rankings for player '%s' in mode %s", name, pname, mode_name
|
||||||
))
|
))
|
||||||
return true, "Rankings reset for player " .. pname
|
return true, string.format("Rankings reset for player '%s' in mode %s", pname, mode_name)
|
||||||
else
|
else
|
||||||
return false, "The ctf_admin priv is required to reset the rankings of other players!"
|
return false, "The ctf_admin priv is required to reset the rankings of other players!"
|
||||||
end
|
end
|
||||||
@ -96,12 +167,14 @@ minetest.register_chatcommand("reset_rankings", {
|
|||||||
mode_data.rankings:set(name, {}, true)
|
mode_data.rankings:set(name, {}, true)
|
||||||
allow_reset[key] = nil
|
allow_reset[key] = nil
|
||||||
|
|
||||||
|
minetest.log("action", string.format(
|
||||||
|
"Player '%s' reset their rankings in mode %s", name, mode_name
|
||||||
|
))
|
||||||
return true, "Your rankings have been reset"
|
return true, "Your rankings have been reset"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("top50", {
|
minetest.register_chatcommand("top50", {
|
||||||
description = "Show the top 50 players",
|
description = "Show the top 50 players",
|
||||||
params = "[mode:technical modename]",
|
params = "[mode:technical modename]",
|
||||||
@ -146,7 +219,7 @@ minetest.register_chatcommand("make_pro", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not pname then
|
if not pname then
|
||||||
return false, "You should provide the player name"
|
return false, "You should provide the player name!"
|
||||||
end
|
end
|
||||||
|
|
||||||
local old_ranks = mode_data.rankings:get(pname)
|
local old_ranks = mode_data.rankings:get(pname)
|
||||||
|
@ -32,6 +32,10 @@ return {
|
|||||||
|
|
||||||
rankings:add(player, amounts)
|
rankings:add(player, amounts)
|
||||||
end,
|
end,
|
||||||
|
get = function(player)
|
||||||
|
player = PlayerName(player)
|
||||||
|
return rankings_players[player] or {}
|
||||||
|
end,
|
||||||
set_team = function(player, team)
|
set_team = function(player, team)
|
||||||
player = PlayerName(player)
|
player = PlayerName(player)
|
||||||
local tcolor = ctf_teams.team[team].color
|
local tcolor = ctf_teams.team[team].color
|
||||||
|
Loading…
x
Reference in New Issue
Block a user