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()
end
minetest.register_chatcommand("rankings", {
func = function(name, param)
if param == "me" then
local function send_as_chat_message(to, name)
local players = {}
for pname, pstat in pairs(ctf_stats.players) do
pstat.name = pname
@ -142,13 +140,14 @@ minetest.register_chatcommand("rankings", {
if place < 1 then
place = #players + 1
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
local kd = me.kills
if me.deaths > 0 then
kd = kd / me.deaths
end
minetest.chat_send_player(name,
minetest.chat_send_player(to,
"Kills: " .. me.kills ..
" | Deaths: " .. me.deaths ..
" | K/D: " .. math.floor(kd*10)/10 ..
@ -156,6 +155,18 @@ minetest.register_chatcommand("rankings", {
" | Attempts: " .. me.attempts ..
" | Score: " .. me.score)
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
local players = {}
for pname, pstat in pairs(ctf_stats.players) do

View file

@ -52,6 +52,13 @@ function ctf_stats.load()
ctf.needs_save = true
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 {
wins = {
blue = 0,