Allow specifying optional param for /r

This commit is contained in:
ClobberXD 2018-12-31 04:40:39 +05:30 committed by rubenwardy
parent 2b8356511f
commit 3b4692814d

View file

@ -235,7 +235,7 @@ function ctf_stats.html_to_file(filepath)
f:close() f:close()
end end
local function send_as_chat_result(to, name) local function return_as_chat_result(to, name)
local players = {} local players = {}
for pname, pstat in pairs(ctf_stats.players) do for pname, pstat in pairs(ctf_stats.players) do
pstat.name = pname pstat.name = pname
@ -279,9 +279,21 @@ local function send_as_chat_result(to, name)
end end
minetest.register_chatcommand("r", { minetest.register_chatcommand("r", {
description = "Display your rankings as a chat result.", params = "[<name>]",
description = "Display rankings of yourself or another player as a chat result.",
func = function(name, param) func = function(name, param)
return send_as_chat_result(name, name) local target
if param ~= "" then
param = param:trim()
if ctf_stats.players[param] then
target = param
else
return false, "Can't find player '" .. param .. "'"
end
else
target = name
end
return return_as_chat_result(name, target)
end end
}) })
@ -302,7 +314,7 @@ minetest.register_chatcommand("rankings", {
end end
if not minetest.get_player_by_name(name) then if not minetest.get_player_by_name(name) then
return send_as_chat_result(name, target) return return_as_chat_result(name, target)
else else
local players = {} local players = {}
for pname, pstat in pairs(ctf_stats.players) do for pname, pstat in pairs(ctf_stats.players) do