diff --git a/mods/ctf_stats/gui.lua b/mods/ctf_stats/gui.lua index 58611d9..f7ec1c3 100644 --- a/mods/ctf_stats/gui.lua +++ b/mods/ctf_stats/gui.lua @@ -76,14 +76,14 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, return ret end -function ctf_stats.get_formspec(title, players, header) +function ctf_stats.get_formspec(title, players, header, hlt_name) table.sort(players, function(one, two) return one.score > two.score end) - local ret = "size[12,"..6.5+header.."]" + local ret = "size[12," .. 6.5 + header .. "]" ret = ret .. default.gui_bg .. default.gui_bg_img - ret = ret .. "container[0,"..header.."]" + ret = ret .. "container[0," .. header .. "]" ret = ret .. "vertlabel[0,0;" .. title .. "]" ret = ret .. "tablecolumns[color;text;text;text;text;text;text;text;text;text]" @@ -91,27 +91,60 @@ function ctf_stats.get_formspec(title, players, header) ret = ret .. "table[0.5,0;11.25,6;scores;" ret = ret .. "#ffffff,,Player,Kills,Deaths,K/D ratio,Bounty kills,Captures,Attempts,Score" - for i = 1, #players do + local player_in_top_50 = false + + for i = 1, math.min(#players, 50) do local pstat = players[i] - local color = pstat.color or "#ffffff" + local color + if hlt_name and pstat.name == hlt_name then + color = "#ffff00" + player_in_top_50 = true + else + color = pstat.color or "#ffffff" + end local kd = pstat.kills - if pstat.deaths > 0 then + if pstat.deaths > 1 then kd = kd / pstat.deaths end ret = ret .. - "," .. string.gsub(color, "0x", "#") .. - "," .. i .. - "," .. pstat.name .. - "," .. pstat.kills .. - "," .. pstat.deaths .. - "," .. math.floor(kd*10)/10 .. - "," .. pstat.bounty_kills .. - "," .. pstat.captures .. - "," .. pstat.attempts .. - "," .. math.floor(pstat.score*10)/10 - if i > 49 then - break + "," .. string.gsub(color, "0x", "#") .. + "," .. i .. + "," .. pstat.name .. + "," .. pstat.kills .. + "," .. pstat.deaths .. + "," .. math.floor(kd * 10) / 10 .. + "," .. pstat.bounty_kills .. + "," .. pstat.captures .. + "," .. pstat.attempts .. + "," .. math.floor(pstat.score * 10) / 10 + end + + if hlt_name and not player_in_top_50 then + local hlt_player, hlt_rank, hlt_kd + + for i = 1, #players do + if players[i].name == hlt_name then + hlt_player = players[i] + hlt_rank = i + break + end end + + hlt_kd = hlt_player.kills + if hlt_player.deaths > 1 then + hlt_kd = hlt_kd / hlt_player.deaths + end + ret = ret .. + "," .. "#ffff00" .. + "," .. hlt_rank .. + "," .. hlt_player.name .. + "," .. hlt_player.kills .. + "," .. hlt_player.deaths .. + "," .. math.floor(hlt_kd * 10) / 10 .. + "," .. hlt_player.bounty_kills .. + "," .. hlt_player.captures .. + "," .. hlt_player.attempts .. + "," .. math.floor(hlt_player.score * 10) / 10 end ret = ret .. ";-1]" @@ -128,18 +161,19 @@ function ctf_stats.get_html(title, players) local ret = "
" .. - " | username | " .. - "kills | " .. - "deaths | " .. + "Player | " .. + "Kills | " .. + "Deaths | " .. "K/D ratio | " .. - "captures | " .. - "attempts | " .. - "score | Bounty kills | " .. + "Captures | " .. + "Attempts | " .. + "Score | " - for i = 1, #players do + for i = 1, math.min(#players, 50) do local pstat = players[i] local kd = pstat.kills - if pstat.deaths > 0 then + if pstat.deaths > 1 then kd = kd / pstat.deaths end ret = ret .. @@ -147,13 +181,11 @@ function ctf_stats.get_html(title, players) "" .. pstat.name .. " | " .. pstat.kills .. " | " .. pstat.deaths .. - " | " .. math.floor(kd*10)/10 .. + " | " .. math.floor(kd * 10) / 10 .. + " | " .. pstat.bounty_kills .. " | " .. pstat.captures .. " | " .. pstat.attempts .. " | " .. math.floor(pstat.score*10)/10 .. " | " - if i > 49 then - break - end end ret = ret .. "
---|