Compare commits

..

15 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

View File

@ -12,6 +12,8 @@ local splits = {}
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
@ -76,21 +78,34 @@ 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}
})
local cv_afk = CV_RegisterVar({
local AntiAFK = true
CV_RegisterVar({
name = "lb_afk",
defaultvalue = 1,
flags = CV_NETVAR,
PossibleValue = CV_OnOff
defaultvalue = "On",
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({
name = "lb_enable",
defaultvalue = 1,
defaultvalue = "On",
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
@ -110,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)
@ -178,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)
@ -239,7 +254,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
@ -282,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
@ -324,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
@ -660,7 +678,7 @@ function ticsToTime(tics, pure)
return string.format(
"%d:%02d:%02d",
G_TicsToMinutes(tics),
G_TicsToMinutes(tics, true),
G_TicsToSeconds(tics),
G_TicsToCentiseconds(tics)
)
@ -907,9 +925,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)
@ -961,8 +979,6 @@ local function drawScoreboard(v, player)
cachePatches(v)
local scoreTable = getScoreTable(gamemap, Flags)
local gui = cv_gui.value
if leveltime < START_TIME or player.exiting or player.lives == 0 then
gui = GUI_ON
@ -1009,7 +1025,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
@ -1038,7 +1054,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(
@ -1145,28 +1162,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 AntiAFK 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
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
@ -1181,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)
@ -1217,29 +1236,34 @@ 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")
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
-- Scroll controller
-- Spectators can't input buttons so let the gamer do it
@ -1292,11 +1316,17 @@ 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
addHook("IntermissionThinker", interThink)
addHook("VoteThinker", interThink)
-- Returns the values clamed between min, max
function clamp(min_v, v, max_v)