Exports & hooks ​
All exports are called as exports.np_inventory:<name>(...). The names and signatures follow ox_inventory where they
overlap, so the same calls work through exports.ox_inventory with provide 'ox_inventory'. The extra ox-only and
qb-inventory exports are on Compatibility.
Server ​
server
inv is any of:
- a server id (the player's pockets),
- an inventory id (
'stash:lsmd_locker','trunk:AB12CD34','player:ABC12345', …), - a stash id (
'lsmd_locker'), { id = 'stashId', owner = 'ABC12345' }for a personal stash of a character.
Stored inventories (stashes, owned trunks) are loaded on demand, so these exports can yield. Weights are grams.
Items ​
| Export | Returns | Description |
|---|---|---|
AddItem(inv, name, count, metadata?, slot?, cb?) |
ok, item | reason |
Adds items. item is a copy of the (first) slot written. cb(ok, itemOrReason) is called too, like ox |
RemoveItem(inv, name, count, metadata?, slot?, ignoreTotal?, strict?) |
ok, reason |
Removes items. metadata matches partially unless strict. ignoreTotal removes what's there when there's less than count |
CanCarryItem(inv, name, count, metadata?) |
ok, reason |
Slot and weight check without changing anything |
CanCarryWeight(inv, grams) |
boolean |
Weight check only |
GetItemCount(inv, name, metadata?, strict?) |
number |
Total over all slots |
GetItem(inv, name, metadata?, returnsCount?) |
table | number |
The item definition with count (ox semantics), or just the count |
GetSlot(inv, slot) |
item | nil |
Copy of one slot |
SetMetadata(inv, slot, metadata) |
boolean |
Replaces a slot's metadata |
SetDurability(inv, slot, percent) |
boolean |
Durability 0–100, or the freshness of a decaying item |
DegradeItem(inv, name, points, slot?) |
ok, durabilityLeft | reason |
Wears one instance of a durability item by points the way a use does (removed at 0, durability 0 with keepBroken). Without slot the first slot with a non-broken name. Reasons: not_found, invalid. Used by np_minigames' opts.item.degrade |
GetInventory(inv) |
table | nil |
Plain copy: { id, type, label, owner, slots, maxWeight, weight, items, groups, coords, plate, … } |
GetInventoryItems(inv) |
{ [slot] = item } |
Copy of the items |
ClearInventory(inv, keep?) |
boolean |
Empties it. keep = an item name or a list of names to keep |
Items(name?) |
def | table |
One item definition, or all of them |
RegisterItem(name, def) |
boolean |
Adds or replaces an item definition at runtime (fields). The client-safe part is sent to every client, also to players who join later |
-- buy a burger: money first, then the item
if exports.np_inventory:CanCarryItem(source, 'burger', 1) and exports.np_inventory:RemoveItem(source, 'money', 9) then
exports.np_inventory:AddItem(source, 'burger', 1)
end
-- a car key for a plate
exports.np_inventory:AddItem(source, 'car_keys', 1, { plate = 'AB12CD34' })
-- remove only the key of that plate
exports.np_inventory:RemoveItem(source, 'car_keys', 1, { plate = 'AB12CD34' })
-- wear a tool down by hand
local slot = exports.np_inventory:GetSlotIdWithItem(source, 'lockpick')
local item = slot and exports.np_inventory:GetSlot(source, slot)
if item then exports.np_inventory:SetDurability(source, slot, item.metadata.durability - 20) end
Item objects look like ox_inventory's:
{ name = 'water', label = 'Water', slot = 3, count = 4, weight = 2000, -- total grams, bag contents included
metadata = { … }, stack = true, close = true, description = 'Still water, 0.5 l.' }
Reasons (reason above, and code in RPC answers): no_space, too_heavy, not_found, stale, invalid,
not_allowed, too_far, busy, locked, not_useable, spoiled, broken, cooldown, no_money, no_stock,
license, container_nested, container_type, equip_slot, rate, timeout, internal, dead, cuffed,
in_vehicle, target_full, cancelled, no_target (a built-in item found no valid target), empty (an empty jerry
can), shop_disabled (a built-in shop switched off while np_shops runs). Each has a localised text (err_<code>).
Inventories ​
| Export | Returns | Description |
|---|---|---|
RegisterStash(id, label, slots, maxWeight, owner?, groups?, coords?) |
boolean |
Registers a stash. owner = true makes it personal, a string a fixed owner. Also RegisterStash(id, { label, slots, maxWeight, owner, groups, coords, radius, pin, personal }). With coords it is announced to the clients (prompt and TAB). See Stashes |
CreateTemporaryStash({ label, slots, maxWeight, items, coords?, radius? }) |
id |
Memory-only stash, removed when the last viewer closes it. items = { { name, count, metadata? } } or { { 'name', count } } |
OpenInventory(src, type, id) |
boolean |
Forced open, no access checks. type: 'player' (id = server id), 'stash' (stash id or { id, owner }; personal stashes default to the caller), 'trunk' / 'glovebox' (plate; sized by the spawned vehicle's model override, else Config.Vehicles.defaultTrunk), 'drop', 'evidence' (case), 'container' (uid). OpenInventory(src, nil, inventoryId) opens any inventory by id |
CloseInventory(src) |
boolean |
Closes the player's inventory UI |
CreateDrop(coords, items, label?) |
id | nil |
A ground drop with these items |
ConfiscateInventory(src) / ReturnInventory(src) |
boolean |
Moves pockets and equipment into stash:confiscated:<owner> and back |
SetMaxWeight(inv, grams) / SetSlotCount(inv, n) |
boolean |
For a player this sets the base; equipment bonuses stay on top |
GetPlayerWeight(src) / GetPlayerMaxWeight(src) |
number |
Current and max carry weight |
SetVehicleOwned(plate, owned) |
boolean |
Persist a trunk / glovebox without a framework vehicle table (standalone, rentals) |
-- police: open the cuffed suspect's pockets for the officer
exports.np_inventory:OpenInventory(officerSrc, 'player', suspectSrc)
-- a gang stash that only the Ballas can open
exports.np_inventory:RegisterStash('ballas', 'Ballas Stash', 60, 300000, nil, { ballas = 0 }, vec3(85.1, -1959.4, 21.1))
-- jail: take everything, give it back on release
exports.np_inventory:ConfiscateInventory(src)
exports.np_inventory:ReturnInventory(src)
Weapons and use ​
| Export | Returns | Description |
|---|---|---|
GetCurrentWeapon(inv) |
item | nil |
The weapon the player has drawn (inv = server id) |
UseSlot(src, slot) |
ok, code |
Uses a pocket slot as if the player did it (all checks apply) |
Hooks ​
local id = exports.np_inventory:registerHook(event, function(payload)
-- return false (or false, 'Reason text') to veto
end, filter?)
exports.np_inventory:removeHook(id)
Hooks run on the server, synchronously, in registration order. A hook that errors is skipped and logged. Hooks of a
resource are removed when it stops. A veto answers the player with not_allowed and shows your reason text.
| Event | Payload | When |
|---|---|---|
beforeMove |
{ source, action, fromInventory, toInventory, fromType, toType, fromSlot, toSlot, item, count } |
Moves, quick moves, take all, the transfer of a give, drop pick-ups. action: move, split, stack, swap, transfer |
onDrop |
same as beforeMove, action = 'drop' |
An item is dropped on the ground |
beforeUse / afterUse |
{ source, action = 'use', inventoryId, slot, item } |
Before a use is accepted / after it completed |
beforeGive |
{ source, action = 'give', target, fromInventory, toInventory, fromSlot, item, count } |
Give to another player |
beforeBuy |
{ source, action = 'buy', shopId, toInventory, items, totals } |
A shop purchase (after the checks, before the payment) |
beforeCraft |
{ source, action = 'craft', benchId, recipe, item = { name }, count } |
Queueing a craft |
beforeOpen |
{ source, inventoryId, inventoryType } |
Opening a secondary inventory (stash, trunk, drop, player, …) |
onCreate |
{ source, action = 'create', toInventory, toType, item, count, metadata } |
An item is created. Return a table to replace its metadata |
action |
{ source, action, inventoryId, slot, item, value } |
A custom item action |
filter (optional) limits a hook:
{
itemFilter = { weed = true, black_money = true }, -- or { 'weed', 'black_money' }
inventoryFilter = { '^trunk:', '^stash:police' }, -- Lua patterns on the inventory id (source or target)
typeFilter = { drop = true, trunk = true }, -- inventory types (source or target)
}
ox_inventory hook names are accepted as aliases: swapItems → beforeMove, usingItem → beforeUse,
buyItem → beforeBuy, craftItem → beforeCraft, createItem → onCreate, openInventory → beforeOpen,
give → beforeGive. The payloads are np_inventory's, not ox's.
-- no guns in civilian trunks
exports.np_inventory:registerHook('beforeMove', function(p)
if p.toType == 'trunk' then return false, 'Guns stay out of the trunk.' end
end, { itemFilter = { weapon_pistol = true, weapon_smg = true } })
-- stamp who bought it
exports.np_inventory:registerHook('onCreate', function(p)
if p.source then
local md = p.metadata or {}
md.boughtBy = GetPlayerName(p.source)
return md
end
end, { itemFilter = { 'phone' } })
Client ​
client
| Export | Returns | Description |
|---|---|---|
openInventory(type?, data?) |
boolean |
No arguments: own inventory. 'stash' (id), 'player' (server id: rob or frisk), 'trunk' / 'glovebox' ({ netid = NetworkGetNetworkIdFromEntity(vehicle) }, or nothing for the vehicle in reach), 'drop' (id), 'shop' ({ type = shopId, id = locationIndex? }), 'crafting' (bench id). The server checks access |
closeInventory() |
Closes the UI | |
isOpen() |
boolean |
Any np_inventory screen is open |
setBusy(on) |
true |
Blocks opening and the hotbar (e.g. while another UI is open) and closes an open inventory |
GetItemCount(name, metadata?, strict?) |
number |
Count in the pockets. metadata matches partially unless strict; a string means { type = string } |
Search('count' | 'slots', items, metadata?) |
number | item[] (or a table per name) |
ox-style search over the pockets |
GetPlayerItems() |
{ [slot] = item } |
The pockets |
GetPlayerWeight() / GetPlayerMaxWeight() |
number |
Grams |
Items(name?) |
def | table |
Client-side item definitions |
useSlot(slot) |
boolean |
Uses a pocket slot |
getCurrentWeapon() |
item | nil |
The drawn weapon with hash and ammo |
isWeaponJammed() |
boolean |
The drawn weapon is jammed. A reload clears it |
reloadWeapon() |
boolean |
Starts a reload from ammo items without MakePedReload: the clip is set directly. Async. false = nothing to reload (clip full and not jammed), no reloadable weapon, or a reload is already running. Used by np_crouch-crawl-shoot while prone deployed |
displayMetadata(keys, label?) |
true |
Show extra metadata keys in tooltips: ('key', 'Label'), ({ key = 'Label' }) or ({ 'key' }). See Items → Metadata |
useItem(data, cb) |
boolean |
ox's useItem: inside an item's client.export it calls cb(slot) right away (the use is already confirmed). Outside one it does nothing |
requestTrade(serverId?) |
Ask a player (nil = the closest) to trade | |
setHandsUp(on) |
Hands up / down (the handsUp state bag) |
|
HasItem(items, amount?) |
boolean |
qb style: 'name', { 'a', 'b' } (each ≥ amount) or { a = 2, b = 1 } |
-- a target option on a locker
exports.np_inventory:openInventory('stash', 'mrpd_locker')
-- don't open your phone over the inventory
if exports.np_inventory:isOpen() then return end
-- block the inventory while your minigame runs
exports.np_inventory:setBusy(true)
-- …
exports.np_inventory:setBusy(false)
-- every slot that holds water
for slot, item in pairs(exports.np_inventory:GetPlayerItems()) do
if item.name == 'water' then print(slot, item.count) end
end
Prone fire (np_crouch-crawl-shoot) ​
MakePedReload plays the standing reload and breaks a prone pose. While LocalPlayer.state.proneDeployed is true
(set by np_crouch-crawl-shoot), np_inventory leaves the reload to the prone script:
- no auto reload when you pull the trigger on an empty clip,
npinv_reload(R) does nothing,- any reload that still runs (a jam clear,
reloadWeapon()) sets the clip directly instead of callingMakePedReload.
The prone script calls isWeaponJammed() before each shot (a jammed weapon clicks) and reloadWeapon() on R or an
empty clip. Its scripted shots are counted for durability and jams through the
np_ccs:shotFired event.
-- a scripted firing mode of your own, same idea
if exports.np_inventory:isWeaponJammed() then return end -- click, no shot
if not exports.np_inventory:reloadWeapon() then
-- full clip, no ammo items, or already reloading
end
Events ​
See Events, state bags & commands for np_inventory:server:itemAdded, :used, np_inventory:itemCount,
:currentWeapon and the rest.