Compare commits

...

6 Commits

Author SHA1 Message Date
Lonsfor e25b417fbd fix function name 2022-05-15 22:31:51 +02:00
Lonsfor 3d54350dae Use strings as the default cvar value 2022-05-14 08:12:58 +02:00
Lonsfor 89da89fbfe Simplify allowJoin() 2022-05-14 08:04:28 +02:00
Lonsfor 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
Lonsfor 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
Lonsfor 6ea3341b06 better init logic + make sure we are not in battle 2022-05-14 07:33:03 +02:00
1 changed files with 22 additions and 19 deletions

View File

@ -78,7 +78,7 @@ local allowJoin
local cv_gui = CV_RegisterVar({
name = "lb_gui",
defaultvalue = GUI_ON,
defaultvalue = "On",
flags = 0,
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
})
@ -86,7 +86,7 @@ local cv_gui = CV_RegisterVar({
local AntiAFK = true
CV_RegisterVar({
name = "lb_afk",
defaultvalue = 1,
defaultvalue = "On",
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
@ -105,7 +105,7 @@ CV_RegisterVar({
local cv_enable = CV_RegisterVar({
name = "lb_enable",
defaultvalue = 1,
defaultvalue = "On",
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
@ -125,7 +125,7 @@ local cv_saves = CV_RegisterVar({
local cv_interrupt = CV_RegisterVar({
name = "lb_interrupt",
defaultvalue = 0,
defaultvalue = "Off",
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
@ -193,7 +193,7 @@ end
local cv_spb_separate = CV_RegisterVar({
name = "lb_spb_combined",
defaultvalue = 1,
defaultvalue = "On",
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_YesNo,
func = function(v)
@ -297,36 +297,39 @@ end
function allowJoin(v)
if not cv_interrupt.value then
local y
if v then
y = "yes"
COM_BufInsertText(server, "allowteamchange Yes")
hud.enable("freeplay")
else
y = "no"
COM_BufInsertText(server, "allowteamchange No")
hud.disable("freeplay")
end
COM_BufInsertText(server, "allowteamchange " + y)
end
end
local function ingame()
local function TwoPlusInGame()
local n = 0
for p in players.iterate do
if p.valid and not p.spectator then
n = $ + 1
if n == 2 then
return true
end
end
end
return n
return false
end
local function initLeaderboard(player)
if disable and leveltime < START_TIME then
disable = ingame() > 1
if cv_enable.value and G_RaceGametype() then
if disable and leveltime < START_TIME then
disable = TwoPlusInGame()
else
disable = $ or TwoPlusInGame()
end
else
disable = disable or ingame() > 1
disable = true
end
disable = $ or not cv_enable.value
-- Restore encore mode to initial value
if disable and EncoreInitial != nil then
@ -339,7 +342,7 @@ end
addHook("PlayerSpawn", initLeaderboard)
local function doyoudare(player)
if ingame() > 1 or player.spectator then
if TwoPlusInGame() or player.spectator then
CONS_Printf(player, "How dare you")
return false
end
@ -1160,7 +1163,7 @@ local function think()
if disable then
if AntiAFK then
if ingame() > 1 then
if TwoPlusInGame() 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
@ -1197,7 +1200,7 @@ local function think()
if leveltime < START_TIME then
-- Help message
if leveltime == START_TIME - TICRATE * 3 then
if ingame() == 1 then
if p then
if help then
help = false
chatprint(HELP_MESSAGE, true)