Compare commits

..

9 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
Not
8a6161a1e1 prevent netvar changes in replays 2022-04-30 15:50:23 +02:00

View File

@ -78,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)
@ -112,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)
@ -180,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)
@ -284,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 end
return n return false
end end
local function initLeaderboard(player) local function initLeaderboard(player)
if disable and leveltime < START_TIME then if cv_enable.value and G_RaceGametype() then
disable = ingame() > 1 if disable and leveltime < START_TIME then
disable = TwoPlusInGame()
else
disable = $ or TwoPlusInGame()
end
else else
disable = disable or ingame() > 1 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
@ -326,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
@ -1146,8 +1162,8 @@ local function think()
end end
if disable then if disable then
if cv_afk.value then if AntiAFK then
if ingame() > 1 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
@ -1184,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)
@ -1272,13 +1288,15 @@ local function think()
p.afkTime = leveltime p.afkTime = leveltime
end end
if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then if not replayplayback then
if cv_teamchange.value then if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then
allowJoin(false) if cv_teamchange.value then
end allowJoin(false)
elseif p.afkTime + AFK_TIMEOUT < leveltime then end
if not cv_teamchange.value then elseif p.afkTime + AFK_TIMEOUT < leveltime then
allowJoin(true) if not cv_teamchange.value then
allowJoin(true)
end
end end
end end