From de63c4b2be5d7da80d2bfcdfca7ef43e317c584e Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 20:52:42 +0200 Subject: [PATCH 1/8] Mmove local cv_teamchange to the top scope No need to constantly look up the cvar when it can be saved --- leaderboard.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 8fdc31d..ed90b2f 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -12,6 +12,7 @@ local splits = {} local PATCH = nil local help = true local EncoreInitial = nil +local cv_teamchange -- Tracks if stats have been written or not local StatTrack = false @@ -1239,7 +1240,10 @@ local function think() end end - local cv_teamchange = CV_FindVar("allowteamchange") + if not cv_teamchange then + cv_teamchange = CV_FindVar("allowteamchange") + end + if p then -- Scroll controller -- Spectators can't input buttons so let the gamer do it @@ -1290,7 +1294,12 @@ local function interThink() COM_BufInsertText(server, "map " + nextMap) nextMap = nil end - if not CV_FindVar("allowteamchange").value then + + if not cv_teamchange then + cv_teamchange = CV_FindVar("allowteamchange") + end + + if not cv_teamchange.value then allowJoin(true) end end From 41b152ccf627066a1b01b5dd7744b06805650f9b Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 20:55:38 +0200 Subject: [PATCH 2/8] add VoteThinker hook --- leaderboard.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/leaderboard.lua b/leaderboard.lua index ed90b2f..a332efe 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1304,6 +1304,7 @@ local function interThink() end end addHook("IntermissionThinker", interThink) +addHook("VoteThinker", interThink) -- Returns the values clamed between min, max function clamp(min_v, v, max_v) From e3c870eefd52dfd99452795f5537dcf5ab3cae0b Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 21:00:55 +0200 Subject: [PATCH 3/8] Prevent overflow of minutes --- leaderboard.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leaderboard.lua b/leaderboard.lua index a332efe..4ee32d7 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -661,7 +661,7 @@ function ticsToTime(tics, pure) return string.format( "%d:%02d:%02d", - G_TicsToMinutes(tics), + G_TicsToMinutes(tics, true), G_TicsToSeconds(tics), G_TicsToCentiseconds(tics) ) From 5790a3c020a5fe5082573b211f1ba5b1ca0852fc Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 21:30:34 +0200 Subject: [PATCH 4/8] Dont iterate players if afk is disabled --- leaderboard.lua | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 4ee32d7..7239446 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1146,28 +1146,30 @@ local function think() end if disable then - if cv_afk.value and ingame() > 1 then - for p in players.iterate do - if p.valid and not p.spectator and not p.exiting and p.lives > 0 then - if p.cmd.buttons then - p.afkTime = leveltime - end + if cv_afk.value then + if ingame() > 1 then + for p in players.iterate do + if p.valid and not p.spectator and not p.exiting and p.lives > 0 then + if p.cmd.buttons then + p.afkTime = leveltime + end - --Away from kart - if p.afkTime + AFK_BALANCE_WARN == leveltime then - chatprintf(p, "[AFK] \x89You will be moved to spectator in 10 seconds!", false) - S_StartSound(nil, 26, p) - end - if p.afkTime + AFK_BALANCE < leveltime then - p.spectator = true - chatprint("\x89" + p.name + " was moved to the other team for game balance", true) + --Away from kart + if p.afkTime + AFK_BALANCE_WARN == leveltime then + chatprintf(p, "[AFK] \x89You will be moved to spectator in 10 seconds!", false) + S_StartSound(nil, 26, p) + end + if p.afkTime + AFK_BALANCE < leveltime then + p.spectator = true + chatprint("\x89" + p.name + " was moved to the other team for game balance", true) + end end end - end - else - for p in players.iterate do - if p.valid and not p.spectator then - p.afkTime = leveltime + else + for p in players.iterate do + if p.valid and not p.spectator then + p.afkTime = leveltime + end end end end From 5080672f7afaa44f4930aadbf6cba276c7ce0266 Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 22:49:28 +0200 Subject: [PATCH 5/8] Update 'leaderboard.lua' --- leaderboard.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 7239446..de4e104 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -908,9 +908,9 @@ local function drawScroll(v, player, scoreTable, gui) local x = 10 if #scoreTable >= 10 then x = x + 8 - end - if #scoreTable >= 100 then - x = x + 8 + if #scoreTable >= 100 then + x = x + 8 + end end local y = FixedInt(scrollY) From 14f8769d9371ca953bf4d112abf1af00ccb15e6b Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 22:56:19 +0200 Subject: [PATCH 6/8] dont do an iteration when the player is already known --- leaderboard.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index de4e104..4a9321e 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1220,22 +1220,22 @@ local function think() end if clearcheats then clearcheats = false - for p in players.iterate do - p.SPBAKARTBIG = false - p.SPBAjustice = false - p.SPBAshutup = false + for q in players.iterate do + q.SPBAKARTBIG = false + q.SPBAjustice = false + q.SPBAshutup = false end end - for p in players.iterate do - if not p.spectator then - if p.SPBAKARTBIG then - Flags = $ | F_SPBBIG - end - if p.SPBAjustice then - Flags = $ | F_SPBJUS - end + + if p then + if p.SPBAKARTBIG then + Flags = $ | F_SPBBIG + end + if p.SPBAjustice then + Flags = $ | F_SPBJUS end end + end if not (Flags & F_SPBATK) then hud.enable("freeplay") From 23a8373230f3fb8d543dd5f1ae0af99294eeff08 Mon Sep 17 00:00:00 2001 From: Lonsfor Date: Sat, 30 Apr 2022 23:11:52 +0200 Subject: [PATCH 7/8] only look for scoreTable once --- leaderboard.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 4a9321e..8a66357 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -13,6 +13,7 @@ local PATCH = nil local help = true local EncoreInitial = nil local cv_teamchange +local scoreTable -- Tracks if stats have been written or not local StatTrack = false @@ -240,7 +241,7 @@ if f then flags = tonumber(t[7]) end - local scoreTable = getScoreTable(tonumber(t[1]), flags) or {} + scoreTable = getScoreTable(tonumber(t[1]), flags) or {} local spl = {} if t[6] != nil then @@ -961,8 +962,6 @@ local function drawScoreboard(v, player) if player != displayplayers[0] then return end cachePatches(v) - - local scoreTable = getScoreTable(gamemap, Flags) local gui = cv_gui.value if leveltime < START_TIME or player.exiting or player.lives == 0 then @@ -1010,7 +1009,7 @@ end -- Find location of player and scroll to it function scroll_to(player) - local m = getScoreTable(gamemap, Flags) or {} + local m = scoreTable or {} scrollToPos = 2 for pos, score in ipairs(m) do @@ -1039,7 +1038,8 @@ local function writeStats() end local function saveTime(player) - local scoreTable = getScoreTable(gamemap, Flags) or {} + + scoreTable = $ or {} local pskin = skins[player.mo.skin] local newscore = score_t( @@ -1242,6 +1242,8 @@ local function think() end end + scoreTable = getScoreTable(gamemap, Flags) + if not cv_teamchange then cv_teamchange = CV_FindVar("allowteamchange") end From 6c7cdf34b96e9dea037eb38da86f7e6c3294d130 Mon Sep 17 00:00:00 2001 From: Not Date: Thu, 12 May 2022 12:14:48 +0200 Subject: [PATCH 8/8] set players afkTime before enabling antiAFK --- leaderboard.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 8a66357..f03fa55 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -83,11 +83,24 @@ local cv_gui = CV_RegisterVar({ PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON} }) -local cv_afk = CV_RegisterVar({ +local AntiAFK = true +CV_RegisterVar({ name = "lb_afk", defaultvalue = 1, - flags = CV_NETVAR, - PossibleValue = CV_OnOff + flags = CV_NETVAR | CV_CALL, + PossibleValue = CV_OnOff, + func = function(v) + -- Set players afkTime and toggle AntiAFK + if v.value then + for p in players.iterate do + p.afkTime = leveltime + end + + AntiAFK = true + else + AntiAFK = false + end + end }) local cv_enable = CV_RegisterVar({ @@ -1146,7 +1159,7 @@ local function think() end if disable then - if cv_afk.value then + if AntiAFK then if ingame() > 1 then for p in players.iterate do if p.valid and not p.spectator and not p.exiting and p.lives > 0 then