Compare commits

..

16 Commits

Author SHA1 Message Date
e25b417fbd fix function name 2022-05-15 22:31:51 +02:00
3d54350dae Use strings as the default cvar value 2022-05-14 08:12:58 +02:00
89da89fbfe Simplify allowJoin() 2022-05-14 08:04:28 +02:00
906444ae08 change ingame() to only check if there is 2 players in game
as ingame() is only used to check if there is more than 1 player then it is changed to not look for more than 2 since its not needed. name changed to reflect that.
2022-05-14 08:02:05 +02:00
405a0e50f2 save player iteration on thinker
we know that there are no more than one player as `disable` is false and you know there is 1 if `p` exist
2022-05-14 07:41:40 +02:00
6ea3341b06 better init logic + make sure we are not in battle 2022-05-14 07:33:03 +02:00
Not
14645dbc90 Merge branch 'lonsfor-patch-1' 2022-05-12 12:17:36 +02:00
Not
6c7cdf34b9 set players afkTime before enabling antiAFK 2022-05-12 12:14:48 +02:00
23a8373230 only look for scoreTable once 2022-04-30 23:11:52 +02:00
14f8769d93 dont do an iteration when the player is already known 2022-04-30 22:56:19 +02:00
5080672f7a Update 'leaderboard.lua' 2022-04-30 22:49:28 +02:00
5790a3c020 Dont iterate players if afk is disabled 2022-04-30 21:30:34 +02:00
e3c870eefd Prevent overflow of minutes 2022-04-30 21:00:55 +02:00
41b152ccf6 add VoteThinker hook 2022-04-30 20:55:38 +02:00
de63c4b2be Mmove local cv_teamchange to the top scope
No need to constantly look up the cvar when it can be saved
2022-04-30 20:52:42 +02:00
Not
8a6161a1e1 prevent netvar changes in replays 2022-04-30 15:50:23 +02:00

View File

@ -12,6 +12,8 @@ local splits = {}
local PATCH = nil local PATCH = nil
local help = true local help = true
local EncoreInitial = nil local EncoreInitial = nil
local cv_teamchange
local scoreTable
-- Tracks if stats have been written or not -- Tracks if stats have been written or not
local StatTrack = false local StatTrack = false
@ -76,21 +78,34 @@ local allowJoin
local cv_gui = CV_RegisterVar({ local cv_gui = CV_RegisterVar({
name = "lb_gui", name = "lb_gui",
defaultvalue = GUI_ON, defaultvalue = "On",
flags = 0, flags = 0,
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON} PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
}) })
local cv_afk = CV_RegisterVar({ local AntiAFK = true
CV_RegisterVar({
name = "lb_afk", name = "lb_afk",
defaultvalue = 1, defaultvalue = "On",
flags = CV_NETVAR, flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff 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({ local cv_enable = CV_RegisterVar({
name = "lb_enable", name = "lb_enable",
defaultvalue = 1, defaultvalue = "On",
flags = CV_NETVAR | CV_CALL, flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff, PossibleValue = CV_OnOff,
func = function(v) func = function(v)
@ -110,7 +125,7 @@ local cv_saves = CV_RegisterVar({
local cv_interrupt = CV_RegisterVar({ local cv_interrupt = CV_RegisterVar({
name = "lb_interrupt", name = "lb_interrupt",
defaultvalue = 0, defaultvalue = "Off",
flags = CV_NETVAR | CV_CALL, flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff, PossibleValue = CV_OnOff,
func = function(v) func = function(v)
@ -178,7 +193,7 @@ end
local cv_spb_separate = CV_RegisterVar({ local cv_spb_separate = CV_RegisterVar({
name = "lb_spb_combined", name = "lb_spb_combined",
defaultvalue = 1, defaultvalue = "On",
flags = CV_NETVAR | CV_CALL, flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_YesNo, PossibleValue = CV_YesNo,
func = function(v) func = function(v)
@ -239,7 +254,7 @@ if f then
flags = tonumber(t[7]) flags = tonumber(t[7])
end end
local scoreTable = getScoreTable(tonumber(t[1]), flags) or {} scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
local spl = {} local spl = {}
if t[6] != nil then if t[6] != nil then
@ -282,36 +297,39 @@ end
function allowJoin(v) function allowJoin(v)
if not cv_interrupt.value then if not cv_interrupt.value then
local y
if v then if v then
y = "yes" COM_BufInsertText(server, "allowteamchange Yes")
hud.enable("freeplay") hud.enable("freeplay")
else else
y = "no" COM_BufInsertText(server, "allowteamchange No")
hud.disable("freeplay") hud.disable("freeplay")
end end
COM_BufInsertText(server, "allowteamchange " + y)
end end
end end
local function ingame() local function TwoPlusInGame()
local n = 0 local n = 0
for p in players.iterate do for p in players.iterate do
if p.valid and not p.spectator then if p.valid and not p.spectator then
n = $ + 1 n = $ + 1
if n == 2 then
return true
end end
end end
return n end
return false
end end
local function initLeaderboard(player) local function initLeaderboard(player)
if cv_enable.value and G_RaceGametype() then
if disable and leveltime < START_TIME then if disable and leveltime < START_TIME then
disable = ingame() > 1 disable = TwoPlusInGame()
else else
disable = disable or ingame() > 1 disable = $ or TwoPlusInGame()
end
else
disable = true
end end
disable = $ or not cv_enable.value
-- Restore encore mode to initial value -- Restore encore mode to initial value
if disable and EncoreInitial != nil then if disable and EncoreInitial != nil then
@ -324,7 +342,7 @@ end
addHook("PlayerSpawn", initLeaderboard) addHook("PlayerSpawn", initLeaderboard)
local function doyoudare(player) local function doyoudare(player)
if ingame() > 1 or player.spectator then if TwoPlusInGame() or player.spectator then
CONS_Printf(player, "How dare you") CONS_Printf(player, "How dare you")
return false return false
end end
@ -660,7 +678,7 @@ function ticsToTime(tics, pure)
return string.format( return string.format(
"%d:%02d:%02d", "%d:%02d:%02d",
G_TicsToMinutes(tics), G_TicsToMinutes(tics, true),
G_TicsToSeconds(tics), G_TicsToSeconds(tics),
G_TicsToCentiseconds(tics) G_TicsToCentiseconds(tics)
) )
@ -907,10 +925,10 @@ local function drawScroll(v, player, scoreTable, gui)
local x = 10 local x = 10
if #scoreTable >= 10 then if #scoreTable >= 10 then
x = x + 8 x = x + 8
end
if #scoreTable >= 100 then if #scoreTable >= 100 then
x = x + 8 x = x + 8
end end
end
local y = FixedInt(scrollY) local y = FixedInt(scrollY)
@ -961,8 +979,6 @@ local function drawScoreboard(v, player)
cachePatches(v) cachePatches(v)
local scoreTable = getScoreTable(gamemap, Flags)
local gui = cv_gui.value local gui = cv_gui.value
if leveltime < START_TIME or player.exiting or player.lives == 0 then if leveltime < START_TIME or player.exiting or player.lives == 0 then
gui = GUI_ON gui = GUI_ON
@ -1009,7 +1025,7 @@ end
-- Find location of player and scroll to it -- Find location of player and scroll to it
function scroll_to(player) function scroll_to(player)
local m = getScoreTable(gamemap, Flags) or {} local m = scoreTable or {}
scrollToPos = 2 scrollToPos = 2
for pos, score in ipairs(m) do for pos, score in ipairs(m) do
@ -1038,7 +1054,8 @@ local function writeStats()
end end
local function saveTime(player) local function saveTime(player)
local scoreTable = getScoreTable(gamemap, Flags) or {}
scoreTable = $ or {}
local pskin = skins[player.mo.skin] local pskin = skins[player.mo.skin]
local newscore = score_t( local newscore = score_t(
@ -1145,7 +1162,8 @@ local function think()
end end
if disable then if disable then
if cv_afk.value and ingame() > 1 then if AntiAFK then
if TwoPlusInGame() then
for p in players.iterate do for p in players.iterate do
if p.valid and not p.spectator and not p.exiting and p.lives > 0 then if p.valid and not p.spectator and not p.exiting and p.lives > 0 then
if p.cmd.buttons then if p.cmd.buttons then
@ -1170,6 +1188,7 @@ local function think()
end end
end end
end end
end
help = true help = true
return return
@ -1181,7 +1200,7 @@ local function think()
if leveltime < START_TIME then if leveltime < START_TIME then
-- Help message -- Help message
if leveltime == START_TIME - TICRATE * 3 then if leveltime == START_TIME - TICRATE * 3 then
if ingame() == 1 then if p then
if help then if help then
help = false help = false
chatprint(HELP_MESSAGE, true) chatprint(HELP_MESSAGE, true)
@ -1217,14 +1236,14 @@ local function think()
end end
if clearcheats then if clearcheats then
clearcheats = false clearcheats = false
for p in players.iterate do for q in players.iterate do
p.SPBAKARTBIG = false q.SPBAKARTBIG = false
p.SPBAjustice = false q.SPBAjustice = false
p.SPBAshutup = false q.SPBAshutup = false
end end
end end
for p in players.iterate do
if not p.spectator then if p then
if p.SPBAKARTBIG then if p.SPBAKARTBIG then
Flags = $ | F_SPBBIG Flags = $ | F_SPBBIG
end end
@ -1232,14 +1251,19 @@ local function think()
Flags = $ | F_SPBJUS Flags = $ | F_SPBJUS
end end
end end
end
end end
if not (Flags & F_SPBATK) then if not (Flags & F_SPBATK) then
hud.enable("freeplay") hud.enable("freeplay")
end end
end end
local cv_teamchange = CV_FindVar("allowteamchange") scoreTable = getScoreTable(gamemap, Flags)
if not cv_teamchange then
cv_teamchange = CV_FindVar("allowteamchange")
end
if p then if p then
-- Scroll controller -- Scroll controller
-- Spectators can't input buttons so let the gamer do it -- Spectators can't input buttons so let the gamer do it
@ -1264,6 +1288,7 @@ local function think()
p.afkTime = leveltime p.afkTime = leveltime
end end
if not replayplayback then
if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then
if cv_teamchange.value then if cv_teamchange.value then
allowJoin(false) allowJoin(false)
@ -1273,6 +1298,7 @@ local function think()
allowJoin(true) allowJoin(true)
end end
end end
end
if p.laps >= mapheaderinfo[gamemap].numlaps and timeFinished == 0 then if p.laps >= mapheaderinfo[gamemap].numlaps and timeFinished == 0 then
timeFinished = p.realtime timeFinished = p.realtime
@ -1290,11 +1316,17 @@ local function interThink()
COM_BufInsertText(server, "map " + nextMap) COM_BufInsertText(server, "map " + nextMap)
nextMap = nil nextMap = nil
end 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) allowJoin(true)
end end
end end
addHook("IntermissionThinker", interThink) addHook("IntermissionThinker", interThink)
addHook("VoteThinker", interThink)
-- Returns the values clamed between min, max -- Returns the values clamed between min, max
function clamp(min_v, v, max_v) function clamp(min_v, v, max_v)