Skip to content

Compatibility ​

np_inventory registers the common ox_inventory and qb-inventory exports under its own name. With a provide line in fxmanifest.lua it answers in place of the original resource, so frameworks and scripts that call exports.ox_inventory:… or exports['qb-inventory']:… keep working without changes:

lua
-- fxmanifest.lua: uncomment the one you need and remove the original resource
provide 'ox_inventory'    -- qbx_core, and scripts written for ox_inventory
provide 'qb-inventory'    -- qb-core, and scripts written for qb-inventory

provide shares one export namespace. Where both APIs use the same name (AddItem, RemoveItem, GetItemCount, ClearInventory, GetInventory, OpenInventory), the export looks at the arguments, and calls from qb-core always get qb's behaviour. Setup per framework: Installation.

ox_inventory ​

Server ​

Every native export that ox_inventory also has uses ox's signature and returns np_inventory's item objects, which have ox's shape (name, label, weight, slot, count, metadata, stack, close, description). On top of those:

Export Notes
GetSlotWithItem(inv, name, metadata?, strict?) / GetSlotsWithItem(…) First / all slots with the item
GetSlotIdWithItem(…) / GetSlotIdsWithItem(…) Their slot numbers
GetEmptySlot(inv) First free slot
Search(inv, 'slots' | 'count', items, metadata?) items = a name or a list of names
CanSwapItem(inv, firstItem, firstCount, testItem, testCount) Weight check for swapping one item for another
CanCarryAmount(inv, item) How many more units fit (slots and weight)
GetContainerFromSlot(inv, slot) The bag inventory of the item in that slot
RegisterShop(shopType, { name, inventory, locations, groups }) Runtime shop, see Shops
forceOpenInventory(src, invType, data) Like OpenInventory; 'shop' is not supported
CustomDrop(prefix, items, coords, slots?, maxWeight?, instance?, model?) A drop with a label and its own size
setPlayerInventory(player, data?) Loads a player (how the qbx bridge of ox hands over a login)
registerHook / removeHook / removeHooks() ox hook names are accepted as aliases, see Hooks
ConfiscateInventory / ReturnInventory, CreateTemporaryStash, RegisterStash, SetMaxWeight, SetSlotCount, GetCurrentWeapon Native exports with ox's signatures

AddItem's sixth parameter cb(success, response) is supported. RegisterStash(id, label, slots, maxWeight, owner, groups, coords) behaves like ox's: owner = true is one stash per character.

Client ​

  • Exports with ox's signatures: openInventory, closeInventory, Search, GetItemCount, GetPlayerItems, GetPlayerWeight, GetPlayerMaxWeight, Items, useSlot, useItem, displayMetadata, getCurrentWeapon.
  • State bags: invBusy (blocks and closes), invHotkeys = false (no hotbar keys), invOpen (set by np_inventory).
  • Events: np_inventory mirrors ox_inventory:itemCount and ox_inventory:currentWeapon, and listens to ox_inventory:disarm (net event: put the weapon away) and ox_inventory:closeInventory (local event).

Item callbacks ​

Item definitions use ox's callback signatures:

  • server = { export = 'resource.fn' } is called as fn(event, item, inventory, slot, data) with usingItem (before the use; false cancels it), usedItem (after it) and buying (before a shop purchase; false refuses it).
  • client = { export = 'resource.fn' } is called as fn(data, slot) after the server confirmed the use. Inside it, useItem(data, cb) calls cb(slot) right away.

See Items → server and client.

Differences to know ​

ox_inventory np_inventory
Item definitions data/items.lua, data/weapons.lua Config.Items (see Items → Coming from ox). ox's data files are not read
Use flow client.export can start its own progress with useItem np_inventory always runs the progress and the server check first, then calls client.export
Hook payloads ox's fields np_inventory's fields (fromInventory, toType, …), also under ox's hook names
consume Amount per use Status deltas; one unit per use

Not implemented, among others: the server exports SetItem, GetItemSlots, InspectInventory and UpdateVehicle, the client exports weaponWheel and giveItemToTarget, and ox's server events (ox_inventory:usedItem, ox_inventory:openedInventory, ox_inventory:closedInventory). Use np_inventory's events instead.

qbx_core ​

qbx_core talks to its inventory only through ox's exports. With provide 'ox_inventory' and Config.Framework = 'qbx':

  • Player.Functions.AddItem / RemoveItem / HasItem, exports.qbx_core:HasItem and everything else that qbx routes to ox_inventory reach np_inventory.
  • Usable items registered with exports.qbx_core:CreateUseableItem are used through that callback when the item has no use of its own (Framework usable items).
  • Player inventories that ox_inventory stored in players.inventory are imported on first load (Migrating).

qb-inventory ​

qb-core's Player.Functions.AddItem, RemoveItem, GetItemBySlot, GetItemByName, GetItemsByName, ClearInventory, SetInventory, QBCore.Functions.HasItem and UseItem call exports['qb-inventory']. With provide 'qb-inventory' they reach these exports, with the signatures of the current qb-inventory:

Export Returns Notes
AddItem(identifier, item, amount, slot?, info?, reason?) boolean Falls back to a free slot when slot is taken. reason is logged
RemoveItem(identifier, item, amount, slot?, reason?) boolean
HasItem(source, items, amount?) boolean 'name', { 'a', 'b' } (each ≥ amount) or { a = 2, b = 1 }
GetItemCount(source, items) number A name or a list (summed)
GetItemBySlot(source, slot) / GetItemByName(source, item) / GetItemsByName(source, item) qb item(s)
GetSlotsByItem(items, name) / GetFirstSlotByItem(items, name) slots Over a qb items table
GetTotalWeight(items) grams A qb items table, or a server id
GetFreeWeight(source) grams
GetSlots(identifier) used, free
CanAddItem(source, item, amount) ok, 'weight' | 'slots'
SetInventory(source, items) / SetItemData(source, item, key, value) boolean
ClearInventory(source, filter?) / ClearStash(identifier) / RemoveInventory(identifier) boolean filter = names to keep
UseItem(itemName, source, item) boolean Runs the framework usable callback. The older UseItem(source, item) works too
CreateInventory(identifier, { label, maxweight, slots }) boolean Registers a stash on first use
OpenInventory(source, identifier?, data?) boolean Own inventory without identifier; else that stash / trunk / glovebox / player, created with data when it doesn't exist. No access checks, like qb-inventory: the caller checks
OpenInventoryById(source, targetId) boolean Another player's pockets (admin mode)
CloseInventory(source) boolean
GetInventory(identifier) table { label, slots, maxweight, items, isOpen }
LoadInventory(source) / SaveInventory(source) np_inventory loads on login and saves itself; these return the items / flush
CreateShop(shopData) / OpenShop(source, name) boolean qb-shops style shops (Shops)

identifier is a server id, a stash id or inventory id, or qb's trunk-<plate> / glovebox-<plate>. Items come back in qb's shape: { name, amount, info, label, slot, weight (per unit), type, unique, … }.

  • Player.PlayerData.items is mirrored from the pockets after every change, so scripts that read QBCore.Functions.GetPlayerData().items or loop over PlayerData.items see the real inventory.
  • Usable items from QBCore.Functions.CreateUseableItem keep working (Framework usable items).
  • Client: exports['qb-inventory']:HasItem(items, amount?), which qb-core's client QBCore.Functions.HasItem calls.
  • qb-inventory's net events (inventory:server:OpenInventory, the ItemBox popups, …) are not implemented. Open inventories through the exports; the item feed replaces the item box.

ESX ​

np_inventory works with es_extended for identity, jobs, money (cash and black money synced with the accounts in item mode), licences (esx_license), status (esx_status) and usable items (ESX.RegisterUsableItem).

ESX's own inventory functions are not replaced by default: xPlayer.addInventoryItem, removeInventoryItem, getInventoryItem, canCarryItem and the ESX inventory menu work on ESX's inventory. Two ways to handle that:

  • Use np_inventory's exports in your scripts.
  • Set Config.Esx.overrideInventory = true (ESX Legacy 1.9+). np_inventory then registers ESX player function overrides (the mechanism ox_inventory uses), so getInventory, getInventoryItem, hasItem, addInventoryItem, removeInventoryItem, setInventoryItem, canCarryItem, canSwapItem, getWeight, getMaxWeight and setMaxWeight call np_inventory. This applies to players who log in after np_inventory started; players already online keep ESX's functions until they relog. Items come back in ESX's shape: { name, label, count, weight, usable, rare, canRemove }.

Player inventories stored in users.inventory are imported on first load. Recipe skill requirements are skipped on ESX unless you set Config.Skills.get.

Other np_* resources ​

Resource How it fits
np_phone The phone item opens np_phone (exports.np_phone:toggle())
np_hud Progress bars, prompts and toasts go through np_hud while it runs (Config.UseNpHud = 'auto'). The hotbar is always np_inventory's own
np_character np_inventory loads the inventory on np_character:loaded, and standalone it uses the character's CID as owner. np_character's starter pack and ID card reach np_inventory on qb and qbx (through provide), and on ESX with Config.Esx.overrideInventory
np_menu The quick menu's Inventory entry runs a command when no event is set: Config.Quick.inventoryCommand = 'npinv'
np_payments Shop carts paid in cash or by card open the np_payments checkout while it runs (Config.Payments = 'auto'). See Shops → np_payments. np_payments registers its receipt item in np_inventory at runtime, and locks the inventory while its sheet is open
np_shops Detected automatically: while np_shops runs, np_inventory's built-in shops (Config.Shops) switch off (no prompts, blips or purchases), live when np_shops starts or stops. Runtime shops stay. Config.NpShops = false keeps both. See Shops → np_shops detection
np_fuel Registers jerrycan (with server = { export = 'np_fuel.jerrycan' }) and fuel_receipt at runtime. The built-in jerry can steps aside while np_fuel runs (Config.BuiltinItems.jerrycan.owner = 'np_fuel'), see Items → Owner resource and np_fuel → Jerry can
np_mechanic Registers its mech_* items at runtime (parts with maker and serial metadata, scanner, toolbox, consumables, fake plates, crates, invitations) with images, plus workshop supply stashes and hidden compartments guarded by the beforeOpen hook. Dirty money is the black_money item. Your built-in repairkit, spare_tire, jerrycan, car_keys and lockpick are untouched. See np_mechanic → Compatibility
np_vending Registers its tool items (vending_crate, vending_deed, vending_key, vending_tablet, vending_repairkit, vending_skimmer, crowbar) and every stock item it sells (category vending, with consume from its effects) at runtime when they are missing. Machines are stocked from the player's inventory, Drink now uses the item through UseSlot, and the wholesale depot is a shop registered with RegisterShop (npv_wholesale). See np_vending → Items
np_minigames While it runs, the built-in lockpick (and, opt-in, repairkit / spare_tire) play its server-validated games (Config.Minigames, see Items → Minigames). np_inventory is np_minigames' first-choice bridge for opts.item (GetItemCount, RemoveItem, DegradeItem)
np_metal-scanner Registers metal_wand, locker_ticket, seized_weapon, tray_weapon, lead_pouch, ceramic_knife, the ground detecting kit and its find_* items at runtime (use callback np_metal-scanner.useItem), and again whenever np_inventory restarts. Items may carry a metal field ({ mass, class, zone }, 0 for invisible) that gates and wands read after its own Config.ItemMetal. Evidence goes into the evidence inventory type (one per case), lockers into stashes, the divest tray into a temporary stash, and the drawn weapon item (GetCurrentWeapon) is de-duplicated against the ped's weapon. See np_metal-scanner → Items
np_fishing Registers its gear (fishing_*, bait_*, lure_*), one unique fish_<species> item per species (stars in quality, spoiling with created / expires, fish SVGs as images), fish_fillet and fishing_trophy at runtime, and again whenever np_inventory restarts. Usable items call server = { export = 'np_fishing.useItem' }; the rig and the wear live in the rod's metadata (durability bar). fishing_cooler is a container with half the decay rate. The bait & tackle shops are registered with RegisterShop (np_fishing_<shop id>), and np_fishing marks the inventory busy (setBusy) while a line is out. See np_fishing → Items
np_golf Registers golf_bag (a container that only takes golf items), golf_club (one item per club, metadata { club, set, wear }), three ball items and golf_hio_insurance at runtime, and again whenever np_inventory restarts. The server reads the clubs and balls inside the bag, wears the clubs after each round and removes balls lost in water; np_golf marks the inventory busy (setBusy) while a player addresses the ball. See np_golf → Items & the bag
np_darts Registers dart_set (unique, the build and the flight durability in its metadata, shown in the tooltip) and dart_flights at runtime, and again whenever np_inventory restarts. Free pints and coffee or water steady the hand through an afterUse hook, and np_darts marks the inventory busy (setBusy) while a player throws. See np_darts → Items
np_billiards Registers its cue gear (pool_cue with serial, tip wear and stats in the metadata, pool_shaft, pool_glove, pool_tip_kit, pool_chalk) at runtime with server = { export = 'np_billiards.useItem' } (opens the cue case), and marks the inventory busy (setBusy) while a player plays. See np_billiards → Items & the cue case