From a90ae15fd5be62b1e8b26b4675d1fcae9d22befd Mon Sep 17 00:00:00 2001 From: Mr Techtroid <64828294+mrtechtroid@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:02:55 +0530 Subject: [PATCH 1/2] Added command /top. --- mods/ctf/ctf_modebase/ranking_commands.lua | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mods/ctf/ctf_modebase/ranking_commands.lua b/mods/ctf/ctf_modebase/ranking_commands.lua index 29116c5f4a..6094de2305 100644 --- a/mods/ctf/ctf_modebase/ranking_commands.lua +++ b/mods/ctf/ctf_modebase/ranking_commands.lua @@ -259,6 +259,42 @@ minetest.register_chatcommand("top50", { }) end, }) +minetest.register_chatcommand("top", { + description = "Show the top players(value less than 200)", + params = "[mode:technical modename] ", + func = function(name, param) + local mode_name, mode_data, top_amt = get_gamemode(param) + if not mode_name or not mode_data then + return false, mode_data + end + if not top_amt or tonumber(top_amt)>200 then + return false + end + top_amt = tonumber(top_amt) + local topPlayers = {} + + for i, pname in ipairs(mode_data.rankings.top:get_top(top_amt)) do + local t = table.copy(mode_data.rankings:get(pname) or {}) + t.pname = pname + table.insert(topPlayers, t) + end + + local own_pos = mode_data.rankings.top:get_place(name) + if own_pos > top_amt then + local t = table.copy(mode_data.rankings:get(name) or {}) + t.pname = name + t.number = own_pos + table.insert(topPlayers, t) + end + + mode_data.summary_ranks._sort = "score" + ctf_modebase.summary.show_gui_sorted(name, topPlayers, {}, mode_data.summary_ranks, { + title = "Top "..top_amt.." Players", + gamemode = mode_name, + disable_nonuser_colors = true, + }) + end, +}) minetest.register_chatcommand("make_pro", { description = "Make yourself or another player a pro (Will break target player's ranks)", From f1114e0b220f7cacf6a4207ced4b1a444c8dc57a Mon Sep 17 00:00:00 2001 From: Mr Techtroid <64828294+mrtechtroid@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:10:16 +0530 Subject: [PATCH 2/2] Fix bug - Negative or zero no of players --- mods/ctf/ctf_modebase/ranking_commands.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ctf/ctf_modebase/ranking_commands.lua b/mods/ctf/ctf_modebase/ranking_commands.lua index 6094de2305..7b9b02fd2e 100644 --- a/mods/ctf/ctf_modebase/ranking_commands.lua +++ b/mods/ctf/ctf_modebase/ranking_commands.lua @@ -260,14 +260,14 @@ minetest.register_chatcommand("top50", { end, }) minetest.register_chatcommand("top", { - description = "Show the top players(value less than 200)", + description = "Show the top players [1-200]", params = "[mode:technical modename] ", func = function(name, param) local mode_name, mode_data, top_amt = get_gamemode(param) if not mode_name or not mode_data then return false, mode_data end - if not top_amt or tonumber(top_amt)>200 then + if not top_amt or tonumber(top_amt)>200 or tonumber(top_amt)<1 then return false end top_amt = tonumber(top_amt)