2015-12-03 23:46:52 +00:00
|
|
|
function ctf_stats.get_formspec_match_summary(stats)
|
|
|
|
local players = {}
|
|
|
|
for name, pstat in pairs(stats.red) do
|
|
|
|
pstat.name = name
|
|
|
|
pstat.color = ctf.flag_colors.red
|
|
|
|
table.insert(players, pstat)
|
|
|
|
end
|
|
|
|
for name, pstat in pairs(stats.blue) do
|
|
|
|
pstat.name = name
|
|
|
|
pstat.color = ctf.flag_colors.blue
|
|
|
|
table.insert(players, pstat)
|
|
|
|
end
|
2015-12-03 23:57:28 +00:00
|
|
|
local ret = ctf_stats.get_formspec("Match Summary", players)
|
2015-12-03 23:46:52 +00:00
|
|
|
ret = ret .. "label[3.5,6.2;Tip: type /rankings for league tables]"
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2015-12-03 23:57:28 +00:00
|
|
|
function ctf_stats.get_formspec(title, players)
|
2015-12-04 11:16:33 +00:00
|
|
|
for i = 1, #players do
|
2015-12-04 11:14:22 +00:00
|
|
|
local pstat = players[i]
|
|
|
|
pstat.kills = pstat.kills or 0
|
|
|
|
pstat.deaths = pstat.deaths or 0
|
|
|
|
pstat.captures = pstat.captures or 0
|
|
|
|
pstat.attempts = pstat.attempts or 0
|
2015-12-04 11:24:39 +00:00
|
|
|
pstat.score = 0.1 * pstat.kills + 10 * pstat.captures +
|
2015-12-04 11:25:41 +00:00
|
|
|
5 * pstat.attempts + 5 * pstat.kills / (pstat.deaths + 1)
|
2015-12-03 23:46:52 +00:00
|
|
|
end
|
|
|
|
table.sort(players, function(one, two)
|
2015-12-04 11:14:22 +00:00
|
|
|
return one.score > two.score
|
2015-12-03 23:46:52 +00:00
|
|
|
end)
|
|
|
|
|
2015-12-04 11:21:25 +00:00
|
|
|
local ret = "size[12,6.5]"
|
2015-12-03 23:46:52 +00:00
|
|
|
ret = ret .. "vertlabel[0,0;" .. title .. "]"
|
2015-12-03 23:57:28 +00:00
|
|
|
ret = ret .. "tablecolumns[color;text;text;text;text;text;text;text;text]"
|
2015-12-03 23:46:52 +00:00
|
|
|
ret = ret .. "tableoptions[highlight=#00000000]"
|
2015-12-04 11:21:25 +00:00
|
|
|
ret = ret .. "table[0.5,0;11.25,6;scores;"
|
2015-12-03 23:57:28 +00:00
|
|
|
ret = ret .. "#ffffff,,username,kills,deaths,K/D ratio,captures,attempts,score"
|
2015-12-03 23:46:52 +00:00
|
|
|
|
2015-12-04 11:16:33 +00:00
|
|
|
for i = 1, #players do
|
2015-12-04 11:14:22 +00:00
|
|
|
local pstat = players[i]
|
2015-12-03 23:46:52 +00:00
|
|
|
local color = pstat.color or "#ffffff"
|
|
|
|
ret = ret ..
|
|
|
|
"," .. string.gsub(color, "0x", "#") ..
|
2015-12-03 23:57:28 +00:00
|
|
|
"," .. i ..
|
2015-12-03 23:46:52 +00:00
|
|
|
"," .. pstat.name ..
|
|
|
|
"," .. pstat.kills ..
|
|
|
|
"," .. pstat.deaths ..
|
|
|
|
"," .. math.floor(pstat.kills / (pstat.deaths + 1)*10)/10 ..
|
|
|
|
"," .. pstat.captures ..
|
|
|
|
"," .. pstat.attempts ..
|
2015-12-05 19:12:34 +00:00
|
|
|
"," .. math.floor(pstat.score*10)/10
|
2015-12-03 23:57:28 +00:00
|
|
|
if i > 40 then
|
|
|
|
break
|
|
|
|
end
|
2015-12-03 23:46:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ret = ret .. ";-1]"
|
|
|
|
ret = ret .. "button_exit[0.5,6;3,1;close;Close]"
|
|
|
|
return ret
|
|
|
|
end
|
2015-12-03 23:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
minetest.register_chatcommand("rankings", {
|
|
|
|
func = function(name)
|
|
|
|
local players = {}
|
|
|
|
for name, pstat in pairs(ctf_stats.players) do
|
|
|
|
pstat.name = name
|
|
|
|
pstat.color = nil
|
|
|
|
table.insert(players, pstat)
|
|
|
|
end
|
|
|
|
local fs = ctf_stats.get_formspec("Player Rankings", players)
|
2015-12-04 00:16:16 +00:00
|
|
|
minetest.show_formspec(name, "ctf_stats:rankings", fs)
|
2015-12-03 23:57:28 +00:00
|
|
|
end
|
|
|
|
})
|