From ca8cde8a0a0b3323ce9dee026162c3a27acb1a5d Mon Sep 17 00:00:00 2001 From: philipmi Date: Sat, 13 Feb 2021 20:53:29 +0100 Subject: [PATCH] Add "Capture Rate" statistic --- mods/ctf/ctf_stats/chat.lua | 8 +++++++- mods/ctf/ctf_stats/gui.lua | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mods/ctf/ctf_stats/chat.lua b/mods/ctf/ctf_stats/chat.lua index a3f3aa5..4ce5f00 100644 --- a/mods/ctf/ctf_stats/chat.lua +++ b/mods/ctf/ctf_stats/chat.lua @@ -40,6 +40,10 @@ local function return_as_chat_result(to, target) if stat.deaths > 1 then kd = kd / stat.deaths end + local ca = stat.captures + if stat.attempts > 1 then + ca = ca / stat.attempts + end result = result .. minetest.colorize("#63d437", "Kills: ") .. minetest.colorize("#ffea00", stat.kills .. @@ -49,10 +53,12 @@ local function return_as_chat_result(to, target) minetest.colorize("#ffea00", math.floor(kd * 10) / 10 .. minetest.colorize("#63d437", "\nBounty kills: ")) .. minetest.colorize("#ffea00", stat.bounty_kills .. - minetest.colorize("#63d437", " | Captures: ") .. + minetest.colorize("#63d437", "\nCaptures: ") .. minetest.colorize("#ffea00", stat.captures .. minetest.colorize("#63d437", " | Attempts: ")) .. minetest.colorize("#ffea00", stat.attempts .. + minetest.colorize("#63d437", " | Capture Rate: ")) .. + minetest.colorize("#ffea00", math.floor(ca * 100) .. "%" .. minetest.colorize("#63d437", "\nScore: ")) .. minetest.colorize("#ffea00", math.floor(stat.score))) end diff --git a/mods/ctf/ctf_stats/gui.lua b/mods/ctf/ctf_stats/gui.lua index 48f0550..e3a628d 100644 --- a/mods/ctf/ctf_stats/gui.lua +++ b/mods/ctf/ctf_stats/gui.lua @@ -5,13 +5,14 @@ ctf_stats.rankings_display_count = 50 local tablecolumns = { "tablecolumns[color;", "text;", - "text,width=16;", + "text,width=10;", "text,width=4;", "text,width=4;", "text,width=4;", "text,width=6;", "text,width=6;", "text,width=6;", + "text,width=6;", "text,width=6]" } tablecolumns = table.concat(tablecolumns, "") @@ -125,7 +126,7 @@ function ctf_stats.get_formspec(title, players, header, target) ret = ret .. tablecolumns ret = ret .. "tableoptions[highlight=#00000000]" ret = ret .. "table[0.5,0;13.25,6.1;scores;" - ret = ret .. "#ffffff,,Player,Kills,Deaths,K/D,Bounty Kills,Captures,Attempts,Score" + ret = ret .. "#ffffff,,Player,Kills,Deaths,K/D,Bounty Kills,Captures,Attempts,Capture Rate,Score" local hstat, hplace if type(target) == "number" then @@ -153,6 +154,10 @@ function ctf_stats.get_formspec(title, players, header, target) if pstat.deaths > 1 then kd = kd / pstat.deaths end + local ca = pstat.captures + if pstat.attempts > 1 then + ca = ca / pstat.attempts + end ret = ret .. "," .. string.gsub(color, "0x", "#") .. "," .. i .. @@ -163,6 +168,7 @@ function ctf_stats.get_formspec(title, players, header, target) "," .. pstat.bounty_kills .. "," .. pstat.captures .. "," .. pstat.attempts .. + "," .. math.floor(ca * 100) .. "%" .. "," .. math.floor(pstat.score * 10) / 10 end ret = ret .. ";-1]" @@ -175,6 +181,10 @@ function ctf_stats.get_formspec(title, players, header, target) if hstat.deaths > 1 then h_kd = h_kd / hstat.deaths end + local h_ca = hstat.captures + if hstat.attempts > 1 then + h_ca = h_ca / hstat.attempts + end ret = ret .. tablecolumns ret = ret .. "tableoptions[highlight=#00000000]" @@ -188,6 +198,7 @@ function ctf_stats.get_formspec(title, players, header, target) "," .. hstat.bounty_kills .. "," .. hstat.captures .. "," .. hstat.attempts .. + "," .. math.floor(h_ca * 100) .. "%" .. "," .. math.floor(hstat.score * 10) / 10 .. ";-1]" --[[ else ret = ret .. "box[0.5,6.1;13.25,0.4;#101010]" @@ -213,6 +224,7 @@ function ctf_stats.get_html(title) "Bounty kills" .. "Captures" .. "Attempts" .. + "Capture Rate" .. "Score" for i = 1, math.min(#players, 50) do @@ -221,6 +233,10 @@ function ctf_stats.get_html(title) if pstat.deaths > 1 then kd = kd / pstat.deaths end + local ca = pstat.captures + if pstat.attempts > 1 then + ca = ca / pstat.attempts + end ret = ret .. "" .. i .. "" .. pstat.name .. @@ -230,6 +246,7 @@ function ctf_stats.get_html(title) "" .. pstat.bounty_kills .. "" .. pstat.captures .. "" .. pstat.attempts .. + "" .. math.floor(ca * 100) .. "%" .. "" .. math.floor(pstat.score*10)/10 .. "" end