This commit is contained in:
Not 2022-03-28 13:14:30 +02:00
parent 70cd579079
commit b040fdd933
1 changed files with 194 additions and 106 deletions

View File

@ -1,4 +1,5 @@
-- Leaderboards written by Not
-- Reusable
local FILENAME = "leaderboard.txt"
local lb = {}
@ -27,9 +28,50 @@ local AFK_TIMEOUT = TICRATE * 5
local AFK_BALANCE = TICRATE * 60
local PREVENT_JOIN_TIME = START_TIME + TICRATE * 5
local GUI_OFF = 0x0
local GUI_SPLITS = 0x1
local GUI_ON = 0x2
-- patch caching function
local cachePatches
local cv_gui = CV_RegisterVar({
name = "lb_gui",
defaultvalue = GUI_ON,
flags = 0,
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
})
local cv_afk = CV_RegisterVar({
name = "lb_afk",
defaultvalue = 1,
flags = CV_NETVAR,
PossibleValue = CV_OnOff
})
local cv_enable = CV_RegisterVar({
name = "lb_enable",
defaultvalue = 1,
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
disable = $ or not v.value
end
})
local cv_interrupt = CV_RegisterVar({
name = "lb_interrupt",
defaultvalue = 0,
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_OnOff,
func = function(v)
if v.value then
COM_BufInsertText(server, "allowteamchange yes")
end
end
})
local function lbID(map, flags)
local id = tostring(map)
if flags & F_SPBATK then
@ -99,6 +141,7 @@ else
end
local function allowJoin(v)
if not cv_interrupt.value then
local y
if v then
y = "yes"
@ -109,6 +152,7 @@ local function allowJoin(v)
end
COM_BufInsertText(server, "allowteamchange " + y)
end
end
local function ingame()
@ -127,7 +171,8 @@ local function initLeaderboard(player)
else
disable = disable or ingame() > 1
end
player.afkTimeout = leveltime
disable = $ or not cv_enable.value
player.afkTime = leveltime
end
addHook("PlayerSpawn", initLeaderboard)
@ -157,6 +202,33 @@ local function exitlevel(player, ...)
end
COM_AddCommand("exit", exitlevel)
local function findMap(player, ...)
local search = ...
if search == nil then
return
end
for i = 1, #mapheaderinfo do
local map = mapheaderinfo[i]
if map == nil then
continue
end
if map.lvlttl:lower():find(search:lower()) then
CONS_Printf(
player,
string.format(
"%s - %s",
G_BuildMapName(i),
map.lvlttl
)
)
end
end
end
COM_AddCommand("findmap", findMap)
local function mapNotExists(player, map)
CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper()))
end
@ -279,7 +351,9 @@ local function marquee(text, maxwidth)
return text:sub(pos, pos + maxwidth - 1)
end
-- Bats on ...
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
local splitSymbol = {[true]="-", [false]="+"}
@ -296,6 +370,12 @@ local function drawScoreboard(v, player)
return
end
local gui = cv_gui.value
if leveltime < START_TIME or player.exiting or player.lives == 0 then
gui = GUI_ON
end
if gui then
for i, score in ipairs(m) do
local name = score["name"]
local skin = skins[score["skin"]]
@ -355,6 +435,7 @@ local function drawScoreboard(v, player)
end
end
if gui == GUI_ON or (gui == GUI_SPLITS and showSplit)
-- Shorten long names
local stralign = "left"
local MAXWIDTH = 70
@ -381,7 +462,7 @@ local function drawScoreboard(v, player)
)
-- Draw splits
if showSplit > 0 and score["splits"][prevLap] != nil then
if showSplit and score["splits"][prevLap] != nil then
local split = splits[prevLap] - score["splits"][prevLap]
v.drawString(
px + skinPatch.width,
@ -398,6 +479,8 @@ local function drawScoreboard(v, player)
)
end
end
end
end
end
hud.add(drawScoreboard, "game")
@ -533,13 +616,13 @@ local function think()
end
if disable then
if ingame() > 1 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 then
if p.cmd.buttons then
p.afkTimeout = leveltime
p.afkTime = leveltime
end
if p.afkTimeout + AFK_BALANCE < leveltime then
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
@ -548,7 +631,7 @@ local function think()
else
for p in players.iterate do
if p.valid and not p.spectator then
p.afkTimeout = leveltime
p.afkTime = leveltime
end
end
end
@ -567,7 +650,7 @@ local function think()
if ingame() == 1 then
if help then
help = false
chatprint("\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats", true)
chatprint("\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui", true)
end
else
help = true
@ -611,19 +694,22 @@ local function think()
end
end
end
if not (Flags & F_SPBATK) then
hud.enable("freeplay")
end
end
local cv_teamchange = CV_FindVar("allowteamchange")
if p then
if p.cmd.buttons then
p.afkTimeout = leveltime
p.afkTime = leveltime
end
if leveltime > PREVENT_JOIN_TIME and p.afkTimeout + AFK_TIMEOUT > leveltime then
if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then
if cv_teamchange.value then
allowJoin(false)
end
elseif p.afkTimeout + AFK_TIMEOUT < leveltime then
elseif p.afkTime + AFK_TIMEOUT < leveltime then
if not cv_teamchange.value then
allowJoin(true)
end
@ -653,5 +739,7 @@ addHook("IntermissionThinker", interThink)
local function netvars(net)
lb = net($)
splits = net($)
prevLap = net($)
end
addHook("NetVars", netvars)