Need HELP ! - esx_extraitems ammo

Hello !
So i have esx_extraitems installed for my server and i come across a problem with the Ammo boxes. If i try using them when my pistol is put away i will get the notification that i have to take out my weapon first. So … far so good… Once i take my weapon out and try using a box i get this error :

SCRIPT ERROR: @esx_extraitems/server/main.lua:289: attempt to call a nil value (field ‘addWeaponAmmo’)

That segment of the script goes as this:

RegisterNetEvent(‘esx_extraitems:removebox’)
AddEventHandler(‘esx_extraitems:removebox’, function(hash, ammo, type)
local xPlayer = ESX.GetPlayerFromId(source)

if type == 'boxpistol' then
	for k,v in pairs(Config.Weapons.Pistols) do
		if (v.weaponHash == hash) then
			xPlayer.addWeaponAmmo(v.weaponName, ammo)

			if Config.Removeables.AmmoBoxes then
				xPlayer.removeInventoryItem('boxpistol', 1)
				xPlayer.showNotification(_U('used_boxpistol'))
			end
			break
		else
			xPlayer.showNotification(_U('not_suitable'))
		end
	end

I just can’t figure out what the problem is… :frowning: is it because the “addWeaponAmmo” is not used anymore and should be replaced by something else?

Esx is still using addWeaponAmmo so that should still work Wiki.

You are getting the error attempt to call a nil value, because the script
did not pass the information to the next function. In other words the
addWeaponAmmo contains no information, thus is nil.

But it looks like the addWeaponAmmo can’t be called upon as it
receives a nil value from xPlayer. You can try something simple
as calling upon xPlayer and see if that returns any information.

To check if the xPlayer is working you can do the
following.

Citizen.CreateThread(function()
  while true do
    local xPlayer = ESX.GetPlayerFromId(source)
    if xPlayer then
      print('I have found some info!')
    else
      print("xPlayer did not return any information!")
    end
    Citizen.Wait(5000)
  end
end)

See if that is working then it must be something different.
I see that this plugin also gives you database entries!
Are you sure you have added the sql files to your database ?
If you did this, then please check if the ammo type you are trying
to remove is actually in the database list. Maybe that specific ammo
type was left out, or failed to insert into your database.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.