Issue with silent item removal [ESX] / [ESX_Weaponsync]

Hey guys,

Okay so I’m using a plugin called esx_weaponsync, the developer of the plugin asked me to add the following to my main.lua file in the client folder in es_extended:

RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(item, count, silent)

  for i=1, #ESX.PlayerData.inventory, 1 do
    if ESX.PlayerData.inventory[i].name == item.name then
      ESX.PlayerData.inventory[i] = item
    end
  end

  if not silent then
    ESX.UI.ShowInventoryItemNotification(false, item, count)
  end

  if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
    ESX.ShowInventory()
  end

end)

This is the part that the script does to request a silent item removal, but for some reason it’s isn’t working:

RegisterServerEvent('esx:discardInventoryItem')
AddEventHandler('esx:discardInventoryItem', function(item, count)

	local _source = source
	local xPlayer  = ESX.GetPlayerFromId(source)

  xPlayer.removeInventoryItem(item, count, true)

end)

I’m sure something is going wrong with the script, normally I would see the issue but I just can’t find the issue in this script. I hope anyone is able to help me solve the issue. Any suggestion or tip is welcome.

Many Thanks!

Quick update: It’s also showing this, and not -1 how it should be… I’ve no idea what’s going on.

1 Like

Shouldn’t it be

if silent then

considering silent is set to true.

if not silent then

would mean if it’s not true, AKA false.

1 Like

Omg… I’m so stupid. :man_facepalming:

You’re a hero! Thanks for giving me the solution. :sweat_smile:

Have an awesome day!

1 Like

Would you be able tot help me I’m having problems witht it were it wont let me hold the weapon.

I’m not using the script anymore, I send it to a different server since I didn’t need it anymore.

Could you help me to get it to work tho

No I’m sorry, don’t really remember how the script works.

Did you find a better method of doing this

Yes we did. This script was just broken and bugged. The best thing was to just make a script for it.

Are you able to share with me please in a message if you don’t mind I truly appreciate it

No sorry I can’t share it.

Thanks for your response appreciate it :grinning:

1 Like

I would love to share anything but for some reason others are not. I’ve to keep the scripts for our own. I’m very sorry, but if you need help with anything I’m happy to help. I just don’t really know how the script is working since I didn’t use it for a while.

Thank you

1 Like

Could you tell me where you put the code exactly please?

How the script is installed because I have put the code in the client.lua of the esx_extended and when I go to the inventory there is no weapon

Same i have that problem to

So, you can see here where to put the code to really silent the notification when you are shooting :

es_extended/server/classes/player.lua

Search for self.addInventoryItem and self.removeInventoryItem and add silent like

In es_extended/client/main.lua, search for esx:addInventoryItem and esx:removeInventoryItem then add silent like this :

Can’t add a picture…

RegisterNetEvent(‘esx:addInventoryItem’)

AddEventHandler(‘esx:addInventoryItem’, function(item, count, silent)

for k,v in ipairs(ESX.PlayerData.inventory) do

    if v.name == item.name then

        ESX.PlayerData.inventory[k] = item

        break

    end

end



if not silent then

ESX.UI.ShowInventoryItemNotification(true, item, count)

end

if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then

    ESX.ShowInventory()

end

end)

RegisterNetEvent(‘esx:removeInventoryItem’)

AddEventHandler(‘esx:removeInventoryItem’, function(item, count, silent)

for k,v in ipairs(ESX.PlayerData.inventory) do

    if v.name == item.name then

        ESX.PlayerData.inventory[k] = item

        break

    end

end

if not silent then

    ESX.UI.ShowInventoryItemNotification(false, item, count)

end

if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then

    ESX.ShowInventory()

end

end)