forked from Not/srb2k-leaderboard
v1.2.15
This commit is contained in:
parent
70cd579079
commit
b040fdd933
108
leaderboard.lua
108
leaderboard.lua
@ -1,4 +1,5 @@
|
|||||||
-- Leaderboards written by Not
|
-- Leaderboards written by Not
|
||||||
|
-- Reusable
|
||||||
|
|
||||||
local FILENAME = "leaderboard.txt"
|
local FILENAME = "leaderboard.txt"
|
||||||
local lb = {}
|
local lb = {}
|
||||||
@ -27,9 +28,50 @@ local AFK_TIMEOUT = TICRATE * 5
|
|||||||
local AFK_BALANCE = TICRATE * 60
|
local AFK_BALANCE = TICRATE * 60
|
||||||
local PREVENT_JOIN_TIME = START_TIME + TICRATE * 5
|
local PREVENT_JOIN_TIME = START_TIME + TICRATE * 5
|
||||||
|
|
||||||
|
local GUI_OFF = 0x0
|
||||||
|
local GUI_SPLITS = 0x1
|
||||||
|
local GUI_ON = 0x2
|
||||||
|
|
||||||
-- patch caching function
|
-- patch caching function
|
||||||
local cachePatches
|
local cachePatches
|
||||||
|
|
||||||
|
local cv_gui = CV_RegisterVar({
|
||||||
|
name = "lb_gui",
|
||||||
|
defaultvalue = GUI_ON,
|
||||||
|
flags = 0,
|
||||||
|
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
|
||||||
|
})
|
||||||
|
|
||||||
|
local cv_afk = CV_RegisterVar({
|
||||||
|
name = "lb_afk",
|
||||||
|
defaultvalue = 1,
|
||||||
|
flags = CV_NETVAR,
|
||||||
|
PossibleValue = CV_OnOff
|
||||||
|
})
|
||||||
|
|
||||||
|
local cv_enable = CV_RegisterVar({
|
||||||
|
name = "lb_enable",
|
||||||
|
defaultvalue = 1,
|
||||||
|
flags = CV_NETVAR | CV_CALL,
|
||||||
|
PossibleValue = CV_OnOff,
|
||||||
|
func = function(v)
|
||||||
|
disable = $ or not v.value
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
local cv_interrupt = CV_RegisterVar({
|
||||||
|
name = "lb_interrupt",
|
||||||
|
defaultvalue = 0,
|
||||||
|
flags = CV_NETVAR | CV_CALL,
|
||||||
|
PossibleValue = CV_OnOff,
|
||||||
|
func = function(v)
|
||||||
|
if v.value then
|
||||||
|
COM_BufInsertText(server, "allowteamchange yes")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
local function lbID(map, flags)
|
local function lbID(map, flags)
|
||||||
local id = tostring(map)
|
local id = tostring(map)
|
||||||
if flags & F_SPBATK then
|
if flags & F_SPBATK then
|
||||||
@ -99,6 +141,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function allowJoin(v)
|
local function allowJoin(v)
|
||||||
|
if not cv_interrupt.value then
|
||||||
local y
|
local y
|
||||||
if v then
|
if v then
|
||||||
y = "yes"
|
y = "yes"
|
||||||
@ -110,6 +153,7 @@ local function allowJoin(v)
|
|||||||
|
|
||||||
COM_BufInsertText(server, "allowteamchange " + y)
|
COM_BufInsertText(server, "allowteamchange " + y)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function ingame()
|
local function ingame()
|
||||||
local n = 0
|
local n = 0
|
||||||
@ -127,7 +171,8 @@ local function initLeaderboard(player)
|
|||||||
else
|
else
|
||||||
disable = disable or ingame() > 1
|
disable = disable or ingame() > 1
|
||||||
end
|
end
|
||||||
player.afkTimeout = leveltime
|
disable = $ or not cv_enable.value
|
||||||
|
player.afkTime = leveltime
|
||||||
end
|
end
|
||||||
addHook("PlayerSpawn", initLeaderboard)
|
addHook("PlayerSpawn", initLeaderboard)
|
||||||
|
|
||||||
@ -157,6 +202,33 @@ local function exitlevel(player, ...)
|
|||||||
end
|
end
|
||||||
COM_AddCommand("exit", exitlevel)
|
COM_AddCommand("exit", exitlevel)
|
||||||
|
|
||||||
|
local function findMap(player, ...)
|
||||||
|
local search = ...
|
||||||
|
if search == nil then
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, #mapheaderinfo do
|
||||||
|
local map = mapheaderinfo[i]
|
||||||
|
if map == nil then
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
if map.lvlttl:lower():find(search:lower()) then
|
||||||
|
CONS_Printf(
|
||||||
|
player,
|
||||||
|
string.format(
|
||||||
|
"%s - %s",
|
||||||
|
G_BuildMapName(i),
|
||||||
|
map.lvlttl
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
COM_AddCommand("findmap", findMap)
|
||||||
|
|
||||||
local function mapNotExists(player, map)
|
local function mapNotExists(player, map)
|
||||||
CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper()))
|
CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper()))
|
||||||
end
|
end
|
||||||
@ -279,7 +351,9 @@ local function marquee(text, maxwidth)
|
|||||||
return text:sub(pos, pos + maxwidth - 1)
|
return text:sub(pos, pos + maxwidth - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Bats on ...
|
||||||
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
|
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
|
||||||
|
|
||||||
local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
|
local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
|
||||||
local splitSymbol = {[true]="-", [false]="+"}
|
local splitSymbol = {[true]="-", [false]="+"}
|
||||||
|
|
||||||
@ -296,6 +370,12 @@ local function drawScoreboard(v, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local gui = cv_gui.value
|
||||||
|
if leveltime < START_TIME or player.exiting or player.lives == 0 then
|
||||||
|
gui = GUI_ON
|
||||||
|
end
|
||||||
|
|
||||||
|
if gui then
|
||||||
for i, score in ipairs(m) do
|
for i, score in ipairs(m) do
|
||||||
local name = score["name"]
|
local name = score["name"]
|
||||||
local skin = skins[score["skin"]]
|
local skin = skins[score["skin"]]
|
||||||
@ -355,6 +435,7 @@ local function drawScoreboard(v, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if gui == GUI_ON or (gui == GUI_SPLITS and showSplit)
|
||||||
-- Shorten long names
|
-- Shorten long names
|
||||||
local stralign = "left"
|
local stralign = "left"
|
||||||
local MAXWIDTH = 70
|
local MAXWIDTH = 70
|
||||||
@ -381,7 +462,7 @@ local function drawScoreboard(v, player)
|
|||||||
)
|
)
|
||||||
|
|
||||||
-- Draw splits
|
-- Draw splits
|
||||||
if showSplit > 0 and score["splits"][prevLap] != nil then
|
if showSplit and score["splits"][prevLap] != nil then
|
||||||
local split = splits[prevLap] - score["splits"][prevLap]
|
local split = splits[prevLap] - score["splits"][prevLap]
|
||||||
v.drawString(
|
v.drawString(
|
||||||
px + skinPatch.width,
|
px + skinPatch.width,
|
||||||
@ -399,6 +480,8 @@ local function drawScoreboard(v, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
hud.add(drawScoreboard, "game")
|
hud.add(drawScoreboard, "game")
|
||||||
|
|
||||||
function cachePatches(v)
|
function cachePatches(v)
|
||||||
@ -533,13 +616,13 @@ local function think()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if disable then
|
if disable then
|
||||||
if ingame() > 1 then
|
if cv_afk.value and ingame() > 1 then
|
||||||
for p in players.iterate do
|
for p in players.iterate do
|
||||||
if p.valid and not p.spectator and not p.exiting then
|
if p.valid and not p.spectator and not p.exiting then
|
||||||
if p.cmd.buttons then
|
if p.cmd.buttons then
|
||||||
p.afkTimeout = leveltime
|
p.afkTime = leveltime
|
||||||
end
|
end
|
||||||
if p.afkTimeout + AFK_BALANCE < leveltime then
|
if p.afkTime + AFK_BALANCE < leveltime then
|
||||||
p.spectator = true
|
p.spectator = true
|
||||||
chatprint("\x89" + p.name + " was moved to the other team for game balance", true)
|
chatprint("\x89" + p.name + " was moved to the other team for game balance", true)
|
||||||
end
|
end
|
||||||
@ -548,7 +631,7 @@ local function think()
|
|||||||
else
|
else
|
||||||
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
|
||||||
p.afkTimeout = leveltime
|
p.afkTime = leveltime
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -567,7 +650,7 @@ local function think()
|
|||||||
if ingame() == 1 then
|
if ingame() == 1 then
|
||||||
if help then
|
if help then
|
||||||
help = false
|
help = false
|
||||||
chatprint("\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats", true)
|
chatprint("\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui", true)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
help = true
|
help = true
|
||||||
@ -611,19 +694,22 @@ local function think()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not (Flags & F_SPBATK) then
|
||||||
|
hud.enable("freeplay")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local cv_teamchange = CV_FindVar("allowteamchange")
|
local cv_teamchange = CV_FindVar("allowteamchange")
|
||||||
if p then
|
if p then
|
||||||
if p.cmd.buttons then
|
if p.cmd.buttons then
|
||||||
p.afkTimeout = leveltime
|
p.afkTime = leveltime
|
||||||
end
|
end
|
||||||
|
|
||||||
if leveltime > PREVENT_JOIN_TIME and p.afkTimeout + AFK_TIMEOUT > leveltime then
|
if leveltime > PREVENT_JOIN_TIME and p.afkTime + AFK_TIMEOUT > leveltime then
|
||||||
if cv_teamchange.value then
|
if cv_teamchange.value then
|
||||||
allowJoin(false)
|
allowJoin(false)
|
||||||
end
|
end
|
||||||
elseif p.afkTimeout + AFK_TIMEOUT < leveltime then
|
elseif p.afkTime + AFK_TIMEOUT < leveltime then
|
||||||
if not cv_teamchange.value then
|
if not cv_teamchange.value then
|
||||||
allowJoin(true)
|
allowJoin(true)
|
||||||
end
|
end
|
||||||
@ -653,5 +739,7 @@ addHook("IntermissionThinker", interThink)
|
|||||||
|
|
||||||
local function netvars(net)
|
local function netvars(net)
|
||||||
lb = net($)
|
lb = net($)
|
||||||
|
splits = net($)
|
||||||
|
prevLap = net($)
|
||||||
end
|
end
|
||||||
addHook("NetVars", netvars)
|
addHook("NetVars", netvars)
|
||||||
|
Loading…
Reference in New Issue
Block a user