Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
3101d29dcc | |||
36134572af | |||
bc002667c8 | |||
b0d5b5abeb | |||
18a81fab6d | |||
9a1fb0677a | |||
321ff7737c |
160
leaderboard.lua
160
leaderboard.lua
@ -7,6 +7,7 @@ local disable = true
|
||||
local prevLap = 0
|
||||
local splits = {}
|
||||
local PATCH = nil
|
||||
local help = true
|
||||
|
||||
local Flags = 0
|
||||
|
||||
@ -91,42 +92,90 @@ 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
|
||||
|
||||
disable = ingame > 1
|
||||
return n
|
||||
end
|
||||
|
||||
if disable then
|
||||
--print("To many players in game, leaderboard has been disabled")
|
||||
return
|
||||
end
|
||||
local function initLeaderboard(player)
|
||||
disable = ingame() > 1
|
||||
end
|
||||
addHook("PlayerSpawn", initLeaderboard)
|
||||
|
||||
local function retry(player, ...)
|
||||
local function doyoudare(player)
|
||||
if disable or player.spectator then
|
||||
CONS_Printf(player, "How dare you")
|
||||
return
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
||||
local function retry(player, ...)
|
||||
if doyoudare(player) then
|
||||
COM_BufInsertText(server, "map " + G_BuildMapName(gamemap))
|
||||
end
|
||||
end
|
||||
COM_AddCommand("retry", retry)
|
||||
|
||||
local function exitlevel(player, ...)
|
||||
if disable or player.spectator then
|
||||
CONS_Printf(player, "How dare you")
|
||||
return
|
||||
if doyoudare(player) then
|
||||
G_ExitLevel()
|
||||
end
|
||||
G_ExitLevel()
|
||||
end
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
COM_BufInsertText(server, "map " + (G_BuildMapName(mapnum)))
|
||||
end
|
||||
COM_AddCommand("changelevel", changelevel)
|
||||
|
||||
local function clearcheats(player)
|
||||
if not player.spectator then
|
||||
clearcheats = true
|
||||
@ -186,11 +235,23 @@ local function drawitem(v, x, y, scale, itempatch, vflags)
|
||||
)
|
||||
end
|
||||
|
||||
local function marquee(text, maxwidth)
|
||||
if #text <= maxwidth then
|
||||
return text
|
||||
end
|
||||
|
||||
local shift = 16
|
||||
local pos = ((leveltime / 16) % (#text - maxwidth + shift * 2)) + 1 - shift
|
||||
pos = min(max(pos, 1), #text - maxwidth + 1)
|
||||
return text:sub(pos, pos + maxwidth - 1)
|
||||
end
|
||||
|
||||
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
|
||||
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
|
||||
@ -213,9 +274,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
|
||||
@ -227,7 +288,7 @@ local function drawScoreboard(v, player)
|
||||
h - 2,
|
||||
scale,
|
||||
PATCH["SPB"],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
if score["flags"] & F_SPBEXP then
|
||||
drawitem(
|
||||
@ -236,7 +297,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
|
||||
@ -246,7 +307,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
|
||||
@ -256,7 +317,7 @@ local function drawScoreboard(v, player)
|
||||
h + skinPatch.height - 4,
|
||||
scale,
|
||||
PATCH["HYUD"],
|
||||
V_HUDTRANS
|
||||
V_HUDTRANS | VFLAGS
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -273,19 +334,35 @@ local function drawScoreboard(v, player)
|
||||
stralign = "small"
|
||||
py = 2
|
||||
if v.stringWidth(name, 0, "small") > MAXWIDTH then
|
||||
name = name:sub(0, 15) + "..."
|
||||
name = marquee(name, 15)
|
||||
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
|
||||
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
|
||||
@ -410,6 +487,7 @@ end
|
||||
|
||||
local function think()
|
||||
if disable then
|
||||
help = true
|
||||
return
|
||||
end
|
||||
if showSplit > 0 then
|
||||
@ -417,6 +495,36 @@ local function think()
|
||||
end
|
||||
|
||||
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)
|
||||
if leveltime > startTime - (3 * TICRATE) / 2 and server.SPBArunning then
|
||||
Flags = $ | F_SPBATK
|
||||
|
Reference in New Issue
Block a user