forked from Not/srb2k-leaderboard
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
f1a886182c | |||
017794c554 | |||
2e5c209a65 |
115
leaderboard.lua
115
leaderboard.lua
@ -3,7 +3,7 @@
|
|||||||
local FILENAME = "leaderboard.txt"
|
local FILENAME = "leaderboard.txt"
|
||||||
local lb = {}
|
local lb = {}
|
||||||
local timeFinished = 0
|
local timeFinished = 0
|
||||||
local disable = true
|
local disable = false
|
||||||
local prevLap = 0
|
local prevLap = 0
|
||||||
local splits = {}
|
local splits = {}
|
||||||
local PATCH = nil
|
local PATCH = nil
|
||||||
@ -19,7 +19,10 @@ 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
|
||||||
|
|
||||||
-- patch caching function
|
-- patch caching function
|
||||||
local cachePatches
|
local cachePatches
|
||||||
@ -92,6 +95,20 @@ else
|
|||||||
print("Failed to open file: ", FILENAME)
|
print("Failed to open file: ", FILENAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function allowJoin(v)
|
||||||
|
local y
|
||||||
|
if v then
|
||||||
|
y = "yes"
|
||||||
|
--hud.enable("freeplay")
|
||||||
|
else
|
||||||
|
y = "no"
|
||||||
|
-- Why in gods name does this work on a local server but fails on a public one
|
||||||
|
--hud.disable("freeplay")
|
||||||
|
end
|
||||||
|
|
||||||
|
COM_BufInsertText(server, "allowteamchange " + y)
|
||||||
|
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,12 +120,17 @@ local function ingame()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function initLeaderboard(player)
|
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
|
end
|
||||||
addHook("PlayerSpawn", initLeaderboard)
|
addHook("PlayerSpawn", initLeaderboard)
|
||||||
|
|
||||||
local function doyoudare(player)
|
local function doyoudare(player)
|
||||||
if disable or player.spectator then
|
if ingame() > 1 or player.spectator then
|
||||||
CONS_Printf(player, "How dare you")
|
CONS_Printf(player, "How dare you")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -117,6 +139,10 @@ end
|
|||||||
|
|
||||||
local function retry(player, ...)
|
local function retry(player, ...)
|
||||||
if doyoudare(player) then
|
if doyoudare(player) then
|
||||||
|
-- Prevents bind crash
|
||||||
|
if leveltime < 15 then
|
||||||
|
return
|
||||||
|
end
|
||||||
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -139,6 +165,9 @@ local function changelevel(player, ...)
|
|||||||
if not doyoudare(player) then
|
if not doyoudare(player) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if leveltime < 15 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local map = ...
|
local map = ...
|
||||||
if map == nil then
|
if map == nil then
|
||||||
@ -209,6 +238,8 @@ addHook("MapLoad", function()
|
|||||||
timeFinished = 0
|
timeFinished = 0
|
||||||
splits = {}
|
splits = {}
|
||||||
prevLap = 0
|
prevLap = 0
|
||||||
|
|
||||||
|
allowJoin(true)
|
||||||
--printTable(lb)
|
--printTable(lb)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@ -485,8 +516,37 @@ 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 disable then
|
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
|
help = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -494,9 +554,10 @@ 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
|
||||||
@ -509,16 +570,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
|
||||||
@ -526,7 +581,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
|
||||||
@ -552,16 +607,40 @@ local function think()
|
|||||||
end
|
end
|
||||||
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
|
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 resetTeamchange()
|
||||||
|
if not CV_FindVar("allowteamchange").value then
|
||||||
|
allowJoin(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
addHook("IntermissionThinker", resetTeamchange)
|
||||||
|
|
||||||
local function netvars(net)
|
local function netvars(net)
|
||||||
lb = net($)
|
lb = net($)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user