Events
How to handle inventory events.
When working with events, the general rule is to add a callback once when the game starts. The same callback should never be added twice.
Inventory
Events available from Inventool.Inventory
.
onItemUsed
A callback for when an item is used. This accepts 1 argument: the item used (ItemStack).
onItemPickedUp
A callback for when an item is picked up. This accepts 1 argument: the item picked up (ItemStack).
onItemDropped
A callback for when an item is dropped. This accepts 1 argument: the item dropped (ItemStack).
onItemFailedToAdd
A callback for when an item failed to be added to the inventory. This accepts 2 arguments: the item failed to be added (ItemStack), the error type (InventoryError).
onItemEnchanted
A callback for when an item is enchanted. This accepts 2 arguments: the item enchanted (ItemStack), the item used to enchant (ItemStack).
onEnchantmentFailed
A callback for when an item has failed to enchant. This accepts 1 argument: the reason of failure (string).
onMaxWeightExceeded
A callback for when the weight limit is exceeded.
onMaxWeightExited
A callback for when the weight limit is exited.
onKeyItemsAdded
A callback for when a a key item is added to the inventory. This accepts 1 argument: the key item (ItemStack).
onItemsUpdated
A callback for when the item list is updated.
Equipment
Events available from Inventool.Equipment
.
onItemEquipped
A callback for when an item is equipped. This accepts 1 argument: the item equipped (ItemStack).
onItemUnequipped
A callback for when an item is unequipped. This accepts 1 argument: the item unequipped (ItemStack).
Inventool Window
Events available from InventoolWindow.Instance
you must have an instance of anInventool Window in your scene.
onSlotHovered
A callback for when a slot is hovered. This accepts 1 argument: the button which acts as a slot (Button).
onSlotClicked
A callback for when a slot is clicked. This accepts 1 argument: the button which acts as a slot (Button).
onButtonHovered
A callback for when a button is hovered. This accepts 1 argument: the button (Button).
onButtonClicked
A callback for when a button is clicked. This accepts 1 argument: the button (Button).
Merchant
Events available in the Merchant
class.
onActionFailed
A callback for when an action performed on any merchant fails. This accepts 2 arguments: the error type (MerchantError), the error message (string).
Crafter
Events available in the Crafter
class.
onCraftFailed
A callback for when a crafting fails. This accepts 1 argument: the error message (string).
onCraftSucceeded
A callback for when a crafting succeeds. This accepts 1 argument: the item crafted (ItemStack).
Shopkeeper
Events available in the Shopkeeper
class.
onItemSold
A callback for when an item is sold. This accepts 1 argument: the item sold (ItemStack).
onItemBought
A callback for when an item is bought. This accepts 1 argument: the item bought (ItemStack).
ItemDrop
Events available in the ItemDrop
class.
onEnteredPickUpRange
A callback for when the player enters the pick up range of any item drop.
onExitedPickUpRange
A callback for when the player exits the pick up range for all item drops.
Usage Examples
The method of registering a callback for all events is similar.
Item Equipping Example
Below is an example of how you can use events to equip/unequip items visually on your character model.
This method is the simplest way of handling this, but it's not great. It's recommended to somehow incorporate the custom object field that's available for all items.
Error Message Example
Below is an example of how you can use the Merchant.onActionFailed
event.
Inventool already handles these error messages by default. This is just here for learning purposes.
Last updated