Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
db0696294b | |||
907c07a25d | |||
00aa2060f3 | |||
d7955feaf8 | |||
5a74a428b1 | |||
4f138797a9 | |||
22aa4ecd2f | |||
1305fa2979 | |||
13aeceeedd | |||
7b28cd0777 | |||
ec982d10c3 | |||
f3ec32384a | |||
07dca46c92 | |||
14645dbc90 | |||
6c7cdf34b9 | |||
23a8373230 | |||
14f8769d93 | |||
5080672f7a | |||
5790a3c020 | |||
e3c870eefd | |||
41b152ccf6 | |||
de63c4b2be |
378
leaderboard.lua
378
leaderboard.lua
@ -12,13 +12,30 @@ local splits = {}
|
|||||||
local PATCH = nil
|
local PATCH = nil
|
||||||
local help = true
|
local help = true
|
||||||
local EncoreInitial = nil
|
local EncoreInitial = nil
|
||||||
|
local cv_teamchange
|
||||||
|
local scoreTable
|
||||||
|
|
||||||
|
|
||||||
|
-- Text flash on finish
|
||||||
|
local FlashTics = 0
|
||||||
|
local FlashRate
|
||||||
|
local FlashVFlags
|
||||||
|
local YellowFlash = {
|
||||||
|
[0] = V_YELLOWMAP,
|
||||||
|
[1] = V_ORANGEMAP,
|
||||||
|
[2] = 0
|
||||||
|
}
|
||||||
|
local RedFlash = {
|
||||||
|
[0] = V_REDMAP,
|
||||||
|
[1] = 0
|
||||||
|
}
|
||||||
|
|
||||||
-- Tracks if stats have been written or not
|
-- Tracks if stats have been written or not
|
||||||
local StatTrack = false
|
local StatTrack = false
|
||||||
|
|
||||||
local UNCLAIMED = "Unclaimed Record"
|
local UNCLAIMED = "Unclaimed Record"
|
||||||
local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore"
|
local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore"
|
||||||
local FILENAME = "leaderboard.txt"
|
local FILENAME = "leaderboard"
|
||||||
|
|
||||||
-- Retry / changelevel map
|
-- Retry / changelevel map
|
||||||
local nextMap = nil
|
local nextMap = nil
|
||||||
@ -81,11 +98,24 @@ local cv_gui = CV_RegisterVar({
|
|||||||
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
|
PossibleValue = {Off = GUI_OFF, Splits = GUI_SPLITS, On = GUI_ON}
|
||||||
})
|
})
|
||||||
|
|
||||||
local cv_afk = CV_RegisterVar({
|
local AntiAFK = true
|
||||||
|
CV_RegisterVar({
|
||||||
name = "lb_afk",
|
name = "lb_afk",
|
||||||
defaultvalue = 1,
|
defaultvalue = 1,
|
||||||
flags = CV_NETVAR,
|
flags = CV_NETVAR | CV_CALL,
|
||||||
PossibleValue = CV_OnOff
|
PossibleValue = CV_OnOff,
|
||||||
|
func = function(v)
|
||||||
|
-- Set players afkTime and toggle AntiAFK
|
||||||
|
if v.value then
|
||||||
|
for p in players.iterate do
|
||||||
|
p.afkTime = leveltime
|
||||||
|
end
|
||||||
|
|
||||||
|
AntiAFK = true
|
||||||
|
else
|
||||||
|
AntiAFK = false
|
||||||
|
end
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
local cv_enable = CV_RegisterVar({
|
local cv_enable = CV_RegisterVar({
|
||||||
@ -120,15 +150,36 @@ local cv_interrupt = CV_RegisterVar({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function djb2(message)
|
||||||
|
local digest = 5381
|
||||||
|
for c in message:gmatch(".") do
|
||||||
|
digest = (($ << 5) + $) + string.byte(c)
|
||||||
|
end
|
||||||
|
|
||||||
|
return digest
|
||||||
|
end
|
||||||
|
|
||||||
|
local function mapChecksum(mapnum)
|
||||||
|
local mh = mapheaderinfo[mapnum]
|
||||||
|
if not mh then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local digest = string.format("%04x", djb2(mh.lvlttl+mh.subttl+mh.zonttl))
|
||||||
|
return string.sub(digest, #digest - 3)
|
||||||
|
end
|
||||||
|
|
||||||
local function setST(t, map, flags, scoreTable)
|
local function setST(t, map, flags, scoreTable)
|
||||||
local mode = flags & ST_SEP
|
local mode = flags & ST_SEP
|
||||||
|
local cks = mapChecksum(map)
|
||||||
t[mode] = t[mode] or {}
|
t[mode] = t[mode] or {}
|
||||||
t[mode][map] = scoreTable
|
t[mode][tostring(map)..(cks or "")] = scoreTable
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getST(t, map, flags)
|
local function getST(t, map, flags)
|
||||||
local mode = flags & ST_SEP
|
local mode = flags & ST_SEP
|
||||||
return t[mode] and t[mode][map] or nil
|
local cks = mapChecksum(map)
|
||||||
|
return t[mode] and t[mode][tostring(map)..(cks or "")] or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setScoreTable(map, flags, scoreTable)
|
local function setScoreTable(map, flags, scoreTable)
|
||||||
@ -192,7 +243,7 @@ local cv_spb_separate = CV_RegisterVar({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
local function score_t(map, name, skin, color, time, splits, flags, stat)
|
local function score_t(map, name, skin, color, time, splits, flags, stat, checksum)
|
||||||
return {
|
return {
|
||||||
["map"] = map,
|
["map"] = map,
|
||||||
["name"] = name,
|
["name"] = name,
|
||||||
@ -201,7 +252,8 @@ local function score_t(map, name, skin, color, time, splits, flags, stat)
|
|||||||
["time"] = time,
|
["time"] = time,
|
||||||
["splits"] = splits,
|
["splits"] = splits,
|
||||||
["flags"] = flags,
|
["flags"] = flags,
|
||||||
["stat"] = stat
|
["stat"] = stat,
|
||||||
|
["checksum"] = checksum
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -223,12 +275,47 @@ local function stat_str(stat)
|
|||||||
return "0"
|
return "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function writeScore(fh, score)
|
||||||
|
fh:write(
|
||||||
|
score["map"], "\t",
|
||||||
|
score["name"], "\t",
|
||||||
|
score["skin"], "\t",
|
||||||
|
score["color"], "\t",
|
||||||
|
score["time"], "\t",
|
||||||
|
table.concat(score["splits"], " "), "\t",
|
||||||
|
score["flags"], "\t",
|
||||||
|
stat_str(score["stat"]), "\t",
|
||||||
|
score["checksum"], "\n"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function saveScores()
|
||||||
|
local f = assert(io.open(FILENAME + ".txt", "w"))
|
||||||
|
if f == nil then
|
||||||
|
print("Failed to open file for writing: " + FILENAME + ".txt")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, tbl in pairs(lb) do
|
||||||
|
for _, scoreTable in pairs(tbl) do
|
||||||
|
for _, score in ipairs(scoreTable) do
|
||||||
|
writeScore(f, score)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
-- Read the leaderboard
|
-- Read the leaderboard
|
||||||
local f = io.open(FILENAME, "r")
|
local f = io.open(FILENAME + ".txt", "r")
|
||||||
if f then
|
if f then
|
||||||
|
-- track if scores checksums have been written
|
||||||
|
local checksumWrite = false
|
||||||
|
|
||||||
for l in f:lines() do
|
for l in f:lines() do
|
||||||
-- Leaderboard is stored in the following tab separated format
|
-- Leaderboard is stored in the following tab separated format
|
||||||
-- mapnum, name, skin, color, time, splits, flags, stat
|
-- mapnum, name, skin, color, time, splits, flags, stat, map_checksum
|
||||||
local t = {}
|
local t = {}
|
||||||
for word in (l+"\t"):gmatch("(.-)\t") do
|
for word in (l+"\t"):gmatch("(.-)\t") do
|
||||||
table.insert(t, word)
|
table.insert(t, word)
|
||||||
@ -239,7 +326,7 @@ if f then
|
|||||||
flags = tonumber(t[7])
|
flags = tonumber(t[7])
|
||||||
end
|
end
|
||||||
|
|
||||||
local scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
||||||
|
|
||||||
local spl = {}
|
local spl = {}
|
||||||
if t[6] != nil then
|
if t[6] != nil then
|
||||||
@ -257,17 +344,41 @@ if f then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mapnum = tonumber(t[1])
|
||||||
|
|
||||||
|
-- Checksums
|
||||||
|
local cks = t[9]
|
||||||
|
|
||||||
|
if cks == nil then
|
||||||
|
checksumWrite = true
|
||||||
|
cks = mapChecksum(mapnum)
|
||||||
|
|
||||||
|
-- We have no previous recognition of this map
|
||||||
|
-- remove it
|
||||||
|
if cks == nil then
|
||||||
|
local rsfh = io.open(FILENAME + "_removed_scores.txt", "a")
|
||||||
|
if not rsfh then
|
||||||
|
print("Failed to open file: ", FILENAME + "_removed_scores.txt")
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
rsfh:write(l, "\n")
|
||||||
|
rsfh:close()
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(
|
table.insert(
|
||||||
scoreTable,
|
scoreTable,
|
||||||
score_t(
|
score_t(
|
||||||
tonumber(t[1]),
|
mapnum,
|
||||||
t[2],
|
t[2],
|
||||||
t[3],
|
t[3],
|
||||||
t[4],
|
t[4],
|
||||||
tonumber(t[5]),
|
tonumber(t[5]),
|
||||||
spl,
|
spl,
|
||||||
flags,
|
flags,
|
||||||
stats
|
stats,
|
||||||
|
cks
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -276,8 +387,13 @@ if f then
|
|||||||
|
|
||||||
sortScores()
|
sortScores()
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
|
-- save scores
|
||||||
|
if checksumWrite then
|
||||||
|
saveScores()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
print("Failed to open file: ", FILENAME)
|
print("Failed to open file: ", FILENAME + ".txt")
|
||||||
end
|
end
|
||||||
|
|
||||||
function allowJoin(v)
|
function allowJoin(v)
|
||||||
@ -295,23 +411,27 @@ function allowJoin(v)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ingame()
|
-- Returns true if there is a single player ingame
|
||||||
|
local function singleplayer()
|
||||||
local n = 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
|
||||||
n = $ + 1
|
n = $ + 1
|
||||||
|
if n > 1 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return n
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function initLeaderboard(player)
|
local function initLeaderboard(player)
|
||||||
if disable and leveltime < START_TIME then
|
if disable and leveltime < START_TIME then
|
||||||
disable = ingame() > 1
|
disable = not singleplayer()
|
||||||
else
|
else
|
||||||
disable = disable or ingame() > 1
|
disable = disable or not singleplayer()
|
||||||
end
|
end
|
||||||
disable = $ or not cv_enable.value
|
disable = $ or not cv_enable.value or not (maptol & (TOL_SP | TOL_RACE))
|
||||||
|
|
||||||
-- Restore encore mode to initial value
|
-- Restore encore mode to initial value
|
||||||
if disable and EncoreInitial != nil then
|
if disable and EncoreInitial != nil then
|
||||||
@ -324,7 +444,7 @@ end
|
|||||||
addHook("PlayerSpawn", initLeaderboard)
|
addHook("PlayerSpawn", initLeaderboard)
|
||||||
|
|
||||||
local function doyoudare(player)
|
local function doyoudare(player)
|
||||||
if ingame() > 1 or player.spectator then
|
if not singleplayer() or player.spectator then
|
||||||
CONS_Printf(player, "How dare you")
|
CONS_Printf(player, "How dare you")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -351,24 +471,57 @@ COM_AddCommand("exit", exitlevel)
|
|||||||
|
|
||||||
local function findMap(player, ...)
|
local function findMap(player, ...)
|
||||||
local search = ...
|
local search = ...
|
||||||
if search == nil then
|
|
||||||
|
|
||||||
return
|
local hell = "\x85HELL"
|
||||||
|
local tol = {
|
||||||
|
[TOL_SP] = "\x81Race\x80", -- Nuked race maps
|
||||||
|
[TOL_COOP] = "\x8D\Battle\x80", -- Nuked battle maps
|
||||||
|
[TOL_RACE] = "\x88Race\x80",
|
||||||
|
[TOL_MATCH] = "\x87\Battle\x80"
|
||||||
|
}
|
||||||
|
local lvltype, map, lvlttl
|
||||||
|
|
||||||
|
local zoneAct = function(zone, act, levelflags)
|
||||||
|
local z = ""
|
||||||
|
if zone != "" then
|
||||||
|
z = " " + zone
|
||||||
|
elseif not(levelflags & LF_NOZONE) then
|
||||||
|
z = " Zone"
|
||||||
|
end
|
||||||
|
if act != "" then
|
||||||
|
z = $ + " " + act
|
||||||
|
end
|
||||||
|
|
||||||
|
return z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
for i = 1, #mapheaderinfo do
|
for i = 1, #mapheaderinfo do
|
||||||
local map = mapheaderinfo[i]
|
map = mapheaderinfo[i]
|
||||||
if map == nil then
|
if map == nil then
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
if map.lvlttl:lower():find(search:lower()) then
|
lvlttl = map.lvlttl + zoneAct(map.zonttl, map.actnum, map.levelflags)
|
||||||
|
|
||||||
|
if not search or lvlttl:lower():find(search:lower()) then
|
||||||
|
-- Only care for up to TOL_MATCH (0x10)
|
||||||
|
lvltype = tol[map.typeoflevel & 0x1F] or map.typeoflevel
|
||||||
|
|
||||||
|
-- If not battle print numlaps
|
||||||
|
lvltype = (map.typeoflevel & (TOL_MATCH | TOL_COOP) and lvltype)
|
||||||
|
or string.format("%s \x82%-2d\x80", lvltype, map.numlaps)
|
||||||
|
|
||||||
|
|
||||||
CONS_Printf(
|
CONS_Printf(
|
||||||
player,
|
player,
|
||||||
string.format(
|
string.format(
|
||||||
"%s - %s",
|
"%s %-9s %-30s - %s\t%s",
|
||||||
G_BuildMapName(i),
|
G_BuildMapName(i),
|
||||||
map.lvlttl
|
lvltype,
|
||||||
|
lvlttl,
|
||||||
|
map.subttl,
|
||||||
|
(map.menuflags & LF2_HIDEINMENU and hell) or ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -380,8 +533,6 @@ 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
|
||||||
|
|
||||||
local ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
||||||
|
|
||||||
local function changelevel(player, ...)
|
local function changelevel(player, ...)
|
||||||
if not doyoudare(player) then
|
if not doyoudare(player) then
|
||||||
return
|
return
|
||||||
@ -403,6 +554,8 @@ local function changelevel(player, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local mapnum = 0
|
local mapnum = 0
|
||||||
|
local A = string.byte("A")
|
||||||
|
|
||||||
if tonumber(p) != nil then
|
if tonumber(p) != nil then
|
||||||
-- Non extended map numbers
|
-- Non extended map numbers
|
||||||
if tonumber(q) == nil then
|
if tonumber(q) == nil then
|
||||||
@ -412,11 +565,12 @@ local function changelevel(player, ...)
|
|||||||
mapnum = tonumber(p) * 10 + tonumber(q)
|
mapnum = tonumber(p) * 10 + tonumber(q)
|
||||||
else
|
else
|
||||||
--Extended map numbers
|
--Extended map numbers
|
||||||
p = ALPH:find(p) - 1
|
p = string.byte(p) - A
|
||||||
local qn = tonumber(q)
|
local qn = tonumber(q)
|
||||||
if qn == nil then
|
if qn == nil then
|
||||||
qn = ALPH:find(q) + 9
|
qn = string.byte(q) - A + 10
|
||||||
end
|
end
|
||||||
|
|
||||||
mapnum = 36 * p + qn + 100
|
mapnum = 36 * p + qn + 100
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -425,6 +579,12 @@ local function changelevel(player, ...)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Verify valid race level
|
||||||
|
if not (mapheaderinfo[mapnum].typeoflevel & (TOL_SP | TOL_RACE)) then
|
||||||
|
CONS_Printf(player, "Battle maps are not supported")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
nextMap = G_BuildMapName(mapnum)
|
nextMap = G_BuildMapName(mapnum)
|
||||||
end
|
end
|
||||||
COM_AddCommand("changelevel", changelevel)
|
COM_AddCommand("changelevel", changelevel)
|
||||||
@ -647,6 +807,7 @@ addHook("MapLoad", function()
|
|||||||
drawState = DS_DEFAULT
|
drawState = DS_DEFAULT
|
||||||
scrollY = 50 * FRACUNIT
|
scrollY = 50 * FRACUNIT
|
||||||
scrollAcc = 0
|
scrollAcc = 0
|
||||||
|
FlashTics = 0
|
||||||
|
|
||||||
allowJoin(true)
|
allowJoin(true)
|
||||||
--printTable(lb)
|
--printTable(lb)
|
||||||
@ -660,7 +821,7 @@ function ticsToTime(tics, pure)
|
|||||||
|
|
||||||
return string.format(
|
return string.format(
|
||||||
"%d:%02d:%02d",
|
"%d:%02d:%02d",
|
||||||
G_TicsToMinutes(tics),
|
G_TicsToMinutes(tics, true),
|
||||||
G_TicsToSeconds(tics),
|
G_TicsToSeconds(tics),
|
||||||
G_TicsToCentiseconds(tics)
|
G_TicsToCentiseconds(tics)
|
||||||
)
|
)
|
||||||
@ -739,10 +900,11 @@ local FACERANK_DIM = 16
|
|||||||
local FACERANK_SPC = FACERANK_DIM + 4
|
local FACERANK_SPC = FACERANK_DIM + 4
|
||||||
local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, textVFlags)
|
local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, textVFlags)
|
||||||
textVFlags = textVFlags or V_HUDTRANSHALF
|
textVFlags = textVFlags or V_HUDTRANSHALF
|
||||||
|
local me = player.name == score["name"]
|
||||||
|
|
||||||
--draw Patch/chili
|
--draw Patch/chili
|
||||||
v.draw(x, y, faceRank, V_HUDTRANS | VFLAGS, v.getColormap("sonic", score["color"]))
|
v.draw(x, y, faceRank, V_HUDTRANS | VFLAGS, v.getColormap("sonic", score["color"]))
|
||||||
if player.name == score["name"] then
|
if me then
|
||||||
v.draw(x, y, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
|
v.draw(x, y, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -754,7 +916,7 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
|
|||||||
bob + (y + FACERANK_DIM / 2) * FRACUNIT,
|
bob + (y + FACERANK_DIM / 2) * FRACUNIT,
|
||||||
FRACUNIT / 6,
|
FRACUNIT / 6,
|
||||||
PATCH["RUBY"],
|
PATCH["RUBY"],
|
||||||
V_HUDTRANS
|
V_HUDTRANS | VFLAGS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -838,11 +1000,16 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local flashV = 0
|
||||||
|
if me and FlashTics > leveltime then
|
||||||
|
flashV = FlashVFlags[leveltime / FlashRate % (#FlashVFlags + 1)]
|
||||||
|
end
|
||||||
|
|
||||||
v.drawString(
|
v.drawString(
|
||||||
x + FACERANK_DIM + px,
|
x + FACERANK_DIM + px,
|
||||||
y + py,
|
y + py,
|
||||||
name,
|
name,
|
||||||
textVFlags | V_ALLOWLOWERCASE | VFLAGS,
|
textVFlags | V_ALLOWLOWERCASE | VFLAGS | flashV,
|
||||||
stralign
|
stralign
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -860,7 +1027,7 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
|
|||||||
x + px + FACERANK_DIM,
|
x + px + FACERANK_DIM,
|
||||||
y + 8,
|
y + 8,
|
||||||
ticsToTime(score["time"], true),
|
ticsToTime(score["time"], true),
|
||||||
textVFlags | bodium[min(pos, 4)] | VFLAGS
|
textVFlags | bodium[min(pos, 4)] | VFLAGS | flashV
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -907,9 +1074,9 @@ local function drawScroll(v, player, scoreTable, gui)
|
|||||||
local x = 10
|
local x = 10
|
||||||
if #scoreTable >= 10 then
|
if #scoreTable >= 10 then
|
||||||
x = x + 8
|
x = x + 8
|
||||||
end
|
if #scoreTable >= 100 then
|
||||||
if #scoreTable >= 100 then
|
x = x + 8
|
||||||
x = x + 8
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local y = FixedInt(scrollY)
|
local y = FixedInt(scrollY)
|
||||||
@ -961,8 +1128,6 @@ local function drawScoreboard(v, player)
|
|||||||
|
|
||||||
cachePatches(v)
|
cachePatches(v)
|
||||||
|
|
||||||
local scoreTable = getScoreTable(gamemap, Flags)
|
|
||||||
|
|
||||||
local gui = cv_gui.value
|
local gui = cv_gui.value
|
||||||
if leveltime < START_TIME or player.exiting or player.lives == 0 then
|
if leveltime < START_TIME or player.exiting or player.lives == 0 then
|
||||||
gui = GUI_ON
|
gui = GUI_ON
|
||||||
@ -1009,7 +1174,7 @@ end
|
|||||||
|
|
||||||
-- Find location of player and scroll to it
|
-- Find location of player and scroll to it
|
||||||
function scroll_to(player)
|
function scroll_to(player)
|
||||||
local m = getScoreTable(gamemap, Flags) or {}
|
local m = scoreTable or {}
|
||||||
|
|
||||||
scrollToPos = 2
|
scrollToPos = 2
|
||||||
for pos, score in ipairs(m) do
|
for pos, score in ipairs(m) do
|
||||||
@ -1038,7 +1203,8 @@ local function writeStats()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function saveTime(player)
|
local function saveTime(player)
|
||||||
local scoreTable = getScoreTable(gamemap, Flags) or {}
|
|
||||||
|
scoreTable = $ or {}
|
||||||
|
|
||||||
local pskin = skins[player.mo.skin]
|
local pskin = skins[player.mo.skin]
|
||||||
local newscore = score_t(
|
local newscore = score_t(
|
||||||
@ -1049,7 +1215,8 @@ local function saveTime(player)
|
|||||||
timeFinished,
|
timeFinished,
|
||||||
splits,
|
splits,
|
||||||
Flags,
|
Flags,
|
||||||
stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight)
|
stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight),
|
||||||
|
mapChecksum(gamemap)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Check if you beat your previous best
|
-- Check if you beat your previous best
|
||||||
@ -1058,10 +1225,16 @@ local function saveTime(player)
|
|||||||
if lbComp(newscore, scoreTable[i]) then
|
if lbComp(newscore, scoreTable[i]) then
|
||||||
table.remove(scoreTable, i)
|
table.remove(scoreTable, i)
|
||||||
S_StartSound(nil, 130)
|
S_StartSound(nil, 130)
|
||||||
|
FlashTics = leveltime + TICRATE * 3
|
||||||
|
FlashRate = 1
|
||||||
|
FlashVFlags = YellowFlash
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
-- You suck lol
|
-- You suck lol
|
||||||
S_StartSound(nil, 201)
|
S_StartSound(nil, 201)
|
||||||
|
FlashTics = leveltime + TICRATE * 3
|
||||||
|
FlashRate = 3
|
||||||
|
FlashVFlags = RedFlash
|
||||||
scroll_to(player)
|
scroll_to(player)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -1088,30 +1261,7 @@ local function saveTime(player)
|
|||||||
StatTrack = true
|
StatTrack = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = assert(io.open(FILENAME, "w"))
|
saveScores()
|
||||||
if f == nil then
|
|
||||||
print("Failed to open file for writing: " + FILENAME)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, tbl in pairs(lb) do
|
|
||||||
for _, scoreTable in pairs(tbl) do
|
|
||||||
for _, score in ipairs(scoreTable) do
|
|
||||||
f:write(
|
|
||||||
score["map"], "\t",
|
|
||||||
score["name"], "\t",
|
|
||||||
score["skin"], "\t",
|
|
||||||
score["color"], "\t",
|
|
||||||
score["time"], "\t",
|
|
||||||
table.concat(score["splits"], " "), "\t",
|
|
||||||
score["flags"], "\t",
|
|
||||||
stat_str(score["stat"]), "\n"
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
f:close()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DEBUGGING
|
-- DEBUGGING
|
||||||
@ -1138,35 +1288,39 @@ local function getGamer()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function changeMap()
|
||||||
|
COM_BufInsertText(server, "map " + nextMap + " -force -gametype race")
|
||||||
|
nextMap = nil
|
||||||
|
end
|
||||||
|
|
||||||
local function think()
|
local function think()
|
||||||
if nextMap then
|
if nextMap then changeMap() end
|
||||||
COM_BufInsertText(server, "map " + nextMap)
|
|
||||||
nextMap = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if disable then
|
if disable then
|
||||||
if cv_afk.value and ingame() > 1 then
|
if AntiAFK then
|
||||||
for p in players.iterate do
|
if not singleplayer() then
|
||||||
if p.valid and not p.spectator and not p.exiting and p.lives > 0 then
|
for p in players.iterate do
|
||||||
if p.cmd.buttons then
|
if p.valid and not p.spectator and not p.exiting and p.lives > 0 then
|
||||||
p.afkTime = leveltime
|
if p.cmd.buttons then
|
||||||
end
|
p.afkTime = leveltime
|
||||||
|
end
|
||||||
|
|
||||||
--Away from kart
|
--Away from kart
|
||||||
if p.afkTime + AFK_BALANCE_WARN == leveltime then
|
if p.afkTime + AFK_BALANCE_WARN == leveltime then
|
||||||
chatprintf(p, "[AFK] \x89You will be moved to spectator in 10 seconds!", false)
|
chatprintf(p, "[AFK] \x89You will be moved to spectator in 10 seconds!", false)
|
||||||
S_StartSound(nil, 26, p)
|
S_StartSound(nil, 26, p)
|
||||||
end
|
end
|
||||||
if p.afkTime + 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
|
end
|
||||||
end
|
end
|
||||||
end
|
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.afkTime = leveltime
|
||||||
p.afkTime = leveltime
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1181,7 +1335,7 @@ local function think()
|
|||||||
if leveltime < START_TIME then
|
if leveltime < START_TIME then
|
||||||
-- Help message
|
-- Help message
|
||||||
if leveltime == START_TIME - TICRATE * 3 then
|
if leveltime == START_TIME - TICRATE * 3 then
|
||||||
if ingame() == 1 then
|
if singleplayer() then
|
||||||
if help then
|
if help then
|
||||||
help = false
|
help = false
|
||||||
chatprint(HELP_MESSAGE, true)
|
chatprint(HELP_MESSAGE, true)
|
||||||
@ -1217,29 +1371,34 @@ local function think()
|
|||||||
end
|
end
|
||||||
if clearcheats then
|
if clearcheats then
|
||||||
clearcheats = false
|
clearcheats = false
|
||||||
for p in players.iterate do
|
for q in players.iterate do
|
||||||
p.SPBAKARTBIG = false
|
q.SPBAKARTBIG = false
|
||||||
p.SPBAjustice = false
|
q.SPBAjustice = false
|
||||||
p.SPBAshutup = false
|
q.SPBAshutup = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for p in players.iterate do
|
|
||||||
if not p.spectator then
|
if p then
|
||||||
if p.SPBAKARTBIG then
|
if p.SPBAKARTBIG then
|
||||||
Flags = $ | F_SPBBIG
|
Flags = $ | F_SPBBIG
|
||||||
end
|
end
|
||||||
if p.SPBAjustice then
|
if p.SPBAjustice then
|
||||||
Flags = $ | F_SPBJUS
|
Flags = $ | F_SPBJUS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
if not (Flags & F_SPBATK) then
|
if not (Flags & F_SPBATK) then
|
||||||
hud.enable("freeplay")
|
hud.enable("freeplay")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local cv_teamchange = CV_FindVar("allowteamchange")
|
scoreTable = getScoreTable(gamemap, Flags)
|
||||||
|
|
||||||
|
if not cv_teamchange then
|
||||||
|
cv_teamchange = CV_FindVar("allowteamchange")
|
||||||
|
end
|
||||||
|
|
||||||
if p then
|
if p then
|
||||||
-- Scroll controller
|
-- Scroll controller
|
||||||
-- Spectators can't input buttons so let the gamer do it
|
-- Spectators can't input buttons so let the gamer do it
|
||||||
@ -1288,15 +1447,18 @@ end
|
|||||||
addHook("ThinkFrame", think)
|
addHook("ThinkFrame", think)
|
||||||
|
|
||||||
local function interThink()
|
local function interThink()
|
||||||
if nextMap then
|
if nextMap then changeMap() end
|
||||||
COM_BufInsertText(server, "map " + nextMap)
|
|
||||||
nextMap = nil
|
if not cv_teamchange then
|
||||||
|
cv_teamchange = CV_FindVar("allowteamchange")
|
||||||
end
|
end
|
||||||
if not CV_FindVar("allowteamchange").value then
|
|
||||||
|
if not cv_teamchange.value then
|
||||||
allowJoin(true)
|
allowJoin(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
addHook("IntermissionThinker", interThink)
|
addHook("IntermissionThinker", interThink)
|
||||||
|
addHook("VoteThinker", interThink)
|
||||||
|
|
||||||
-- Returns the values clamed between min, max
|
-- Returns the values clamed between min, max
|
||||||
function clamp(min_v, v, max_v)
|
function clamp(min_v, v, max_v)
|
||||||
|
Reference in New Issue
Block a user