jaksam_inventory/_hooks folder.
Best Practices
Use filters
Always use appropriate filters to avoid unnecessary hook executions
Early returns
Use early returns to exit hooks when conditions aren’t met
Performance
Keep hook logic lightweight to avoid impacting inventory performance
Use Case Examples
- Prevent players from stealing items that have the
sole_ownermetadata field (e.g., VIP items) - Prevent players from moving police weapons into their personal inventory
- Allow only one backpack per player inventory
- Crafting items by dragging a specific item over another item (for example dragging bread on meat can make a sandwich)
- Block item usage when player is handcuffed or in specific zones
- Track item usage statistics and achievements
- Prevent using certain items while in vehicles
- Add starter items to new player inventories when they are created
- Pre-populate dumpsters or stashes with random items on creation
API Functions
Register a Hook
Parameters
Return value
Unregister a Hook
Parameters
Unregister All Resource Hooks
Parameters
Options Parameter
The options parameter accepts a table with filters to optimize performance.- Common (all events)
- Inventory filters
- Transfer filters
Available Hook Events
Hook Behavior
Priority
Higher numbers execute first (default: 0)
Return values
return nil or return true: allow the action to continue.return false, "message", "notifyType": prevents the action and stops further hook execution. The message and notifyType parameters are optional (notifyType can be "error", "success", "info")Exception -
onPreOpenInventory: the message is not shown to the player, because the preload would make it repeat. Call notifyPlayer from inside the hook if you want to tell the player why.ox_inventory Compatibility
When the ox_inventory compatibility resource is installed,exports.ox_inventory:registerHook(...) is translated to the native hooks above, so ox_inventory scripts work without changes. Payloads are reshaped to the ox format, and ox option names (itemFilter, typeFilter, inventoryFilter, print) are translated as well.
Registering an unsupported hook prints a warning and returns
nil instead of throwing.
Three differences to be aware of when migrating:
- An ox hook can only allow or block; it cannot provide a custom message or notification type. Use the native hooks for that
openInventoryinherits the stateless requirement described inonPreOpenInventory- Player inventories are identified differently. ox hooks receive the player’s server ID as a number (
inventoryId = 4), matching ox_inventory. Native hooks receive jaksam’s character identifier as a string (inventoryId = "char1:35030084..."). Every other inventory type uses the same string ID in both
