Skip to main content
Some products need to know when a player moves an item from one inventory to another, and to be able to refuse the move: a shop that must not be emptied into a stash, a job container that only accepts certain items. Every other supported inventory publishes a hook for this. qb-inventory has none: its item move is an internal event with nothing to subscribe to. A product that needs the hook reports it and stops:

Outcome

qb-inventory publishes a RegisterOnSwapItems export, and products that watch item movement start and work. The edit is around fifteen lines in two of its files. Nothing else on your server changes.
Only products that watch item movement need this. If no product reports the line above, you have nothing to do here.

Prerequisites

  • qb-inventory running on your server, and a copy of the two files you are about to edit.
  • The steps below are written against current qb-inventory from qbcore-framework/qb-inventory. If yours is already a fork, the function names are the same but the line numbers are not.
  • Console access to restart qb-inventory and the product.

Steps

1. Add the export

Open qb-inventory/server/functions.lua and add this at the end of the file.

2. Call it from the move

Open qb-inventory/server/main.lua and find the handler for qb-inventory:server:SetInventoryData. It starts like this:
Inside it, after both items have been read (the two lines that call getItem) and before anything is added or removed, insert:
Returning before the move is what refuses it: the item never leaves its slot, and the player’s inventory redraws unchanged.

3. Restart

Verification

The product no longer reports the missing export when it starts. To confirm the hook fires, move an item into an inventory the product watches. A product that refuses the move leaves the item where it was.

Next steps

What the product receives

The handler is called with one table, the same shape every supported inventory reports: A handler that returns false refuses the move. Any other return value (including no return at all) allows it.

Keeping the edit

qb-inventory updates overwrite both files. After updating it, re-apply the two steps above; the product reports the missing export again if you forget, so this fails loudly rather than silently.