It’s strange, I have this but it doesn’t work :
RegisterServerEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
local _source = source
local sourceXPlayer = ESX.GetPlayerFromId(_source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if type == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
local targetItem = targetXPlayer.getInventoryItem(itemName)
if itemCount > 0 and sourceItem.count >= itemCount then
if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
TriggerClientEvent('esx:showNotification', target, _U('ex_inv_lim') .. targetXPlayer.name)
else
sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem (itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' ~g~x' .. itemCount .. ' ' .. ESX.Items[itemName].label .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' ~g~x' .. itemCount .. ' ' .. ESX.Items[itemName].label .. _U('by') .. sourceXPlayer.name)
TriggerEvent("esx:giveitemalert",sourceXPlayer.name,targetXPlayer.name,ESX.Items[itemName].label,itemCount)
end
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_quantity'))
end
elseif type == 'item_money' then
if itemCount > 0 and sourceXPlayer.player.get('money') >= itemCount then
sourceXPlayer.removeMoney(itemCount)
targetXPlayer.addMoney(itemCount)
TriggerEvent("esx:givemoneyalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' ~g~$' .. itemCount .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' ~g~$' .. itemCount .. _U('by') .. sourceXPlayer.name)
TriggerEvent("esx:givemoneyalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_amount'))
end
elseif type == 'item_account' then
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
sourceXPlayer.removeAccountMoney(itemName, itemCount)
targetXPlayer.addAccountMoney(itemName, itemCount)
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' [' .. Config.AccountLabels[itemName] .. '] ~g~$' .. itemCount .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' [' .. Config.AccountLabels[itemName] .. '] ~g~$' .. itemCount .. _U('by') .. sourceXPlayer.name)
TriggerEvent("esx:givemoneybankalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
else
TriggerClientEvent('esx:showNotification', target, _U('imp_invalid_amount'))
end
elseif type == 'item_weapon' then
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)
local weaponLabel = itemName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == itemName then
weaponLabel = Config.Weapons[i].label
break
end
end
TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' x1 ~g~' .. weaponLabel .. _U('to') .. targetXPlayer.name)
TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' x1 ~g~' .. weaponLabel .. _U('by') .. sourceXPlayer.name)
TriggerEvent("esx:giveweaponalert",sourceXPlayer.name,targetXPlayer.name,weaponLabel)
end
end)