forked from Not/srb2k-leaderboard
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
017794c554 | |||
2e5c209a65 | |||
3101d29dcc | |||
36134572af | |||
bc002667c8 |
@ -3,7 +3,7 @@
|
||||
local FILENAME = "leaderboard.txt"
|
||||
local lb = {}
|
||||
local timeFinished = 0
|
||||
local disable = true
|
||||
local disable = false
|
||||
local prevLap = 0
|
||||
local splits = {}
|
||||
local PATCH = nil
|
||||
@ -92,26 +92,27 @@ else
|
||||
print("Failed to open file: ", FILENAME)
|
||||
end
|
||||
|
||||
local function initLeaderboard(player)
|
||||
local ingame = 0
|
||||
local function ingame()
|
||||
local n = 0
|
||||
for p in players.iterate do
|
||||
if p.valid and not p.spectator then
|
||||
ingame = ingame + 1
|
||||
n = $ + 1
|
||||
end
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
disable = ingame > 1
|
||||
|
||||
if disable or ingame == 0 then
|
||||
-- Print the help message next time someone is alone
|
||||
help = true
|
||||
return
|
||||
local function initLeaderboard(player)
|
||||
if disable and leveltime < startTime then
|
||||
disable = ingame() > 1
|
||||
else
|
||||
disable = disable or ingame() > 1
|
||||
end
|
||||
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
|
||||
@ -120,6 +121,10 @@ end
|
||||
|
||||
local function retry(player, ...)
|
||||
if doyoudare(player) then
|
||||
-- Prevents bind crash
|
||||
if leveltime < 15 then
|
||||
return
|
||||
end
|
||||
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
||||
end
|
||||
end
|
||||
@ -142,6 +147,9 @@ local function changelevel(player, ...)
|
||||
if not doyoudare(player) then
|
||||
return
|
||||
end
|
||||
if leveltime < 15 then
|
||||
return
|
||||
end
|
||||
|
||||
local map = ...
|
||||
if map == nil then
|
||||
@ -254,6 +262,7 @@ local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
|
||||
local splitSymbol = {[true]="-", [false]="+"}
|
||||
|
||||
local showSplit = 0
|
||||
local VFLAGS = V_SNAPTOLEFT
|
||||
local function drawScoreboard(v, player)
|
||||
if disable then return end
|
||||
if player != displayplayers[0] then return end
|
||||
@ -276,9 +285,9 @@ local function drawScoreboard(v, player)
|
||||
-- | OFFSET | + | PADDING | * |INDEX|
|
||||
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
|
||||
v.draw(4, h, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS)
|
||||
v.draw(4, h, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
|
||||
end
|
||||
|
||||
-- SPB
|
||||
@ -290,7 +299,7 @@ local function drawScoreboard(v, player)
|
||||
h - 2,
|
||||
scale,
|
||||
PATCH["SPB"],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
if score["flags"] & F_SPBEXP then
|
||||
drawitem(
|
||||
@ -299,7 +308,7 @@ local function drawScoreboard(v, player)
|
||||
h - 2,
|
||||
scale,
|
||||
PATCH["INV"][(leveltime / 4) % 6],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
end
|
||||
if score["flags"] & F_SPBBIG then
|
||||
@ -309,7 +318,7 @@ local function drawScoreboard(v, player)
|
||||
h + skinPatch.height - 4,
|
||||
scale,
|
||||
PATCH["BIG"],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
end
|
||||
if score["flags"] & F_SPBJUS then
|
||||
@ -319,7 +328,7 @@ local function drawScoreboard(v, player)
|
||||
h + skinPatch.height - 4,
|
||||
scale,
|
||||
PATCH["HYUD"],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -341,14 +350,30 @@ local function drawScoreboard(v, player)
|
||||
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
|
||||
if showSplit > 0 and score["splits"][prevLap] != nil then
|
||||
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
|
||||
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
|
||||
@ -473,6 +498,7 @@ end
|
||||
|
||||
local function think()
|
||||
if disable then
|
||||
help = true
|
||||
return
|
||||
end
|
||||
if showSplit > 0 then
|
||||
@ -481,11 +507,35 @@ local function think()
|
||||
|
||||
if leveltime < startTime then
|
||||
-- Help message
|
||||
if help and leveltime == startTime - TICRATE * 3 then
|
||||
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)
|
||||
if leveltime > startTime - (3 * TICRATE) / 2 and server.SPBArunning then
|
||||
Flags = $ | F_SPBATK
|
||||
|
Reference in New Issue
Block a user