Skip to main content

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:

FilterPurpose
itemFilterMap of item names that should reach the callback.
inventoryFilterArray of Lua patterns matched against source or destination inventory IDs.
typeFilterMap of inventory types that should reach the callback.

Supported hook names​

HookBehavior
createItemObserve or replace metadata by returning a metadata table.
swapItemsObserve or cancel item movement by returning false.
buyItemObserve or cancel a shop purchase by returning false.
usingItemObserve or cancel item use by returning false.
throwItemObserve 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.