Add ability to list a certain user's score
This commit is contained in:
parent
ee460930b1
commit
68cea916ce
2 changed files with 55 additions and 37 deletions
|
@ -115,46 +115,57 @@ function ctf_stats.html_to_file(filepath)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function send_as_chat_message(to, name)
|
||||||
|
local players = {}
|
||||||
|
for pname, pstat in pairs(ctf_stats.players) do
|
||||||
|
pstat.name = pname
|
||||||
|
pstat.color = nil
|
||||||
|
table.insert(players, pstat)
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(players, function(one, two)
|
||||||
|
return one.score > two.score
|
||||||
|
end)
|
||||||
|
|
||||||
|
local place = -1
|
||||||
|
local me = nil
|
||||||
|
for i = 1, #players do
|
||||||
|
local pstat = players[i]
|
||||||
|
if pstat.name == name then
|
||||||
|
me = pstat
|
||||||
|
place = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if place < 1 then
|
||||||
|
place = #players + 1
|
||||||
|
end
|
||||||
|
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(to,
|
||||||
|
"Kills: " .. me.kills ..
|
||||||
|
" | Deaths: " .. me.deaths ..
|
||||||
|
" | K/D: " .. math.floor(kd*10)/10 ..
|
||||||
|
" | Captures: " .. me.captures ..
|
||||||
|
" | Attempts: " .. me.attempts ..
|
||||||
|
" | Score: " .. me.score)
|
||||||
|
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
|
||||||
local players = {}
|
send_as_chat_message(name, name)
|
||||||
for pname, pstat in pairs(ctf_stats.players) do
|
elseif param ~= "" then
|
||||||
pstat.name = pname
|
if ctf_stats.players[param:trim()] then
|
||||||
pstat.color = nil
|
send_as_chat_message(name, param:trim())
|
||||||
table.insert(players, pstat)
|
else
|
||||||
end
|
return false, "Can't find player '" .. param:trim() .. "'"
|
||||||
|
|
||||||
table.sort(players, function(one, two)
|
|
||||||
return one.score > two.score
|
|
||||||
end)
|
|
||||||
|
|
||||||
local place = -1
|
|
||||||
local me = nil
|
|
||||||
for i = 1, #players do
|
|
||||||
local pstat = players[i]
|
|
||||||
if pstat.name == name then
|
|
||||||
me = pstat
|
|
||||||
place = i
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if place < 1 then
|
|
||||||
place = #players + 1
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name, "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,
|
|
||||||
"Kills: " .. me.kills ..
|
|
||||||
" | Deaths: " .. me.deaths ..
|
|
||||||
" | K/D: " .. math.floor(kd*10)/10 ..
|
|
||||||
" | Captures: " .. me.captures ..
|
|
||||||
" | Attempts: " .. me.attempts ..
|
|
||||||
" | Score: " .. me.score)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local players = {}
|
local players = {}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue