fix: delay ox_inventory load until character registration completes in non-multicharacter

Delay ox_inventory load until character identity is set (non-multicharacter)
Inventory was loading before firstName were assigned to new
characters when multicharacter was disabled.

Fix/Changes:
* Check if multicharacter is disabled (Config.Multichar)
* Identify new characters (isNew flag)
* Wait for firstName to be registered
* Implement 2-minute timeout to prevent infinite loops
* Log warning if registration fails to complete in time
* Continue loading inventory anyway after timeout

Ensures identity data loads before inventory initializes
This commit is contained in:
SNAILX
2025-10-17 23:32:35 +01:00
committed by GitHub
parent f9792d8117
commit 080bf97283
+16 -5
View File
@@ -354,11 +354,22 @@ function loadESXPlayer(identifier, playerId, isNew)
if not Config.CustomInventory then
xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups)
elseif setPlayerInventory then
if not Config.Multichar and isNew and not xPlayer.get("firstName") and not xPlayer.get("lastName") then
while not xPlayer.get("firstName") and not xPlayer.get("lastName") do
Wait(3000)
end
end
-- Wait for identity to be set before loading inventory (for non-multichar)
if not Config.Multichar and isNew and not xPlayer.get("firstName") then
local sleep = 5000
local registrationTimeout = 120 * 1000 -- 2 minutes
while not xPlayer.get("firstName") do
registrationTimeout = registrationTimeout - sleep
if registrationTimeout <= 0 then
print(('[^3WARNING^7] Player ^5"%s"^7 Registration Timeout Reached (Loading Inventory Anyway).'):format(xPlayer.getName()))
break
end
Wait(sleep)
end
end
setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
end