diff --git a/mods/ctf_stats/gui.lua b/mods/ctf_stats/gui.lua index d4d1dc9..2656250 100644 --- a/mods/ctf_stats/gui.lua +++ b/mods/ctf_stats/gui.lua @@ -15,7 +15,7 @@ function ctf_stats.get_formspec_match_summary(stats) return ret end -function ctf_stats.get_formspec(title, players) +local function calc_scores(players) for i = 1, #players do local pstat = players[i] pstat.kills = pstat.kills or 0 @@ -28,6 +28,10 @@ function ctf_stats.get_formspec(title, players) table.sort(players, function(one, two) return one.score > two.score end) +end + +function ctf_stats.get_formspec(title, players) + calc_scores(players) local ret = "size[12,6.5]" ret = ret .. "vertlabel[0,0;" .. title .. "]" @@ -59,6 +63,60 @@ function ctf_stats.get_formspec(title, players) return ret end +function ctf_stats.get_html(title, players) + calc_scores(players) + + local ret = "

" .. title .. "

" + ret = ret .. "" .. + "" .. + "" .. + "" .. + "" .. + "" .. + "" .. + "" .. + "" + + for i = 1, #players do + local pstat = players[i] + local color = pstat.color or "#ffffff" + ret = ret .. + "" + if i > 40 then + break + end + end + + ret = ret .. "
usernamekillsdeathsK/D ratiocapturesattemptsscore
" .. i .. + "" .. pstat.name .. + "" .. pstat.kills .. + "" .. pstat.deaths .. + "" .. math.floor(pstat.kills / (pstat.deaths + 1)*10)/10 .. + "" .. pstat.captures .. + "" .. pstat.attempts .. + "" .. math.floor(pstat.score*10)/10 .. "
\n" + return ret +end + +function ctf_stats.html_to_file(filepath) + local players = {} + for name, pstat in pairs(ctf_stats.players) do + pstat.name = name + pstat.color = nil + table.insert(players, pstat) + end + local html = ctf_stats.get_html("Player Rankings", players) + local f = io.open(filepath, "w") + f:write("\n") + f:write("\n") + f:write("\n") + f:write("Player Rankings\n") + f:write("\n") + f:write("\n") + f:write(html) + f:write("\n") + f:close() +end minetest.register_chatcommand("rankings", { func = function(name)