Hooks

Event hooks allow external resources to set new behavior without directly altering the inventory code.

registerHook

exports.origen_inventory:registerHook(eventName, function(payload) end, options)
Argument
Type
Options

eventName

string

specific event

payload

table

specific response

options?

table

options.print?

boolean

Print to the console when triggering the event.

options.itemFilter?

{ [string]: true }

The event will only trigger for items defined as keys in a set.

options.inventoryFilter?

string[]

The event will only trigger for inventories that match one of the patterns(opens in a new tab) in the array.

options.typeFilter?

[string]: true }

The event will only trigger for inventories with one of the provided types (e.g. 'player', 'stash')

Argument mark with ' ? ' is optional.

Return:

  • hookId: number

Hook: swapItems

  • Payload: table

    • source: number

    • action: 'move' or 'stack' or 'swap' or 'give'

    • fromInventory: table or string or number

    • toInventory: table or string or number

    • fromType: string

    • toType: string

    • fromSlot: table

    • toSlot?: table or number

    • count: number

    Triggered when moving any item from one slot to another, or when "giving" an item. By returning false, you can cancel the action and revert the inventory state.

Hook: openInventory

  • Payload: table

    • source: number

    • inventoryId: number or string

    • inventoryType: string

    Triggered when a player tries to open a secondary inventory. By returning false, you can cancel the action and keep the player's inventory closed.

Example

Disables gloveboxes and trunks.

Hook: giveItem

Payload: table

  • source: number

  • fromInventory: table or string or number

  • toInventory: table or string or number

  • fromType: string

  • toType: string

  • fromSlot: table

  • toSlot?: table or number

  • count: number

Triggered when a player tries to give item to other player. By returning false, you can cancel the action and keep the player's inventory closed.

Hook: buyItem

  • Payload: table

    • source: number

    • shopType: string

    • shopId: number

    • toInventory: number

    • toSlot: number

    • itemName: string

    • metadata: table

    • count: number

    • price: number

    • totalPrice: number

    • currency?: string

    Triggered when an item is about to be purchased and can return false to prevent the transaction.

Hook: createDrop

Payload: table

  • source: number

  • action: 'move'

  • fromInventory: 'player'

  • toInventory: 'drop'

  • fromType: string

  • toType: 'drop'

  • fromSlot: table

  • toSlot: table

  • count: number

Triggered when an item is about to be dropped and can return false to prevent the action.

removeHooks

Removes a hook created by the invoking resource with the specified ID. If no ID is specified, then all hooks registered by the resource are removed.

  • id?: number

Soon

craftItem, createItem ⌛

Last updated