Skip to content

Commit

Permalink
Ranking reset/league fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Aug 16, 2023
1 parent 55b8e9e commit 25cd0bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
24 changes: 12 additions & 12 deletions mods/ctf/ctf_rankings/leagues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ minetest.register_on_joinplayer(function(player)
end
end

-- This code needs to be commented out post-reset,
-- and changed to only run when there are a certain amount of players in the rankings. Maybe up to wood league?
-- This commented code needs to be changed to only run when there are a certain amount of players in the rankings
-- Maybe up to wood league?

for mode, def in pairs(ctf_modebase.modes) do
local place = def.rankings.top:get_place(player:get_player_name())
-- for mode, def in pairs(ctf_modebase.modes) do
-- local place = def.rankings.top:get_place(player:get_player_name())

for _, league in ipairs(ctf_rankings.leagues_list) do
if place <= ctf_rankings.leagues[league] then
leagues[mode] = league
break
end
end
end
-- for _, league in ipairs(ctf_rankings.leagues_list) do
-- if place <= ctf_rankings.leagues[league] then
-- leagues[mode] = league
-- break
-- end
-- end
-- end

cache[player:get_player_name()] = leagues
-- cache[player:get_player_name()] = leagues

if ctf_modebase.current_mode then
update_league(player)
Expand Down
37 changes: 16 additions & 21 deletions mods/ctf/ctf_rankings/ranking_reset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ ctf_rankings.do_reset = mods:get_int("_do_reset") == 1
local PLAYER_RANKING_PREFIX = "rank:"

if ctf_rankings.do_reset then
minetest.after(5, function()
local after_timer = 0
local after_timer = 0

minetest.after(5, function()
for mode, def in pairs(ctf_modebase.modes) do
local top = def.rankings.top
local time = minetest.get_us_time()
Expand Down Expand Up @@ -71,29 +71,24 @@ if ctf_rankings.do_reset then
minetest.log("action", "Saved old rankings for mode "..mode..". Took "..time)
end

-- Give the world a little time to catch up after that potentially long code loop, then continue
minetest.after(5 + after_timer, function()
after_timer = 0

for mode, def in pairs(ctf_modebase.modes) do
local time = minetest.get_us_time()
def.rankings.op_all(function(pname, value)
def.rankings:del(pname)
for mode, def in pairs(ctf_modebase.modes) do
local time = minetest.get_us_time()
def.rankings.op_all(function(pname, value)
def.rankings:del(pname)

minetest.chat_send_all(string.format("[%s] Reset rankings of player %s", mode, pname))
end)
minetest.chat_send_all(string.format("[%s] Reset rankings of player %s", mode, pname))
end)

after_timer = after_timer + ((minetest.get_us_time()-time) / 1e6)
time = ((minetest.get_us_time()-time) / 1e6).."s"
after_timer = after_timer + ((minetest.get_us_time()-time) / 1e6)
time = ((minetest.get_us_time()-time) / 1e6).."s"

minetest.chat_send_all("Reset rankings for mode "..mode..". Took "..time)
minetest.log("action", "Reset rankings for mode "..mode..". Took "..time)
end
minetest.chat_send_all("Reset rankings for mode "..mode..". Took "..time)
minetest.log("action", "Reset rankings for mode "..mode..". Took "..time)
end

mods:set_int("_do_reset", 0)
mods:set_int("_current_reset", mods:get_int("_current_reset") + 1)
minetest.request_shutdown("Ranking reset done. Thank you for your patience", true, 10 + after_timer)
end)
mods:set_int("_do_reset", 0)
mods:set_int("_current_reset", mods:get_int("_current_reset") + 1)
minetest.request_shutdown("Ranking reset done. Thank you for your patience", true, after_timer + 5)
end)
end

Expand Down

0 comments on commit 25cd0bf

Please sign in to comment.