Hooks and Events
Use hooks to validate or observe server-side inventory actions. Use lifecycle events to react to inventory state changes without modifying the resource.
Register a hook​
local hookId = exports.wasabi_inventory:registerHook('swapItems', function(payload)
print(json.encode(payload))
if payload.toInventory == 'restricted_stash' then
return false
end
end, {
itemFilter = {
water = true,
sandwich = true,
},
inventoryFilter = {
'^stash:',
},
typeFilter = {
player = true,
stash = true,
},
})
Available filter options:
| Filter | Purpose |
|---|---|
itemFilter | Map of item names that should reach the callback. |
inventoryFilter | Array of Lua patterns matched against source or destination inventory IDs. |
typeFilter | Map of inventory types that should reach the callback. |
Supported hook names​
| Hook | Behavior |
|---|---|
createItem | Observe or replace metadata by returning a metadata table. |
swapItems | Observe or cancel item movement by returning false. |
buyItem | Observe or cancel a shop purchase by returning false. |
usingItem | Observe or cancel item use by returning false. |
throwItem | Observe or cancel throwing before the item is removed. |
Hook payloads vary by action and include relevant fields such as source, inventory IDs/types, slots, item names, counts, metadata, coordinates, and weapon state.
Remove hooks​
-- Remove one hook created by this resource.
exports.wasabi_inventory:removeHooks(hookId)
-- Remove every hook registered by this resource.
exports.wasabi_inventory:removeHooks()
Hooks are also removed automatically when the registering resource stops.
Lifecycle events​
Inventory opened and closed (server)​
AddEventHandler('wasabi_inventory:openedInventory', function(source, inventoryId)
print(source, inventoryId)
end)
AddEventHandler('wasabi_inventory:closedInventory', function(source, inventoryId)
print(source, inventoryId)
end)
Local player inventory updated (client)​
AddEventHandler('wasabi_inventory:updateInventory', function(items, weight)
-- items is the current slot map; weight is the current total weight.
end)
Local item count changed (client)​
AddEventHandler('wasabi_inventory:itemCount', function(itemName, count)
print(itemName, count)
end)
Item list ready (server)​
AddEventHandler('wasabi_inventory:itemList', function(items)
-- Fired when the inventory server finishes initializing its item list.
end)
The resource also emits selected ox_inventory:* aliases for compatibility listeners.
warning
Do not call undocumented internal network events as an integration API. Prefer the documented exports, hooks, and lifecycle events; server-side inventory mutations remain authoritative.