ItemEquipable is the base class for items that take effect while they are equipped,
such as weapons and clothing.
An item is equipped for as long as it sits in a particular inventory of the player. A
derived item sets equip_inv, the type of that inventory ('hotbar' by default), and
equip_slot, a slot name or a list of slot names: an item cannot be equipped while
another equipped item of that inventory has one of the same slot names. Optionally,
disabled_inventories lists the types of inventories that are emptied into the main
inventory and disabled while the item is equipped.
A derived item overrides post_equipped(owner) and post_unequipped(owner) to apply
and remove its effect, and can_equip(owner) and can_unequip(owner) to forbid either.
The base class adds the equip button to the menu of the item and reacts to inventory
transfers through its can_transfer and on_transfer callbacks, so that moving the
item into or out of its equipment inventory equips or unequips it. The
OnItemEquipped and OnItemUnequipped hooks tell other plugins about it.
Summary
Methods
Methods
Called by ItemEquipable:can_transfer before the item is equipped. Override it and return false to prevent the item from being equipped.
Parameters
- _owner Player the player who is about to wear the item: the owner of the equipment inventory it is being put into
Returns
- Boolean false to prevent equipping, nil otherwise
ItemEquipable:can_transfer(inventory, _x, _y)
shared plugins/items/plugin/items/bases/sh_item_equipable.lua:52Called on the server by the 'CanItemTransfer' hook before the item is moved to another inventory or picked up into one. Prevents equipping the item if can_equip disallows it for the owner of that inventory or its equipment slot is occupied, and prevents unequipping it if can_unequip disallows it.
Parameters
- inventory Inventory the inventory the item is being moved to
- _x Number target slot, or nil if the position is yet to be found
- _y Number target slot, or nil if the position is yet to be found
Returns
- Boolean false to prevent the transfer, nil otherwise
Called by ItemEquipable:can_transfer before the item is unequipped. Override it and return false to prevent the item from being unequipped.
Parameters
- _owner Player the player that has the item, or nil if no player has it
Returns
- Boolean false to prevent unequipping, nil otherwise
ItemEquipable:equip(owner, should_equip)
shared plugins/items/plugin/items/bases/sh_item_equipable.lua:118Applies or reverts the equipped state of the item; it does not move the item itself. Empties and disables (or enables back) the inventories listed in disabled_inventories, calls post_equipped or post_unequipped and runs the 'OnItemEquipped' or 'OnItemUnequipped' hook.
Parameters
- owner Player
- should_equip Boolean true to equip the item, false to unequip it
Checks whether the item is in the inventory that it gets equipped in.
Returns
- Boolean
Called on the server when a player presses the equip button in the item's menu. Moves the item to its equipment inventory, or back to the main inventory if it is equipped already. An item lying in the world is picked up and equipped.
Parameters
- owner Player
Called on the server right after the player that has the item spawns. Applies the equipped state again if the item is equipped.
Parameters
- owner Player
ItemEquipable:on_transfer(new_inventory, old_inventory)
shared plugins/items/plugin/items/bases/sh_item_equipable.lua:173Called on the server by the 'PreItemTransfer' hook when the item is about to change its inventory. Equips or unequips the item if it enters or leaves its equipment inventory.
Parameters
- new_inventory Inventory where the item goes, or nil if it is dropped
- old_inventory Inventory where the item was, or nil if it is picked up
ItemEquipable:post_equipped(_owner)
shared plugins/items/plugin/items/bases/sh_item_equipable.lua:104Called by ItemEquipable:equip when the item gets equipped. Override it to apply the effects of the item to the player.
Parameters
- _owner Player
ItemEquipable:post_unequipped(_owner)
shared plugins/items/plugin/items/bases/sh_item_equipable.lua:110Called by ItemEquipable:equip when the item gets unequipped. Override it to remove the effects of the item from the player.
Parameters
- _owner Player