mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 00:01:20 +00:00
fix(es_extended/server/functions): xPlayer needs nil check
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user