fix(es_extended/server/functions): xPlayer needs nil check

This commit is contained in:
Kenshin13
2025-08-16 14:26:08 +02:00
parent ceb2927fcd
commit 1a441005a7
2 changed files with 23 additions and 2 deletions
+2 -2
View File
@@ -348,13 +348,13 @@ function ESX.GetNumPlayers(key, val)
end
---@param source number
---@return xPlayer
---@return xPlayer?
function ESX.GetPlayerFromId(source)
return ESX.Players[tonumber(source)]
end
---@param identifier string
---@return xPlayer
---@return xPlayer?
function ESX.GetPlayerFromIdentifier(identifier)
return Core.playersByIdentifier[identifier]
end
+21
View File
@@ -522,6 +522,10 @@ if not Config.CustomInventory then
local playerId = source
local xPlayer = ESX.GetPlayerFromId(playerId)
if not xPlayer then
return
end
if itemType == "item_standard" then
if not itemCount or itemCount < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
@@ -590,6 +594,11 @@ if not Config.CustomInventory then
RegisterNetEvent("esx:useItem", function(itemName)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then
return
end
local count = xPlayer.getInventoryItem(itemName).count
if count < 1 then
@@ -602,6 +611,10 @@ if not Config.CustomInventory then
RegisterNetEvent("esx:onPickup", function(pickupId)
local pickup, xPlayer, success = Core.Pickups[pickupId], ESX.GetPlayerFromId(source)
if not xPlayer then
return
end
if not pickup then return end
local playerPickupDistance = #(pickup.coords - xPlayer.getCoords(true))
@@ -644,6 +657,10 @@ end
ESX.RegisterServerCallback("esx:getPlayerData", function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then
return
end
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
@@ -667,6 +684,10 @@ end)
ESX.RegisterServerCallback("esx:getOtherPlayerData", function(_, cb, target)
local xPlayer = ESX.GetPlayerFromId(target)
if not xPlayer then
return
end
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),