diff --git a/CHANGELOG.md b/CHANGELOG.md index 357ce352bc..ca191e3007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed `GM:TTTBodySearchPopulate` using the wrong data variable (by @TimGoll) - Fixed font initialization to not trip engine font fallback behavior (by @EntranceJew) - Fixed the decoy producing a wrong colored icon for other teams (by @NickCloudAT) +- Fixed the scoreboard being stuck open sometimes if the inflictor was no weapon (by @TimGoll) - Fixed door health displaying as a humongous string of decimals ### Removed diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index 513695cba9..7abb8e5cd8 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -59,6 +59,8 @@ CORPSE_KILL_DIRECTION_SIDE = 3 -- stylua: ignore local cvInspectConfirmMode = CreateConVar("ttt2_inspect_confirm_mode", "0", {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}) +local materialWeaponFallback = Material("vgui/ttt/missing_equip_icon") + bodysearch = {} --- @@ -819,7 +821,25 @@ if CLIENT then local function TypeToMaterial(type, data) if type == "wep" then - return util.WeaponForClass(data.wep).iconMaterial + local wep = util.WeaponForClass(data.wep) + + -- in most cases the inflictor is a weapon and the weapon has a cached + -- material that can be used + if wep.iconMaterial then + return wep.iconMaterial + + -- sometimes the projectile is a custom entity that kills the player + -- which means it is not a weapon with a cached material + else + local mat = Material(wep.Icon) + + if not mat:IsError() then + return mat + end + + -- as a fallback use this missing texture icon + return materialWeaponFallback + end elseif type == "dmg" then return DamageToIconMaterial(data) elseif type == "death_time" then @@ -916,6 +936,8 @@ if CLIENT then function bodysearch.PreprocSearch(raw) local search = {} + local index = 1 + for i = 1, #bodysearch.searchResultOrder do local type = bodysearch.searchResultOrder[i] local searchData = bodysearch.GetContentFromData(type, raw) @@ -930,11 +952,27 @@ if CLIENT then -- only use the first text entry here local transText = LANG.GetDynamicTranslation(text[1].body, text[1].params, true) - search[type] = { - img = searchData.iconMaterial:GetName(), - text = transText, - p = i, -- sorting number - } + if searchData.iconMaterial then + -- note: GetName only returns the material name. This fails if the addon uses a + -- png for its material, we therefore have to check if the material exists on disk + local materialFile = searchData.iconMaterial:GetName() + + if file.Exists("materials/" .. materialFile .. ".png", "GAME") then + materialFile = materialFile .. ".png" + elseif file.Exists("materials/" .. materialFile .. ".jpg", "GAME") then + materialFile = materialFile .. ".jpg" + elseif file.Exists("materials/" .. materialFile .. ".jpeg", "GAME") then + materialFile = materialFile .. ".jpeg" + end + + search[type] = { + img = materialFile, + text = transText, + p = index, -- sorting number + } + + index = index + 1 + end -- special cases with icon text local iconTextFn = TypeToIconText(type, raw)