Add league tables
This commit is contained in:
parent
220d5e2a3c
commit
f952112be0
2 changed files with 39 additions and 9 deletions
|
@ -10,14 +10,17 @@ function ctf_stats.get_formspec_match_summary(stats)
|
||||||
pstat.color = ctf.flag_colors.blue
|
pstat.color = ctf.flag_colors.blue
|
||||||
table.insert(players, pstat)
|
table.insert(players, pstat)
|
||||||
end
|
end
|
||||||
local ret = ctf_stats.get_formspec("Match Summary", players, stats)
|
local ret = ctf_stats.get_formspec("Match Summary", players)
|
||||||
ret = ret .. "label[3.5,6.2;Tip: type /rankings for league tables]"
|
ret = ret .. "label[3.5,6.2;Tip: type /rankings for league tables]"
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf_stats.get_formspec(title, players, stats)
|
function ctf_stats.get_formspec(title, players)
|
||||||
for _, pstat in pairs(players) do
|
for i, pstat in pairs(players) do
|
||||||
pstat.score = pstat.captures + 0.2 * pstat.attempts + 7 * pstat.kills / (pstat.deaths + 1)
|
pstat.score = pstat.captures + 0.2 * pstat.attempts + 7 * pstat.kills / (pstat.deaths + 1)
|
||||||
|
if i > 40 then
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.sort(players, function(one, two)
|
table.sort(players, function(one, two)
|
||||||
return (one.score > two.score)
|
return (one.score > two.score)
|
||||||
|
@ -25,15 +28,16 @@ function ctf_stats.get_formspec(title, players, stats)
|
||||||
|
|
||||||
local ret = "size[9,6.5]"
|
local ret = "size[9,6.5]"
|
||||||
ret = ret .. "vertlabel[0,0;" .. title .. "]"
|
ret = ret .. "vertlabel[0,0;" .. title .. "]"
|
||||||
ret = ret .. "tablecolumns[color;text;text;text;text;text;text;text]"
|
ret = ret .. "tablecolumns[color;text;text;text;text;text;text;text;text]"
|
||||||
ret = ret .. "tableoptions[highlight=#00000000]"
|
ret = ret .. "tableoptions[highlight=#00000000]"
|
||||||
ret = ret .. "table[0.5,0;8.25,6;scores;"
|
ret = ret .. "table[0.5,0;8.25,6;scores;"
|
||||||
ret = ret .. "#ffffff,username,kills,deaths,K/D ratio,wins,attempts,score"
|
ret = ret .. "#ffffff,,username,kills,deaths,K/D ratio,captures,attempts,score"
|
||||||
|
|
||||||
for i, pstat in pairs(players) do
|
for i, pstat in pairs(players) do
|
||||||
local color = pstat.color or "#ffffff"
|
local color = pstat.color or "#ffffff"
|
||||||
ret = ret ..
|
ret = ret ..
|
||||||
"," .. string.gsub(color, "0x", "#") ..
|
"," .. string.gsub(color, "0x", "#") ..
|
||||||
|
"," .. i ..
|
||||||
"," .. pstat.name ..
|
"," .. pstat.name ..
|
||||||
"," .. pstat.kills ..
|
"," .. pstat.kills ..
|
||||||
"," .. pstat.deaths ..
|
"," .. pstat.deaths ..
|
||||||
|
@ -41,9 +45,26 @@ function ctf_stats.get_formspec(title, players, stats)
|
||||||
"," .. pstat.captures ..
|
"," .. pstat.captures ..
|
||||||
"," .. pstat.attempts ..
|
"," .. pstat.attempts ..
|
||||||
"," .. pstat.score
|
"," .. pstat.score
|
||||||
|
if i > 40 then
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ret = ret .. ";-1]"
|
ret = ret .. ";-1]"
|
||||||
ret = ret .. "button_exit[0.5,6;3,1;close;Close]"
|
ret = ret .. "button_exit[0.5,6;3,1;close;Close]"
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
minetest.show_formspec(name, "a", fs)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
|
@ -47,10 +47,12 @@ function ctf_stats.player(name)
|
||||||
local player = ctf_stats.players[name]
|
local player = ctf_stats.players[name]
|
||||||
if not player then
|
if not player then
|
||||||
player = {
|
player = {
|
||||||
|
name = name,
|
||||||
red_wins = 0,
|
red_wins = 0,
|
||||||
blue_wins = 0,
|
blue_wins = 0,
|
||||||
kills = 0,
|
kills = 0,
|
||||||
deaths = 0,
|
deaths = 0,
|
||||||
|
captures = 0,
|
||||||
attempts = 0
|
attempts = 0
|
||||||
}
|
}
|
||||||
ctf_stats.players[name] = player
|
ctf_stats.players[name] = player
|
||||||
|
@ -72,18 +74,21 @@ ctf.register_on_join_team(function(name, tname)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ctf_match.register_on_skip_map(function()
|
ctf_match.register_on_skip_map(function()
|
||||||
|
ctf.needs_save = true
|
||||||
ctf_stats.matches.skipped = ctf_stats.matches.skipped + 1
|
ctf_stats.matches.skipped = ctf_stats.matches.skipped + 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ctf_flag.register_on_capture(function(name, flag)
|
ctf_flag.register_on_capture(function(name, flag)
|
||||||
local tname = ctf.player(name).team
|
local main, match = ctf_stats.player(name)
|
||||||
if ctf_stats.current[tname] and ctf_stats.current[tname][name] then
|
if main and match then
|
||||||
ctf_stats.current[tname][name].captures =
|
main.captures = main.captures + 1
|
||||||
ctf_stats.current[tname][name].captures + 1
|
match.captures = match.captures + 1
|
||||||
|
ctf.needs_save = true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ctf_match.register_on_winner(function(winner)
|
ctf_match.register_on_winner(function(winner)
|
||||||
|
ctf.needs_save = true
|
||||||
ctf_stats.matches[winner .. "_wins"] = ctf_stats.matches[winner .. "_wins"] + 1
|
ctf_stats.matches[winner .. "_wins"] = ctf_stats.matches[winner .. "_wins"] + 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -98,6 +103,7 @@ ctf_match.register_on_new_match(function()
|
||||||
red = {},
|
red = {},
|
||||||
blue = {}
|
blue = {}
|
||||||
}
|
}
|
||||||
|
ctf.needs_save = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ctf_flag.register_on_pick_up(function(name, flag)
|
ctf_flag.register_on_pick_up(function(name, flag)
|
||||||
|
@ -105,6 +111,7 @@ ctf_flag.register_on_pick_up(function(name, flag)
|
||||||
if main and match then
|
if main and match then
|
||||||
main.attempts = main.attempts + 1
|
main.attempts = main.attempts + 1
|
||||||
match.attempts = match.attempts + 1
|
match.attempts = match.attempts + 1
|
||||||
|
ctf.needs_save = true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -113,6 +120,7 @@ ctf_flag.register_on_precapture(function(name, flag)
|
||||||
local main, match = ctf_stats.player(name)
|
local main, match = ctf_stats.player(name)
|
||||||
if main then
|
if main then
|
||||||
main[tplayer.team .. "_wins"] = main[tplayer.team .. "_wins"] + 1
|
main[tplayer.team .. "_wins"] = main[tplayer.team .. "_wins"] + 1
|
||||||
|
ctf.needs_save = true
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
@ -122,6 +130,7 @@ minetest.register_on_dieplayer(function(player)
|
||||||
if main and match then
|
if main and match then
|
||||||
main.deaths = main.deaths + 1
|
main.deaths = main.deaths + 1
|
||||||
match.deaths = match.deaths + 1
|
match.deaths = match.deaths + 1
|
||||||
|
ctf.needs_save = true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue