Hooks
Hooks let you gate an inventory action before it happens. Register a callback for a beforeX event, inspect the payload, optionally mutate it in place, and return false to cancel.
local id = exports.one_inventory:RegisterHook('beforeItemAdd', function(payload)
if payload.item == 'lockpick' and not isAllowed(payload.source) then
return false -- cancels the AddItem call
end
-- mutating in place is supported
payload.count = math.min(payload.count, 5)
end)
-- later
exports.one_inventory:RemoveHook(id)
false cancels the operation. Returning true, nil or nothing allows it. Callbacks run in registration order. Errors are caught and logged, they do not abort the chain.beforeItemAdd
Fires before an item is added to an inventory. Cancel to block the add.
nil for non-player inventories.payload.metadata; the add uses the mutated value.player, stash, trunk, ...).nil if the item is unknown.beforeItemRemove
Fires before an item is removed from an inventory. Cancel to block the removal.
nil for non-player inventories.beforeItemUse
Fires before a player uses or consumes an item. Cancel to block the use.
beforeItemSwap
Fires before an item swap between slots or between inventories. Cancel to block the swap.
nil when the target slot is empty.move (target empty), stack (same stackable item), or swap (different items).beforeShopPurchase
Fires before a shop purchase is finalised. Cancel to block the sale.
unitPrice * count).shopId.beforeShopOpen
Fires before a shop UI opens. Cancel to block the open.
shopId.beforeItemCraft
Fires before a craft begins. Cancel to block the craft.
bench.nil.nil at fire time.beforeItemDrop
Fires before an item is dropped on the ground. Cancel to block the drop.
beforeItemGive
Fires before a player-to-player item transfer. Cancel to block the give.
beforeItemSearch
Fires before a player frisks another player's inventory. Cancel to block the search.
beforeInventoryOpen
Fires before any inventory UI opens. Cancel to block the open.
player, stash, shop, crafting, drop, dumpster, vehicle:trunk, vehicle:glovebox).data.data.beforeInventoryClose
Fires before an inventory UI closes. Cancel to keep it open.
Exports
See RegisterHook and RemoveHook for the export signatures.
