7 Commits

Author SHA1 Message Date
Not
553afc606d add encore to help message 2022-04-05 12:12:32 +02:00
Not
c792dd1079 allow join on disable 2022-04-04 23:07:31 +02:00
Not
ee251b7a44 Add encore support 2022-04-04 20:58:35 +02:00
Not
0bde2a7fea add encore support 2022-04-04 20:56:03 +02:00
Not
c49702c33b create README.md 2022-03-28 13:27:11 +02:00
Not
6244847b81 fix ranking numbers x offset for 10, 100 2022-03-28 13:19:50 +02:00
Not
f53a6ba91f v1.2.17_hf 2022-03-28 13:16:00 +02:00
2 changed files with 50 additions and 8 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Leaderboard plugin for srb2kart
https://mb.srb2.org/addons/time-attack-leaderboard.3742/

View File

@ -13,13 +13,14 @@ local PATCH = nil
local help = true
local UNCLAIMED = "Unclaimed Record"
local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll"
local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore"
local FILENAME = "leaderboard.txt"
-- Retry / changelevel map
local nextMap = nil
local Flags = 0
local F_ENCORE = 0x80
-- SPB flags with the least significance first
local F_SPBATK = 0x1
@ -61,6 +62,8 @@ local clamp
local scroll_to
local ticsToTime
local allowJoin
---------------
local cv_gui = CV_RegisterVar({
@ -84,6 +87,9 @@ local cv_enable = CV_RegisterVar({
PossibleValue = CV_OnOff,
func = function(v)
disable = $ or not v.value
if disable then
allowJoin(true)
end
end
})
@ -121,7 +127,7 @@ local function getScoreTable(map, flags)
--return id
local mode = flags & F_SPBATK
return lb[mode] and lb[mode][map] or {}
return lb[mode] and lb[mode][map] or nil
end
local function score_t(map, name, skin, color, time, splits, flags, restat)
@ -171,7 +177,7 @@ if f then
flags = tonumber(t[7])
end
local scoreTable = getScoreTable(tonumber(t[1]), flags)
local scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
local spl = {}
if t[6] != nil then
@ -210,7 +216,7 @@ else
print("Failed to open file: ", FILENAME)
end
local function allowJoin(v)
function allowJoin(v)
if not cv_interrupt.value then
local y
if v then
@ -352,6 +358,20 @@ local function changelevel(player, ...)
end
COM_AddCommand("changelevel", changelevel)
local function toggleEncore(player)
if not doyoudare(player) then
return
end
local enc = CV_FindVar("kartencore")
if enc.value then
COM_BufInsertText(server, "kartencore off")
else
COM_BufInsertText(server, "kartencore on")
end
end
COM_AddCommand("encore", toggleEncore)
local function clearcheats(player)
if not player.spectator then
clearcheats = true
@ -616,12 +636,25 @@ local FACERANK_DIM = 16
local FACERANK_SPC = FACERANK_DIM + 4
local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, textVFlags)
textVFlags = textVFlags or V_HUDTRANSHALF
--draw Patch/chili
v.draw(x, y, faceRank, V_HUDTRANS | VFLAGS, v.getColormap("sonic", score["color"]))
if player.name == score["name"] then
v.draw(x, y, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
end
-- Encore
if score["flags"] & F_ENCORE then
local bob = sin((leveltime + i * 5) * (ANG10))
v.drawScaled(
x * FRACUNIT,
bob + (y + FACERANK_DIM / 2) * FRACUNIT,
FRACUNIT / 6,
PATCH["RUBY"],
V_HUDTRANS
)
end
-- SPB
if score["flags"] & F_SPBATK then
local scale = FRACUNIT / 4
@ -766,10 +799,10 @@ local function drawScroll(v, player, scoreTable, gui)
end
local x = 10
if #scoreTable > 10 then
if #scoreTable >= 10 then
x = x + 8
end
if #scoreTable > 100 then
if #scoreTable >= 100 then
x = x + 8
end
@ -850,6 +883,7 @@ function cachePatches(v)
end
PATCH["BIG"] = v.cachePatch("K_ISGROW")
PATCH["HYUD"] = v.cachePatch("K_ISHYUD")
PATCH["RUBY"] = v.cachePatch("RUBYICON")
end
end
@ -865,7 +899,7 @@ end
-- Find location of player and scroll to it
function scroll_to(player)
local m = getScoreTable(gamemap, Flags)
local m = getScoreTable(gamemap, Flags) or {}
scrollToPos = 2
for pos, score in ipairs(m) do
@ -879,7 +913,7 @@ function scroll_to(player)
end
local function saveTime(player)
local scoreTable = getScoreTable(gamemap, Flags)
local scoreTable = getScoreTable(gamemap, Flags) or {}
local newscore = score_t(
gamemap,
@ -1021,7 +1055,13 @@ local function think()
end
-- Autospec
-- Encore
if leveltime == 1 then
Flags = $ & !F_ENCORE
if encoremode then
Flags = $ | F_ENCORE
end
if p then
for s in players.iterate do
if s.valid and s.spectator then