From 41f241c88549ae70d1bea8feba8e9ec873008194 Mon Sep 17 00:00:00 2001 From: AmitHaina Date: Sun, 21 Jun 2026 13:02:24 +0545 Subject: [PATCH] fix: resolve typos, nil pointer exceptions, and outfit permission checks - Fix event name typo (illenium-apearance to illenium-appearance) in job/gang outfits commands. -m - Prevent nil check crashes in LoadPlayerUniform, OpenClothingRoom, OpenPlayerOutfitRoom, and importOutfitCode / deleteOutfit. -m - Correct permission evaluation logic in IsPlayerAllowedForOutfitRoom when no citizen IDs are configured. --- client/client.lua | 15 +++++++++------ client/common.lua | 5 ++++- client/outfits.lua | 2 +- client/zones.lua | 4 ++++ server/server.lua | 15 +++++++++++++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/client/client.lua b/client/client.lua index d419f821..9feeedbe 100644 --- a/client/client.lua +++ b/client/client.lua @@ -34,12 +34,15 @@ local function LoadPlayerUniform(reset) TriggerEvent("illenium-appearance:client:changeOutfit", uniform) else - local outfits = Config.Outfits[uniformData.jobName][uniformData.gender] + local jobOutfits = Config.Outfits[uniformData.jobName] + local outfits = jobOutfits and jobOutfits[uniformData.gender] local uniform = nil - for i = 1, #outfits, 1 do - if outfits[i].name == uniformData.label then - uniform = outfits[i] - break + if outfits then + for i = 1, #outfits, 1 do + if outfits[i].name == uniformData.label then + uniform = outfits[i] + break + end end end @@ -727,7 +730,7 @@ RegisterNetEvent("illenium-appearance:client:reloadSkin", function(bypassChecks) end client.setPlayerAppearance(appearance) if Config.PersistUniforms then - LoadPlayerUniform(bypassChecks) + LoadPlayerUniform() end RestorePlayerStats() end) diff --git a/client/common.lua b/client/common.lua index 6a926082..0a7066e7 100644 --- a/client/common.lua +++ b/client/common.lua @@ -3,6 +3,9 @@ function CheckDuty() end function IsPlayerAllowedForOutfitRoom(outfitRoom) + if not outfitRoom or not outfitRoom.citizenIDs or #outfitRoom.citizenIDs == 0 then + return true + end local isAllowed = false local count = #outfitRoom.citizenIDs for i = 1, count, 1 do @@ -11,7 +14,7 @@ function IsPlayerAllowedForOutfitRoom(outfitRoom) break end end - return isAllowed or not outfitRoom.citizenIDs or count == 0 + return isAllowed end function GetPlayerJobOutfits(job) diff --git a/client/outfits.lua b/client/outfits.lua index b477a46f..6f725251 100644 --- a/client/outfits.lua +++ b/client/outfits.lua @@ -136,7 +136,7 @@ RegisterNetEvent("illenium-appearance:client:openOutfitMenu", function() OpenMenu(nil, "outfit") end) -RegisterNetEvent("illenium-apearance:client:outfitsCommand", function(isJob) +RegisterNetEvent("illenium-appearance:client:outfitsCommand", function(isJob) local outfits = GetPlayerJobOutfits(isJob) TriggerEvent("illenium-appearance:client:openJobOutfitsMenu", outfits) end) diff --git a/client/zones.lua b/client/zones.lua index fd0da1cf..54f2d6d1 100644 --- a/client/zones.lua +++ b/client/zones.lua @@ -186,12 +186,16 @@ AddEventHandler("onResourceStop", function(resource) end) RegisterNetEvent("illenium-appearance:client:OpenClothingRoom", function() + if not currentZone or not currentZone.index then return end local clothingRoom = Config.ClothingRooms[currentZone.index] + if not clothingRoom then return end local outfits = GetPlayerJobOutfits(clothingRoom.job) TriggerEvent("illenium-appearance:client:openJobOutfitsMenu", outfits) end) RegisterNetEvent("illenium-appearance:client:OpenPlayerOutfitRoom", function() + if not currentZone or not currentZone.index then return end local outfitRoom = Config.PlayerOutfitRooms[currentZone.index] + if not outfitRoom then return end OpenOutfitRoom(outfitRoom) end) diff --git a/server/server.lua b/server/server.lua index 024906b8..148b300e 100644 --- a/server/server.lua +++ b/server/server.lua @@ -57,6 +57,8 @@ end) lib.callback.register("illenium-appearance:server:importOutfitCode", function(source, outfitName, outfitCode) local citizenID = Framework.GetPlayerID(source) + if not citizenID then return nil end + local existingOutfitCode = Database.PlayerOutfitCodes.GetByCode(outfitCode) if not existingOutfitCode then return nil @@ -77,6 +79,10 @@ lib.callback.register("illenium-appearance:server:importOutfitCode", function(so return end + if outfitCache[citizenID] == nil then + getOutfitsForPlayer(citizenID) + end + outfitCache[citizenID][#outfitCache[citizenID] + 1] = { id = id, name = outfitName, @@ -272,9 +278,14 @@ end) RegisterNetEvent("illenium-appearance:server:deleteOutfit", function(id) local src = source local citizenID = Framework.GetPlayerID(src) + if not citizenID then return end Database.PlayerOutfitCodes.DeleteByOutfitID(id) Database.PlayerOutfits.DeleteByID(id) + if outfitCache[citizenID] == nil then + getOutfitsForPlayer(citizenID) + end + for k, v in ipairs(outfitCache[citizenID]) do if v.id == id then table.remove(outfitCache[citizenID], k) @@ -335,11 +346,11 @@ end if Config.EnableJobOutfitsCommand then lib.addCommand("joboutfits", { help = _L("commands.joboutfits.title"), }, function(source) - TriggerClientEvent("illenium-apearance:client:outfitsCommand", source, true) + TriggerClientEvent("illenium-appearance:client:outfitsCommand", source, true) end) lib.addCommand("gangoutfits", { help = _L("commands.gangoutfits.title"), }, function(source) - TriggerClientEvent("illenium-apearance:client:outfitsCommand", source) + TriggerClientEvent("illenium-appearance:client:outfitsCommand", source) end) end