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 = {} 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 -- GLOBAL
-- Function for adding records from lua -- Function for adding records from lua
local function AddColdStore(record) local function AddColdStore(record)

View File

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