Add ability to list a certain user's score

This commit is contained in:
rubenwardy 2018-01-03 00:23:38 +00:00
parent ee460930b1
commit 68cea916ce
2 changed files with 55 additions and 37 deletions

View file

@ -115,9 +115,7 @@ function ctf_stats.html_to_file(filepath)
f:close() f:close()
end end
minetest.register_chatcommand("rankings", { local function send_as_chat_message(to, name)
func = function(name, param)
if param == "me" then
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
@ -142,13 +140,14 @@ minetest.register_chatcommand("rankings", {
if place < 1 then if place < 1 then
place = #players + 1 place = #players + 1
end end
minetest.chat_send_player(name, "You are in " .. place .. " place.") local you_are_in = (to == name) and "You are in " or "They are in "
minetest.chat_send_player(to, you_are_in .. place .. " place.")
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(name, minetest.chat_send_player(to,
"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 ..
@ -156,6 +155,18 @@ minetest.register_chatcommand("rankings", {
" | Attempts: " .. me.attempts .. " | Attempts: " .. me.attempts ..
" | Score: " .. me.score) " | Score: " .. me.score)
end end
end
minetest.register_chatcommand("rankings", {
func = function(name, param)
if param == "me" then
send_as_chat_message(name, name)
elseif param ~= "" then
if ctf_stats.players[param:trim()] then
send_as_chat_message(name, param:trim())
else
return false, "Can't find player '" .. param:trim() .. "'"
end
else else
local players = {} local players = {}
for pname, pstat in pairs(ctf_stats.players) do for pname, pstat in pairs(ctf_stats.players) do

View file

@ -52,6 +52,13 @@ function ctf_stats.load()
ctf.needs_save = true ctf.needs_save = true
end end
for name, player_stats in pairs(ctf_stats.players) do
if not player_stats.score or player_stats.score <= 0 then
ctf_stats.players[name] = nil
ctf.needs_save = true
end
end
ctf_stats.matches = ctf_stats.matches or { ctf_stats.matches = ctf_stats.matches or {
wins = { wins = {
blue = 0, blue = 0,