5 Commits

Author SHA1 Message Date
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
Not
2e5c209a65 v1.2.10 2022-03-28 13:12:43 +02:00

View File

@ -3,12 +3,15 @@
local FILENAME = "leaderboard.txt"
local lb = {}
local timeFinished = 0
local disable = true
local disable = false
local prevLap = 0
local splits = {}
local PATCH = nil
local help = true
-- Retry / changelevel map
local nextMap = nil
local Flags = 0
-- SPB flags with the least significance first
@ -19,7 +22,10 @@ local F_SPBEXP = 0x8
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
-- patch caching function
local cachePatches
@ -92,6 +98,19 @@ else
print("Failed to open file: ", FILENAME)
end
local function allowJoin(v)
local y
if v then
y = "yes"
hud.enable("freeplay")
else
y = "no"
hud.disable("freeplay")
end
COM_BufInsertText(server, "allowteamchange " + y)
end
local function ingame()
local n = 0
for p in players.iterate do
@ -103,12 +122,17 @@ local function ingame()
end
local function initLeaderboard(player)
disable = ingame() > 1
if disable and leveltime < START_TIME then
disable = ingame() > 1
else
disable = disable or ingame() > 1
end
player.afkTimeout = leveltime
end
addHook("PlayerSpawn", initLeaderboard)
local function doyoudare(player)
if disable or player.spectator then
if ingame() > 1 or player.spectator then
CONS_Printf(player, "How dare you")
return false
end
@ -117,7 +141,11 @@ end
local function retry(player, ...)
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
COM_AddCommand("retry", retry)
@ -139,6 +167,9 @@ local function changelevel(player, ...)
if not doyoudare(player) then
return
end
if leveltime < 20 then
return
end
local map = ...
if map == nil then
@ -172,7 +203,7 @@ local function changelevel(player, ...)
return
end
COM_BufInsertText(server, "map " + (G_BuildMapName(mapnum)))
nextMap = G_BuildMapName(mapnum)
end
COM_AddCommand("changelevel", changelevel)
@ -209,6 +240,8 @@ addHook("MapLoad", function()
timeFinished = 0
splits = {}
prevLap = 0
allowJoin(true)
--printTable(lb)
end
)
@ -399,7 +432,7 @@ local function lbComp(a, b)
-- if s is negative then b is harder
-- if s is 0 then compare time
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
local function saveTime(player)
@ -471,7 +504,7 @@ end
-- DEBUGGING
--local function saveLeaderboard(player, ...)
-- timeFinished = player.realtime
-- timeFinished = tonumber(... or player.realtime)
-- splits = {1000, 2000, 3000}
-- saveTime(player)
--end
@ -485,8 +518,41 @@ local function regLap(player)
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()
if nextMap then
COM_BufInsertText(server, "map " + nextMap)
nextMap = nil
end
if disable then
if 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
end
if p.afkTimeout + 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.afkTimeout = leveltime
end
end
end
help = true
return
end
@ -494,9 +560,10 @@ local function think()
showSplit = showSplit - 1
end
if leveltime < startTime then
local p = getGamer()
if leveltime < START_TIME then
-- Help message
if leveltime == startTime - TICRATE * 3 then
if leveltime == START_TIME - TICRATE * 3 then
if ingame() == 1 then
if help then
help = false
@ -509,16 +576,10 @@ local function think()
-- Autospec
if leveltime == 1 then
local gamer = nil
for p in players.iterate do
if p.valid and not p.spectator then
gamer = #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))
if p then
for s in players.iterate do
if s.valid and s.spectator then
COM_BufInsertText(s, string.format("view \"%d\"", #p))
end
end
end
@ -526,7 +587,7 @@ local function think()
-- Gamemode flags
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
if server.SPBAexpert then
Flags = $ | F_SPBEXP
@ -552,16 +613,44 @@ local function think()
end
end
for p in players.iterate do
local cv_teamchange = CV_FindVar("allowteamchange")
if p then
if p.cmd.buttons then
p.afkTimeout = leveltime
end
if leveltime > PREVENT_JOIN_TIME and p.afkTimeout + AFK_TIMEOUT > leveltime then
if cv_teamchange.value then
allowJoin(false)
end
elseif p.afkTimeout + AFK_TIMEOUT < leveltime then
if not cv_teamchange.value then
allowJoin(true)
end
end
if p.laps >= mapheaderinfo[gamemap].numlaps and timeFinished == 0 then
timeFinished = p.realtime
saveTime(p)
end
regLap(p)
elseif cv_teamchange.value == 0 then
allowJoin(true)
end
end
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)
lb = net($)
end