5 Commits

Author SHA1 Message Date
Not
b040fdd933 v1.2.15 2022-03-28 13:14:30 +02:00
Not
70cd579079 v1.2.14 2022-03-28 13:14:08 +02:00
Not
e68ab38262 v1.2.13 2022-03-28 13:13:42 +02:00
Not
f1a886182c v1.2.12 2022-03-28 13:13:21 +02:00
Not
017794c554 v1.2.11 2022-03-28 13:13:00 +02:00

View File

@ -1,4 +1,5 @@
-- Leaderboards written by Not -- Leaderboards written by Not
-- Reusable
local FILENAME = "leaderboard.txt" local FILENAME = "leaderboard.txt"
local lb = {} local lb = {}
@ -9,6 +10,9 @@ local splits = {}
local PATCH = nil local PATCH = nil
local help = true local help = true
-- Retry / changelevel map
local nextMap = nil
local Flags = 0 local Flags = 0
-- SPB flags with the least significance first -- SPB flags with the least significance first
@ -19,11 +23,55 @@ local F_SPBEXP = 0x8
local clearcheats = false local clearcheats = false
local startTime = 6 * TICRATE + (3 * TICRATE / 4) local START_TIME = 6 * TICRATE + (3 * TICRATE / 4)
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 -- patch caching function
local cachePatches 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 function lbID(map, flags)
local id = tostring(map) local id = tostring(map)
if flags & F_SPBATK then if flags & F_SPBATK then
@ -92,6 +140,21 @@ else
print("Failed to open file: ", FILENAME) print("Failed to open file: ", FILENAME)
end end
local function allowJoin(v)
if not cv_interrupt.value then
local y
if v then
y = "yes"
hud.enable("freeplay")
else
y = "no"
hud.disable("freeplay")
end
COM_BufInsertText(server, "allowteamchange " + y)
end
end
local function ingame() local function ingame()
local n = 0 local n = 0
for p in players.iterate do for p in players.iterate do
@ -103,11 +166,13 @@ local function ingame()
end end
local function initLeaderboard(player) local function initLeaderboard(player)
if disable and leveltime < startTime then if disable and leveltime < START_TIME then
disable = ingame() > 1 disable = ingame() > 1
else else
disable = disable or ingame() > 1 disable = disable or ingame() > 1
end end
disable = $ or not cv_enable.value
player.afkTime = leveltime
end end
addHook("PlayerSpawn", initLeaderboard) addHook("PlayerSpawn", initLeaderboard)
@ -121,7 +186,11 @@ end
local function retry(player, ...) local function retry(player, ...)
if doyoudare(player) then if doyoudare(player) then
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap)) -- Prevents bind crash
if leveltime < 20 then
return
end
nextMap = G_BuildMapName(gamemap)
end end
end end
COM_AddCommand("retry", retry) COM_AddCommand("retry", retry)
@ -133,6 +202,33 @@ local function exitlevel(player, ...)
end end
COM_AddCommand("exit", exitlevel) 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) local function mapNotExists(player, map)
CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper())) CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper()))
end end
@ -143,6 +239,9 @@ local function changelevel(player, ...)
if not doyoudare(player) then if not doyoudare(player) then
return return
end end
if leveltime < 20 then
return
end
local map = ... local map = ...
if map == nil then if map == nil then
@ -176,7 +275,7 @@ local function changelevel(player, ...)
return return
end end
COM_BufInsertText(server, "map " + (G_BuildMapName(mapnum))) nextMap = G_BuildMapName(mapnum)
end end
COM_AddCommand("changelevel", changelevel) COM_AddCommand("changelevel", changelevel)
@ -213,6 +312,8 @@ addHook("MapLoad", function()
timeFinished = 0 timeFinished = 0
splits = {} splits = {}
prevLap = 0 prevLap = 0
allowJoin(true)
--printTable(lb) --printTable(lb)
end end
) )
@ -250,7 +351,9 @@ local function marquee(text, maxwidth)
return text:sub(pos, pos + maxwidth - 1) return text:sub(pos, pos + maxwidth - 1)
end end
-- Bats on ...
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0} local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP} local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
local splitSymbol = {[true]="-", [false]="+"} local splitSymbol = {[true]="-", [false]="+"}
@ -267,6 +370,12 @@ local function drawScoreboard(v, player)
return return
end 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 for i, score in ipairs(m) do
local name = score["name"] local name = score["name"]
local skin = skins[score["skin"]] local skin = skins[score["skin"]]
@ -326,6 +435,7 @@ local function drawScoreboard(v, player)
end end
end end
if gui == GUI_ON or (gui == GUI_SPLITS and showSplit)
-- Shorten long names -- Shorten long names
local stralign = "left" local stralign = "left"
local MAXWIDTH = 70 local MAXWIDTH = 70
@ -352,7 +462,7 @@ local function drawScoreboard(v, player)
) )
-- Draw splits -- 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] local split = splits[prevLap] - score["splits"][prevLap]
v.drawString( v.drawString(
px + skinPatch.width, px + skinPatch.width,
@ -369,6 +479,8 @@ local function drawScoreboard(v, player)
) )
end end
end end
end
end
end end
hud.add(drawScoreboard, "game") hud.add(drawScoreboard, "game")
@ -403,7 +515,7 @@ local function lbComp(a, b)
-- if s is negative then b is harder -- if s is negative then b is harder
-- if s is 0 then compare time -- if s is 0 then compare time
local s = (a["flags"] & (F_SPBEXP | F_SPBBIG)) - (b["flags"] & (F_SPBEXP | F_SPBBIG)) local s = (a["flags"] & (F_SPBEXP | F_SPBBIG)) - (b["flags"] & (F_SPBEXP | F_SPBBIG))
return s > 0 or not(s < 0 or a["time"] > b["time"]) return s > 0 or not(s < 0 or a["time"] >= b["time"])
end end
local function saveTime(player) local function saveTime(player)
@ -475,7 +587,7 @@ end
-- DEBUGGING -- DEBUGGING
--local function saveLeaderboard(player, ...) --local function saveLeaderboard(player, ...)
-- timeFinished = player.realtime -- timeFinished = tonumber(... or player.realtime)
-- splits = {1000, 2000, 3000} -- splits = {1000, 2000, 3000}
-- saveTime(player) -- saveTime(player)
--end --end
@ -489,8 +601,41 @@ local function regLap(player)
end end
end end
local function getGamer()
for p in players.iterate do
if p.valid and not p.spectator then
return p
end
end
end
local function think() local function think()
if nextMap then
COM_BufInsertText(server, "map " + nextMap)
nextMap = nil
end
if disable then 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 then
if p.cmd.buttons then
p.afkTime = leveltime
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
else
for p in players.iterate do
if p.valid and not p.spectator then
p.afkTime = leveltime
end
end
end
help = true help = true
return return
end end
@ -498,13 +643,14 @@ local function think()
showSplit = showSplit - 1 showSplit = showSplit - 1
end end
if leveltime < startTime then local p = getGamer()
if leveltime < START_TIME then
-- Help message -- Help message
if leveltime == startTime - TICRATE * 3 then if leveltime == START_TIME - TICRATE * 3 then
if ingame() == 1 then if ingame() == 1 then
if help then if help then
help = false 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 end
else else
help = true help = true
@ -513,16 +659,10 @@ local function think()
-- Autospec -- Autospec
if leveltime == 1 then if leveltime == 1 then
local gamer = nil if p then
for p in players.iterate do for s in players.iterate do
if p.valid and not p.spectator then if s.valid and s.spectator then
gamer = #p COM_BufInsertText(s, string.format("view \"%d\"", #p))
end
end
if gamer then
for p in players.iterate do
if p.valid and p.spectator then
COM_BufInsertText(p, string.format("view \"%d\"", gamer))
end end
end end
end end
@ -530,7 +670,7 @@ local function think()
-- Gamemode flags -- Gamemode flags
Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS) Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS)
if leveltime > startTime - (3 * TICRATE) / 2 and server.SPBArunning then if leveltime > START_TIME - (3 * TICRATE) / 2 and server.SPBArunning then
Flags = $ | F_SPBATK Flags = $ | F_SPBATK
if server.SPBAexpert then if server.SPBAexpert then
Flags = $ | F_SPBEXP Flags = $ | F_SPBEXP
@ -554,19 +694,52 @@ local function think()
end end
end 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.afkTime = leveltime
end
if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then
if cv_teamchange.value then
allowJoin(false)
end
elseif p.afkTime + AFK_TIMEOUT < leveltime then
if not cv_teamchange.value then
allowJoin(true)
end
end end
for p in players.iterate do
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
saveTime(p) saveTime(p)
end end
regLap(p) regLap(p)
elseif cv_teamchange.value == 0 then
allowJoin(true)
end end
end end
addHook("ThinkFrame", think) addHook("ThinkFrame", think)
local function interThink()
if nextMap then
COM_BufInsertText(server, "map " + nextMap)
nextMap = nil
end
if not CV_FindVar("allowteamchange").value then
allowJoin(true)
end
end
addHook("IntermissionThinker", interThink)
local function netvars(net) local function netvars(net)
lb = net($) lb = net($)
splits = net($)
prevLap = net($)
end end
addHook("NetVars", netvars) addHook("NetVars", netvars)