Add support for transferring player stats

This commit is contained in:
ClobberXD 2018-10-18 02:55:40 +05:30 committed by rubenwardy
parent f8a6b64627
commit e43448482b

View file

@ -254,6 +254,8 @@ local function send_as_chat_result(to, name)
end end
minetest.register_chatcommand("rankings", { minetest.register_chatcommand("rankings", {
params = "[<name>]",
description = "Display rankings of yourself or another player.",
func = function(name, param) func = function(name, param)
local target local target
if param ~= "" then if param ~= "" then
@ -285,6 +287,8 @@ minetest.register_chatcommand("rankings", {
local reset_y = {} local reset_y = {}
minetest.register_chatcommand("reset_rankings", { minetest.register_chatcommand("reset_rankings", {
params = "[<name>]",
description = "Reset the rankings of yourself or another player",
func = function(name, param) func = function(name, param)
param = param:trim() param = param:trim()
if param ~= "" and not minetest.check_player_privs(name, { ctf_admin = true}) then if param ~= "" and not minetest.check_player_privs(name, { ctf_admin = true}) then
@ -301,11 +305,40 @@ minetest.register_chatcommand("reset_rankings", {
ctf_stats.players[name] = nil ctf_stats.players[name] = nil
ctf_stats.player(reset_name) ctf_stats.player(reset_name)
return true, "Reset the stats and ranking of " .. reset_name return true, "Successfully reset the stats and ranking of " .. reset_name
end
})
minetest.register_chatcommand("transfer_rankings", {
params = "<src> <dest>",
description = "Transfer rankings of one player to another.",
privs = {ctf_admin = true},
func = function(name, param)
if not param then
return false, "Invalid syntax. Provide source and destination player names."
end
param = param:trim()
local src, dest = param:trim():match("([%a%d_-]+) ([%a%d_-]+)")
if not src or not dest then
return false, "Invalid usage, see /help transfer_rankings"
end
if not ctf_stats.players[src] then
return false, "Player '" .. src .. "' does not exist."
end
if not ctf_stats.players[dest] then
return false, "Player '" .. dest .. "' does not exist."
end
ctf_stats.players[dest] = ctf_stats.players[src]
ctf_stats.players[src] = nil
ctf.needs_save = true
return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'."
end end
}) })
minetest.register_chatcommand("summary", { minetest.register_chatcommand("summary", {
description = "Display the scoreboard of the previous match.",
func = function (name, param) func = function (name, param)
if not prev_match_summary then if not prev_match_summary then
return false, "Couldn't find the requested data." return false, "Couldn't find the requested data."