Fix /rankings <name> not returning as chat command result

This commit is contained in:
rubenwardy 2018-01-26 23:51:36 +00:00
parent e93dbc9bc8
commit 8db15f5173

View file

@ -115,7 +115,7 @@ function ctf_stats.html_to_file(filepath)
f:close() f:close()
end end
local function send_as_chat_message(to, name) local function send_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
@ -141,29 +141,29 @@ local function send_as_chat_message(to, name)
place = #players + 1 place = #players + 1
end end
local you_are_in = (to == name) and "You are in " or "They are in " local you_are_in = (to == name) and "You are in " or "They are in "
minetest.chat_send_player(to, you_are_in .. place .. " place.") local result = you_are_in .. place .. " place.\n"
if me then if me then
local kd = me.kills local kd = me.kills
if me.deaths > 0 then if me.deaths > 0 then
kd = kd / me.deaths kd = kd / me.deaths
end end
minetest.chat_send_player(to, result = result .. "Kills: " .. me.kills ..
"Kills: " .. me.kills ..
" | Deaths: " .. me.deaths .. " | Deaths: " .. me.deaths ..
" | K/D: " .. math.floor(kd*10)/10 .. " | K/D: " .. math.floor(kd*10)/10 ..
" | Captures: " .. me.captures .. " | Captures: " .. me.captures ..
" | Attempts: " .. me.attempts .. " | Attempts: " .. me.attempts ..
" | Score: " .. me.score) " | Score: " .. me.score
end end
return true, result
end end
minetest.register_chatcommand("rankings", { minetest.register_chatcommand("rankings", {
func = function(name, param) func = function(name, param)
if param == "me" then if param == "me" then
send_as_chat_message(name, name) return send_as_chat_result(name, name)
elseif param ~= "" then elseif param ~= "" then
if ctf_stats.players[param:trim()] then if ctf_stats.players[param:trim()] then
send_as_chat_message(name, param:trim()) return send_as_chat_result(name, param:trim())
else else
return false, "Can't find player '" .. param:trim() .. "'" return false, "Can't find player '" .. param:trim() .. "'"
end end