fix 'rival' command

This commit is contained in:
Not 2022-10-07 17:59:27 +02:00
parent 7bd8a13b14
commit 107a81f67c
2 changed files with 50 additions and 22 deletions

View File

@ -18,6 +18,27 @@ local ColdStore = {}
local LiveStore = {}
-- GLOBAL
-- Returns a list of all maps with records
local function MapList()
local maps = {}
for map in pairs(ColdStore) do
maps[map] = true
end
for map in pairs(LiveStore) do
maps[map] = true
end
local maplist = {}
for map in pairs(maps) do
table.insert(maplist, map)
end
table.sort(maplist)
return maplist
end
rawset(_G, "lb_map_list", MapList)
-- GLOBAL
-- Function for adding records from lua
local function AddColdStore(record)

View File

@ -104,6 +104,7 @@ local BrowserController = BrowserController
-- lb_store.lua
local GetMapRecords = lb_get_map_records
local SaveRecord = lb_save_record
local MapList = lb_map_list
---------------
-- cvars
@ -396,6 +397,7 @@ end
local function records(player, ...)
local mapid = ...
local mapnum = gamemap
local mapRecords = MapRecords
if mapid then
mapnum = mapnumFromExtended(mapid)
@ -403,6 +405,8 @@ local function records(player, ...)
CONS_Printf(player, string.format("Invalid map name: %s", mapid))
return
end
mapRecords = GetMapRecords(mapnum, ST_SEP)
end
local map = mapheaderinfo[mapnum]
@ -430,35 +434,33 @@ local function records(player, ...)
CONS_Printf(player, "\x85UNKNOWN MAP")
end
for mode, maps in pairs(lb) do
local maptbl = maps[mapnum]
if not maptbl then continue end
for mode, records in pairs(mapRecords) do
CONS_Printf(player, "")
CONS_Printf(player, modeToString(mode))
-- don't print flags for time attack
if mode then
for i, tbl in ipairs(maptbl) do
for i, score in ipairs(records) do
CONS_Printf(
player,
string.format(
"%2d %-21s \x89%8s \x80%s",
i,
tbl["name"],
ticsToTime(tbl["time"]),
modeToString(tbl["flags"])
score["name"],
ticsToTime(score["time"]),
modeToString(score["flags"])
)
)
end
else
for i, tbl in ipairs(maptbl) do
for i, score in ipairs(records) do
CONS_Printf(
player,
string.format(
"%2d %-21s \x89%8s",
i,
tbl["name"],
ticsToTime(tbl["time"])
score["name"],
ticsToTime(score["time"])
)
)
end
@ -562,21 +564,26 @@ local function findRival(player, ...)
local totalScores = 0
local totalDiff = 0
CONS_Printf(player, string.format("\x89%s's times:", rival))
CONS_Printf(player, "MAP Time Diff Mode")
for mode, tbl in pairs(lb) do
scores[mode] = {}
local maplist = MapList()
local mapRecords
local rivalScore
local yourScore
for i = 1, #maplist do
mapRecords = GetMapRecords(maplist[i], ST_SEP)
for map, scoreTable in pairs(tbl) do
local rivalScore = nil
local yourScore = nil
for mode, records in pairs(mapRecords) do
scores[mode] = $ or {}
for _, score in pairs(scoreTable) do
if score["name"] == player.name then
rivalScore = nil
yourScore = nil
for _, score in ipairs(records) do
if score.name == player.name then
yourScore = score
elseif score["name"] == rival then
elseif score.name == rival then
rivalScore = score
end
@ -586,7 +593,7 @@ local function findRival(player, ...)
end
if rivalScore and yourScore then
totalDiff = totalDiff + yourScore["time"] - rivalScore["time"]
totalDiff = totalDiff + yourScore.time - rivalScore.time
end
if rivalScore then
@ -594,8 +601,8 @@ local function findRival(player, ...)
table.insert(
scores[mode],
{
["rival"] = rivalScore,
["your"] = yourScore
rival = rivalScore,
your = yourScore
}
)
end