Shiroyo
1
Hello.
I have esx script which should give player the weapon after picking up one of the spawning crate. This script main focus was to give player items not the weapons so probably there is problem with that I’m doing something wrong.
Code:
RegisterServerEvent(‘esx_drugs:pickedUpWeaponCrate’)
AddEventHandler(‘esx_drugs:pickedUpWeaponCrate’, function()
local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem(‘water’)
local player = GetPlayerPed(-1)
local weapon = GetHashKey(“WEAPON_MG”)
----GiveWeaponToPed(xPlayer, GetHashKey(“WEAPON_MG”), 1, 0, false) (neither works)
GiveWeaponToPed(player, weapon, 1, 0, false)
if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
TriggerClientEvent(‘esx:showNotification’, _source, _U(‘weed_inventoryfull’))
else
xPlayer.addInventoryItem(xItem.name, 1)
end
end)
And after picking up the crate I don’t get anything because code doesn’t work and I have such error in the console:
As said in the error in the console image you have provided it says attempt to call a nill value (global 'GiveWeaponToPed')
Are you sure this is a function that exists in your script?
Shiroyo
3
Oops, my bad then. I thought this function is built in and I don’t need to define it.