qb-core icon indicating copy to clipboard operation
qb-core copied to clipboard

[BUG] /giveitem doesn't work when updating items via AddItem/AddItems

Open Waves966 opened this issue 3 years ago • 2 comments

Describe the bug When you add/remove items via the export exports['qb-core']AddItems(items) and try to use /giveitem it will always say the item does not exist.

To Reproduce Steps to reproduce the behavior:

  1. Add an item using exports['qb-core']AddItem(item)
  2. Attempt to use /giveitem for that new item
  3. See notification that item does not exist.

Expected behavior I expect the giveitem command to be able to give items that are added via the exports.

Screenshots If applicable, add screenshots to help explain your problem.

Questions (please complete the following information):

  • When you last updated: 2 Weeks ago
  • Are you using custom resource? which ones? Custom made resource that adds the items, no special logic, just a command that uses the export to add an item.
  • Have you renamed qb- to something custom? [e.g. yes/no] no

Additional context It seems that sometimes the shared object in the resource isn't getting updated even though I have

-- Client
QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('QBCore:Client:UpdateObject', function()
    QBCore = exports['qb-core']:GetCoreObject()
end)

-- Server
QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('QBCore:Server:UpdateObject', function()
    QBCore = exports['qb-core']:GetCoreObject()
end)

Waves966 avatar Jul 14 '22 21:07 Waves966

Update: It seems that the event for updating the object isn't working correctly because if I manually reget the QBCore object at the start of my function AddItem seems to work again. although /giveitem still isn't working

ghost avatar Jul 14 '22 21:07 ghost

You need the refresh object in the inventory resource as well as pretty much every other resource you want to access the new items.

IdrisDose avatar Aug 08 '22 23:08 IdrisDose

So intended behavior but wrong use case? Can this be closed then @Waves966?

ChatDisabled avatar Aug 21 '22 19:08 ChatDisabled

This is still an issue. I am able to reproduce this in a qb-core / qb-inventory environment by:

  1. making a script that calls AddItem
  2. ensuring the script
  3. reloading qb-inventory
  4. calling /giveitem (a "Item Does Not Exist" error is received from a QBCore:Notify event)

Why was this issue closed?

crusopaul avatar Nov 24 '22 14:11 crusopaul

I'll add, this seems related to the open issue #854

crusopaul avatar Nov 24 '22 14:11 crusopaul