Hooks

Event hooks allow 3rd party resources to define new behaviour without modifying the inventory code directly.

RegisterHook

exports["tgiann-inventory"]:RregisterHook(eventName, function(payload) end, options)
  • eventName: string

  • payload: table

  • options?: table

    • print?: boolean

      • Print to the console when triggering the event.

    • itemFilter?: { [string]: true }

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

    • inventoryFilter?: string[]

      • The event will only trigger for inventories that match one of the patterns in the array.

    • toInventoryFilter?: string[]

      • The event will only trigger for other(right Inventory) inventories that match one of the patterns in the array.

    • fromInventoryFilter?: string[]

      • The event will only trigger for player(left Inventory) inventories that match one of the patterns in the array.

    • typeFilter?: { [string]: true }

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

Return:

  • hookId: number


swapItems

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.

  • Payload: table

    • source: number

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

    • fromInventory: table or string or number

    • toInventory: table or string or number

    • fromType: string

    • toType: string

    • fromSlot: table

    • toSlot?: number

    • count: number

Example

Blacklists "water" from being moved into or from gloveboxes and trunks.


openInventory

  • Payload: table

    • source: number

    • inventoryId: string

    • inventoryType: string

Triggered when a player tries to open a secondary inventory.

Example


createItem

  • Payload: table

    • inventoryId?: number or string

    • metadata: table

    • item: table

    • count: number

Triggered when an item is created, either by buying it, using AddItem, or when converting inventory data.

Example


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

Example


usingItem

  • Payload: table

    • source: number

    • inventoryId: string

    • item: table

    • consume: table

Example

RemoveHooks

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

  • id?: number

Last updated