better check for round based + fix nil values

This commit is contained in:
mjkzy 2022-07-04 18:47:08 -05:00
parent 47c09a5fa7
commit fb86147990
2 changed files with 49 additions and 8 deletions

View File

@ -2,6 +2,16 @@ if game:issingleplayer() then
return
end
-- from mpdepotbase.lua, global definition isn't working
InventoryCurrencyType = {
LaunchCredits = 1,
Credits = 2,
Parts = 3,
CoDPoints = 4,
Bonus = 5,
Max = 6
}
custom_depot = {
collection_details_menu = nil,
data = {

View File

@ -1,17 +1,48 @@
local player_score = 0
-- from roundend.lua, dev comments says that the game["round_end"] array contains indexes for this table
local ending_reasons = {
"MP_DRAW",
"LUA_MENU_REPORT_DRAW",
"MP_ROUND_WIN",
"MP_ROUND_LOSS",
"LUA_MENU_REPORT_VICTORY",
"LUA_MENU_REPORT_DEFEAT",
"MP_HALFTIME",
"MP_OVERTIME",
"MP_ROUNDEND",
"MP_INTERMISSION",
"MP_SWITCHING_SIDES",
"MP_MATCH_BONUS_IS",
"MP_MATCH_TIE",
"MP_GAME_END",
"SPLASHES_BLANK"
}
local function starts_with(str, start)
return str:sub(1, #start) == start
end
local player_old_score = 0
Scoreboard_orig = LUI.MenuBuilder.m_types_build["scoreboard"]
Scoreboard = function(unk1, unk2)
local scoreboard = Scoreboard_orig(unk1, unk2)
local scoreboard_orig = LUI.MenuBuilder.m_types_build["scoreboard"]
local scoreboard = function(unk1, unk2)
local scoreboard = scoreboard_orig(unk1, unk2)
scoreboard:registerOmnvarHandler("ui_round_end", function(f22_arg0, f22_arg1)
if GameX.IsRankedMatch() then
local player_score = 0
local gamemode = GameX.GetGameMode()
local player_stats = Game.GetPlayerScoreInfoAtRank(Game.GetPlayerTeam(), Game.GetPlayerScoreRanking())
if Engine.GetDvarInt(string.format("scr_%s_halftime", gamemode)) == 1 or IsGameTypeRoundBased(gamemode) or
gamemode == "conf" or gamemode == "war" then
--[[
this will do the job for when its needed, aka when round loss/win occurs
this check may be true more than once cuz this callback happens 3 times,
but the player_old_score variable will stop us from adding more currency
]] --
local unlocalized_string = ending_reasons[Game.GetOmnvar("ui_round_end_title")]
local is_round_based = starts_with(unlocalized_string, "MP_ROUND") or IsGameTypeRoundBased(gamemode)
if is_round_based or gamemode == "conf" or gamemode == "war" then
player_score = player_stats.score
else
player_score = player_stats.extrascore0
@ -19,7 +50,7 @@ Scoreboard = function(unk1, unk2)
local currency_gain = math.floor((player_score - player_old_score) * 10 / 100)
if currency_gain == 0 then
if currency_gain <= 0 then
return
end
@ -32,4 +63,4 @@ Scoreboard = function(unk1, unk2)
return scoreboard
end
LUI.MenuBuilder.m_types_build["scoreboard"] = Scoreboard
LUI.MenuBuilder.m_types_build["scoreboard"] = scoreboard