From ac4e98e0767623dd71be71bd6c649053f22f5f26 Mon Sep 17 00:00:00 2001 From: Axaxax88 <74550391+Axaxax88@users.noreply.github.com> Date: Mon, 16 Nov 2020 16:51:53 +0100 Subject: [PATCH] Add Team K/D to summary These changes will add "Team K/D" to summary counted from red and blue kills and deaths. Update gui.lua Update gui.lua --- mods/ctf/ctf_stats/gui.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mods/ctf/ctf_stats/gui.lua b/mods/ctf/ctf_stats/gui.lua index 83b2085..9a65f45 100644 --- a/mods/ctf/ctf_stats/gui.lua +++ b/mods/ctf/ctf_stats/gui.lua @@ -32,12 +32,14 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, local red = { color = ctf.flag_colors.red:gsub("0x", "#"), kills = 0, + deaths = 0, attempts = 0, score = 0, } local blue = { color = ctf.flag_colors.blue:gsub("0x", "#"), kills = 0, + deaths = 0, attempts = 0, score = 0, } @@ -46,6 +48,7 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, pstat.color = ctf.flag_colors.red table.insert(players, pstat) red.kills = red.kills + pstat.kills + red.deaths = red.deaths + pstat.deaths red.attempts = red.attempts + pstat.attempts red.score = red.score + pstat.score end @@ -54,6 +57,7 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, pstat.color = ctf.flag_colors.blue table.insert(players, pstat) blue.kills = blue.kills + pstat.kills + blue.deaths = blue.deaths + pstat.deaths blue.attempts = blue.attempts + pstat.attempts blue.score = blue.score + pstat.score end @@ -65,6 +69,14 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, math.floor((time % 3600) / 60), -- minutes math.floor(time % 60)) -- seconds end + local red_kd = math.floor(red.kills / red.deaths * 10) / 10 + if red.deaths <1 then + red_kd = red.kills + end + local blue_kd = math.floor(blue.kills / blue.deaths * 10) / 10 + if blue.deaths <1 then + blue_kd = blue.kills + end local ret = ctf_stats.get_formspec("Match Summary", players, 1) @@ -83,10 +95,13 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player, -- Map name ret = ret .. "label[1,7.6;Map: " .. minetest.colorize("#EEEE00", stats.map) .. "]" - ret = ret .. "label[6,0;Kills]" - ret = ret .. "label[7.5,0;" .. render_team_stats(red, blue, "kills") .. "]" - ret = ret .. "label[6,0.5;Attempts]" - ret = ret .. "label[7.5,0.5;" .. render_team_stats(red, blue, "attempts") .. "]" + ret = ret .. "label[6.5,0;Kills]" + ret = ret .. "label[8,0;" .. render_team_stats(red, blue, "kills") .. "]" + ret = ret .. "label[3.5,0;Team K/D]" + ret = ret .. "label[5,0;" .. minetest.colorize(red.color, tostring(red_kd)) + .. " - " .. " " .. minetest.colorize(blue.color, tostring(blue_kd)) .. "]" + ret = ret .. "label[6.5,0.5;Attempts]" + ret = ret .. "label[8,0.5;" .. render_team_stats(red, blue, "attempts") .. "]" ret = ret .. "label[9.5,0;Duration]" ret = ret .. "label[11,0;" .. match_length .. "]" ret = ret .. "label[9.5,0.5;Total score]"