diff --git a/resources/[essential]/es_extended/client/functions.lua b/resources/[essential]/es_extended/client/functions.lua index 5e85b674..f9d3b60f 100644 --- a/resources/[essential]/es_extended/client/functions.lua +++ b/resources/[essential]/es_extended/client/functions.lua @@ -463,11 +463,11 @@ ESX.Game.GetClosestPlayer = function(coords) local closestPlayer = -1 local coords = coords local usePlayerPed = false - local playerPed = nil + local playerPed = GetPlayerPed(-1) + local playerId = PlayerId() if coords == nil then usePlayerPed = true - playerPed = GetPlayerPed(-1) coords = GetEntityCoords(playerPed) end @@ -475,7 +475,7 @@ ESX.Game.GetClosestPlayer = function(coords) local target = GetPlayerPed(players[i]) - if not usePlayerPed or (usePlayerPed and target ~= playerPed) then + if not usePlayerPed or (usePlayerPed and players[i] ~= playerId) then local targetCoords = GetEntityCoords(target) local distance = GetDistanceBetweenCoords(targetCoords.x, targetCoords.y, targetCoords.z, coords.x, coords.y, coords.z, true) @@ -944,7 +944,15 @@ ESX.ShowInventory = function() if data.current.action == 'give' then if type == 'item_weapon' then - TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, 1) + + local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + + if closestPlayer == -1 or closestDistance > 3.0 then + ESX.ShowNotification(_U('players_nearby')) + else + TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, 1) + end + else ESX.UI.Menu.Open(