Compare commits

..

6 Commits

Author SHA1 Message Date
Not
2e5c209a65 v1.2.10 2022-03-28 13:12:43 +02:00
Not
3101d29dcc v1.2.9 2022-03-28 13:12:16 +02:00
Not
36134572af v1.2.8 2022-03-28 13:11:51 +02:00
Not
bc002667c8 v1.2.7 2022-03-28 13:11:21 +02:00
Not
b0d5b5abeb v1.2.6 2022-03-28 13:11:00 +02:00
Not
18a81fab6d v1.2.5 2022-03-28 13:10:43 +02:00

View File

@ -3,10 +3,11 @@
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
local Flags = 0 local Flags = 0
@ -91,25 +92,27 @@ else
print("Failed to open file: ", FILENAME) print("Failed to open file: ", FILENAME)
end end
local function initLeaderboard(player) local function ingame()
local ingame = 0 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
disable = ingame > 1 end
if disable then local function initLeaderboard(player)
--print("To many players in game, leaderboard has been disabled") if disable and leveltime < startTime then
return disable = ingame() > 1
else
disable = disable or ingame() > 1
end end
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
@ -142,6 +145,11 @@ local function changelevel(player, ...)
end end
local map = ... local map = ...
if map == nil then
CONS_Printf(player, "Usage: changelevel MAPXX")
return
end
local p, q = map:upper():match("MAP(%w)(%w)$", 1) local p, q = map:upper():match("MAP(%w)(%w)$", 1)
if not (p and q) then if not (p and q) then
CONS_Printf(player, string.format("Invalid map name: %s", map)) CONS_Printf(player, string.format("Invalid map name: %s", map))
@ -159,7 +167,7 @@ local function changelevel(player, ...)
else else
--Extended map numbers --Extended map numbers
p = ALPH:find(p) - 1 p = ALPH:find(p) - 1
q = (tonumber(q) or ALPH:find(q) + 10) - 1 q = (tonumber(q) or ALPH:find(q) + 9)
mapnum = 36 * p + q + 100 mapnum = 36 * p + q + 100
end end
@ -247,6 +255,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
@ -269,9 +278,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
@ -283,7 +292,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(
@ -292,7 +301,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
@ -302,7 +311,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
@ -312,7 +321,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
@ -334,14 +343,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
@ -466,6 +491,7 @@ end
local function think() local function think()
if disable then if disable then
help = true
return return
end end
if showSplit > 0 then if showSplit > 0 then
@ -473,6 +499,36 @@ local function think()
end end
if leveltime < startTime then if leveltime < startTime then
-- Help message
if leveltime == startTime - 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
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))
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 > startTime - (3 * TICRATE) / 2 and server.SPBArunning then
Flags = $ | F_SPBATK Flags = $ | F_SPBATK