Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
e68ab38262 | |||
f1a886182c | |||
017794c554 | |||
2e5c209a65 | |||
3101d29dcc | |||
36134572af | |||
bc002667c8 | |||
b0d5b5abeb | |||
18a81fab6d | |||
9a1fb0677a |
246
leaderboard.lua
246
leaderboard.lua
@ -3,10 +3,14 @@
|
|||||||
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
|
||||||
|
local help = true
|
||||||
|
|
||||||
|
-- Retry / changelevel map
|
||||||
|
local nextMap = nil
|
||||||
|
|
||||||
local Flags = 0
|
local Flags = 0
|
||||||
|
|
||||||
@ -18,7 +22,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
|
||||||
@ -91,42 +98,115 @@ else
|
|||||||
print("Failed to open file: ", FILENAME)
|
print("Failed to open file: ", FILENAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function initLeaderboard(player)
|
local function allowJoin(v)
|
||||||
local ingame = 0
|
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
|
for p in players.iterate do
|
||||||
if p.valid and not p.spectator then
|
if p.valid and not p.spectator then
|
||||||
ingame = ingame + 1
|
n = $ + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
|
||||||
disable = ingame > 1
|
local function initLeaderboard(player)
|
||||||
|
if disable and leveltime < START_TIME then
|
||||||
if disable then
|
disable = ingame() > 1
|
||||||
--print("To many players in game, leaderboard has been disabled")
|
else
|
||||||
return
|
disable = disable or ingame() > 1
|
||||||
end
|
end
|
||||||
|
player.afkTimeout = leveltime
|
||||||
end
|
end
|
||||||
addHook("PlayerSpawn", initLeaderboard)
|
addHook("PlayerSpawn", initLeaderboard)
|
||||||
|
|
||||||
local function retry(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
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
local function retry(player, ...)
|
||||||
|
if doyoudare(player) then
|
||||||
|
-- Prevents bind crash
|
||||||
|
if leveltime < 20 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
nextMap = G_BuildMapName(gamemap)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
COM_AddCommand("retry", retry)
|
COM_AddCommand("retry", retry)
|
||||||
|
|
||||||
local function exitlevel(player, ...)
|
local function exitlevel(player, ...)
|
||||||
if disable or player.spectator then
|
if doyoudare(player) then
|
||||||
CONS_Printf(player, "How dare you")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
G_ExitLevel()
|
G_ExitLevel()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
COM_AddCommand("exit", exitlevel)
|
COM_AddCommand("exit", exitlevel)
|
||||||
|
|
||||||
|
local function mapNotExists(player, map)
|
||||||
|
CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper()))
|
||||||
|
end
|
||||||
|
|
||||||
|
local ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
local function changelevel(player, ...)
|
||||||
|
if not doyoudare(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if leveltime < 20 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local map = ...
|
||||||
|
if map == nil then
|
||||||
|
CONS_Printf(player, "Usage: changelevel MAPXX")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local p, q = map:upper():match("MAP(%w)(%w)$", 1)
|
||||||
|
if not (p and q) then
|
||||||
|
CONS_Printf(player, string.format("Invalid map name: %s", map))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local mapnum = 0
|
||||||
|
if tonumber(p) != nil then
|
||||||
|
-- Non extended map numbers
|
||||||
|
if tonumber(q) == nil then
|
||||||
|
mapNotExists(player, map)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
mapnum = tonumber(p) * 10 + tonumber(q)
|
||||||
|
else
|
||||||
|
--Extended map numbers
|
||||||
|
p = ALPH:find(p) - 1
|
||||||
|
q = (tonumber(q) or ALPH:find(q) + 9)
|
||||||
|
mapnum = 36 * p + q + 100
|
||||||
|
end
|
||||||
|
|
||||||
|
if mapheaderinfo[mapnum] == nil then
|
||||||
|
mapNotExists(player, map)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
nextMap = G_BuildMapName(mapnum)
|
||||||
|
end
|
||||||
|
COM_AddCommand("changelevel", changelevel)
|
||||||
|
|
||||||
local function clearcheats(player)
|
local function clearcheats(player)
|
||||||
if not player.spectator then
|
if not player.spectator then
|
||||||
clearcheats = true
|
clearcheats = true
|
||||||
@ -160,6 +240,8 @@ addHook("MapLoad", function()
|
|||||||
timeFinished = 0
|
timeFinished = 0
|
||||||
splits = {}
|
splits = {}
|
||||||
prevLap = 0
|
prevLap = 0
|
||||||
|
|
||||||
|
allowJoin(true)
|
||||||
--printTable(lb)
|
--printTable(lb)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@ -202,6 +284,7 @@ local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
|
|||||||
local splitSymbol = {[true]="-", [false]="+"}
|
local splitSymbol = {[true]="-", [false]="+"}
|
||||||
|
|
||||||
local showSplit = 0
|
local showSplit = 0
|
||||||
|
local VFLAGS = V_SNAPTOLEFT
|
||||||
local function drawScoreboard(v, player)
|
local function drawScoreboard(v, player)
|
||||||
if disable then return end
|
if disable then return end
|
||||||
if player != displayplayers[0] then return end
|
if player != displayplayers[0] then return end
|
||||||
@ -224,9 +307,9 @@ local function drawScoreboard(v, player)
|
|||||||
-- | OFFSET | + | PADDING | * |INDEX|
|
-- | OFFSET | + | PADDING | * |INDEX|
|
||||||
local h = ((200 / 4) + 4) + (skinPatch.height + 4) * (i - 1)
|
local h = ((200 / 4) + 4) + (skinPatch.height + 4) * (i - 1)
|
||||||
|
|
||||||
v.draw(4, h, skinPatch, V_HUDTRANS, v.getColormap("sonic", score["color"]))
|
v.draw(4, h, skinPatch, V_HUDTRANS | VFLAGS, v.getColormap("sonic", score["color"]))
|
||||||
if player.name == name then
|
if player.name == name then
|
||||||
v.draw(4, h, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS)
|
v.draw(4, h, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- SPB
|
-- SPB
|
||||||
@ -238,7 +321,7 @@ local function drawScoreboard(v, player)
|
|||||||
h - 2,
|
h - 2,
|
||||||
scale,
|
scale,
|
||||||
PATCH["SPB"],
|
PATCH["SPB"],
|
||||||
V_HUDTRANS
|
V_HUDTRANS | VFLAGS
|
||||||
)
|
)
|
||||||
if score["flags"] & F_SPBEXP then
|
if score["flags"] & F_SPBEXP then
|
||||||
drawitem(
|
drawitem(
|
||||||
@ -247,7 +330,7 @@ local function drawScoreboard(v, player)
|
|||||||
h - 2,
|
h - 2,
|
||||||
scale,
|
scale,
|
||||||
PATCH["INV"][(leveltime / 4) % 6],
|
PATCH["INV"][(leveltime / 4) % 6],
|
||||||
V_HUDTRANS
|
V_HUDTRANS | VFLAGS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if score["flags"] & F_SPBBIG then
|
if score["flags"] & F_SPBBIG then
|
||||||
@ -257,7 +340,7 @@ local function drawScoreboard(v, player)
|
|||||||
h + skinPatch.height - 4,
|
h + skinPatch.height - 4,
|
||||||
scale,
|
scale,
|
||||||
PATCH["BIG"],
|
PATCH["BIG"],
|
||||||
V_HUDTRANS
|
V_HUDTRANS | VFLAGS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if score["flags"] & F_SPBJUS then
|
if score["flags"] & F_SPBJUS then
|
||||||
@ -267,7 +350,7 @@ local function drawScoreboard(v, player)
|
|||||||
h + skinPatch.height - 4,
|
h + skinPatch.height - 4,
|
||||||
scale,
|
scale,
|
||||||
PATCH["HYUD"],
|
PATCH["HYUD"],
|
||||||
V_HUDTRANS
|
V_HUDTRANS | VFLAGS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -289,14 +372,30 @@ local function drawScoreboard(v, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
v.drawString(px + skinPatch.width, h + py, name, V_HUDTRANSHALF | V_ALLOWLOWERCASE, stralign)
|
v.drawString(
|
||||||
|
px + skinPatch.width,
|
||||||
|
h + py,
|
||||||
|
name,
|
||||||
|
V_HUDTRANSHALF | V_ALLOWLOWERCASE | VFLAGS,
|
||||||
|
stralign
|
||||||
|
)
|
||||||
|
|
||||||
-- Draw splits
|
-- Draw splits
|
||||||
if showSplit > 0 and score["splits"][prevLap] != nil then
|
if showSplit > 0 and score["splits"][prevLap] != nil then
|
||||||
local split = splits[prevLap] - score["splits"][prevLap]
|
local split = splits[prevLap] - score["splits"][prevLap]
|
||||||
v.drawString(px + skinPatch.width, h + 8, splitSymbol[split < 0] + ticsToTime(abs(split)), V_HUDTRANSHALF | splitColor[split < 0])
|
v.drawString(
|
||||||
|
px + skinPatch.width,
|
||||||
|
h + 8,
|
||||||
|
splitSymbol[split < 0] + ticsToTime(abs(split)),
|
||||||
|
V_HUDTRANSHALF | splitColor[split < 0] | VFLAGS
|
||||||
|
)
|
||||||
else
|
else
|
||||||
v.drawString(px + skinPatch.width, h + 8, ticsToTime(score["time"]), V_HUDTRANSHALF | bodium[min(i, 4)])
|
v.drawString(
|
||||||
|
px + skinPatch.width,
|
||||||
|
h + 8,
|
||||||
|
ticsToTime(score["time"]),
|
||||||
|
V_HUDTRANSHALF | bodium[min(i, 4)] | VFLAGS
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -419,17 +518,76 @@ 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 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
|
return
|
||||||
end
|
end
|
||||||
if showSplit > 0 then
|
if showSplit > 0 then
|
||||||
showSplit = showSplit - 1
|
showSplit = showSplit - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if leveltime < startTime then
|
local p = getGamer()
|
||||||
|
if leveltime < START_TIME then
|
||||||
|
-- Help message
|
||||||
|
if leveltime == START_TIME - TICRATE * 3 then
|
||||||
|
if ingame() == 1 then
|
||||||
|
if help then
|
||||||
|
help = false
|
||||||
|
chatprint("\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats", true)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
help = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Autospec
|
||||||
|
if leveltime == 1 then
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 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
|
||||||
@ -455,16 +613,44 @@ 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 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($)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user