Fix give weapon

This commit is contained in:
Jérémie N'gadi
2017-08-18 10:17:47 +02:00
parent 9db0cceb17
commit a5c420e05e
@@ -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(