Hooks hooks
Part of Items System
Hooks called by Items System
Summary
Hooks
on_entity_destroyed callback of its item.on_entity_take_damage callback of its item.Item.create has created a new item instance.post_equipped callback.post_unequipped callback.drop_weapons_on_death config is on.PlayerCanUseItem.PlayerCanUseItem.PlayerCanUseItem.PlayerCanUseItem.Hooks
Called on the client before the menu of an item is opened.
Parameters
- item_obj Item The item instance the menu is for
Returns
- Boolean Return false to prevent the menu from opening
Called from
Call sites
Called on the server before an item is dropped from an inventory into the world.
The Items plugin runs it here for every equipped weapon item of a dying player
that PlayerCanDropWeaponOnDeath has let go of; the Inventory plugin runs it when
a player drops items. The Items plugin handles it by asking the on_drop callback
of the item and by naming the player as the dropper of the item.
Parameters
- actor Player The player dropping the item
- item_obj Item The item that is about to be dropped
Returns
- Boolean Return false to prevent the drop
Called from
Call sites
ItemEntityDestroyed(self, item_obj, damage_info)
server plugins/items/plugin/entities/entities/fl_item.lua:252Called on the server when an item lying in the world has been destroyed by
damage, after the on_entity_destroyed callback of its item. The entity and the
item instance still exist at this point; both are removed right afterward.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance that is being destroyed
- damage_info CTakeDamageInfo The damage that has destroyed the item, or nil if the entity was destroyed by a direct call to its
destroymethod
Called from
Call sites
ItemEntityTakeDamage(self, item_obj, damage_info)
server plugins/items/plugin/entities/entities/fl_item.lua:213Called on the server when an item entity takes damage, after the
on_entity_take_damage callback of its item. Handlers can change the damage
through damage_info. It is run for every item entity, but the damage only takes
health off those that are destructible (entity:is_destructible()). The Items
plugin uses it to keep container items that have something inside from being
damaged.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance tied to the entity
- damage_info CTakeDamageInfo The damage
Returns
- Boolean Return false to ignore the damage
Called from
Call sites
Called on the server right after an item has left its inventory for good: here when a player has destroyed it, in which case the instance is removed right afterward, and also when a dying player has dropped an equipped weapon item, before its entity is spawned. The Inventory plugin runs the same hook for every other transfer.
Parameters
- item_obj Item The item that has left
- new_inventory Inventory Always nil here
- old_inventory Inventory The inventory the item was in
Called from
Call sites
Called on the server after an item instance has been tied to an item entity.
The entity has the model, skin and color of the item by now, and the clients that
know the item have been told which item it represents. When the item is being
spawned by Item.spawn, the entity itself has not been positioned or spawned yet.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance that has been set
Called from
Call sites
Called on the server when Item.create has created a new item instance.
At this point the instance has its instance id and the overridden fields, but it
has not been saved or sent to any client yet and it is not in any inventory.
The Items plugin uses the hook to call the on_created callback of the item.
It is not run for the instances that are loaded from the database.
Parameters
- item_obj Item The new item instance
Called from
Call sites
Called when an equipable item has been equipped, after its post_equipped callback.
This happens on the server when the item is about to enter its equipment inventory
(the transfer itself has not been made yet), and every time its owner spawns while
it is equipped.
Parameters
- owner Player The player who has the item
- item_obj Item The equipped item
Called from
Call sites
Called when an equipable item has been unequipped, after its post_unequipped
callback. This happens on the server when the item is about to leave its equipment
inventory: it is moved to another inventory, dropped or removed after use.
Parameters
- owner Player The player who has the item
- item_obj Item The unequipped item
Called from
Call sites
Called on the server once the items of the current map have been loaded from the database, after those that lie in the world have been spawned. Handlers put the other items where they belong: the Containers plugin claims the items of its container props, and the Inventory plugin puts the contents of container items into the inventories of their containers.
Parameters
- items List<Item> The loaded instances, the contents of container items among them
Call sites
Called on the server before a player destroys an item from an inventory through
the menu of the item. The Items plugin uses it to refuse equipped items that their
can_unequip callback does not let go of, and container items that are not empty.
The on_destroy callback of the item is asked afterward, if no handler has refused.
Parameters
- actor Player The player destroying the item
- item_obj Item The item that is about to be destroyed
Returns
- Boolean Return false to prevent the destruction
- String Error phrase to notify the player with
Called from
Call sites
Called on the server before an equipped weapon item of a dying player is dropped
into the world, which happens when the drop_weapons_on_death config is on. The
CanPlayerDropItem hook, and with it the on_drop callback of the item, is asked
afterward.
Parameters
- victim Player The player who is dying
- item_obj Item The equipped weapon item
Returns
- Boolean Return false to leave the item in the inventory of the player
Called from
Call sites
Called on the server before a player performs any menu action on an item: using, taking, dropping or destroying it, or pressing one of its custom buttons. The Items plugin uses it to reject actions on items the player does not have and on items in the world that are out of reach.
Parameters
- actor Player The player performing the action
- item_obj Item The item instance
- act String Name of the action:
'on_use','on_take','on_drop','on_destroy'or the callback of a custom button - ... Vararg Extra arguments that were passed to
ItemBase:do_menu_action
Returns
- Boolean Return false to prevent the action
Called from
Call sites
Called on the server when a player consumes a consumable item. This is the place to apply the effect of the item: the base class does nothing else with it. The item is removed from the inventory afterward.
Parameters
- actor Player The player consuming the item
- item_obj Item The consumable item
Called from
Call sites
Called on the server after a player has destroyed an item through its menu. The
item has been taken out of its inventory and its instance has been removed by now,
so item_obj is only good for looking at what the item was.
Parameters
- actor Player The player who destroyed the item
- item_obj Item The destroyed item
Called from
Call sites
Called on the server when a player destroys an item through its menu, after
PlayerCanUseItem. The hook is what performs the action: the Items plugin
handles it by asking the PlayerCanDestroyItem hook and the on_destroy callback
of the item, taking the item out of its inventory and removing the instance for
good. Only items that are in an inventory can be destroyed this way; the client
asks the player to confirm before it sends the request.
Parameters
- actor Player The player destroying the item
- item_obj Item The item instance
- ... Vararg Extra arguments that were passed to
ItemBase:do_menu_action
Returns
- Any Any value other than nil ends the action right there: the action sound is not played and
PlayerUsedItemis not run. The Items plugin returns false when the item has not been destroyed
Called from
Call sites
Called on the server when a player drops an item through its menu, after
PlayerCanUseItem. The hook is what performs the action: the Inventory plugin
handles it by taking the item out of its inventory and spawning it in front of
the player. The Inventory plugin also runs this hook itself, with a list of
instance ids instead of a single one, when items are dragged out of an inventory
panel.
Parameters
- actor Player The player dropping the item
- instance_id Number Instance id of the item
Returns
- Any Any value other than nil ends the action right there: the action sound is not played and
PlayerUsedItemis not run
Called from
Call sites
Called on the server after an equipped weapon item of a dying player has been taken out of their inventory and dropped into the world.
Parameters
- victim Player The player who is dying
- item_obj Item The weapon item
- entity Entity The
fl_itementity the item lies in the world as
Called from
Call sites
Called on the server when a player takes an item, after PlayerCanUseItem.
The hook is what performs the action: the Inventory plugin handles it by putting
an item that lies in the world into one of the player's inventories.
Parameters
- actor Player The player taking the item
- item_obj Item The item instance
- ... Vararg Extra arguments of the action; a table with an
inv_typefield names the inventory type the item should go to
Returns
- Any Any value other than nil ends the action right there: the action sound is not played and
PlayerUsedItemis not run
Called from
Call sites
Called on the server when a frag grenade has been thrown.
It runs on the next tick after an npc_grenade_frag entity is created. The
Inventory plugin uses it to take the equipped throwable item away from the
thrower.
Parameters
- owner Entity The owner of the grenade, normally the player who threw it; it is not checked for validity and is not necessarily a player
- entity Entity The grenade
Call sites
Called on the server after a player has performed a menu action on an item.
It is not run when the action was rejected by PlayerCanUseItem or ended by a
handler of PlayerTakeItem, PlayerUseItem, PlayerDropItem or
PlayerDestroyItem. After the 'on_destroy' action the item is a removed instance.
Parameters
- actor Player The player who performed the action
- item_obj Item The item instance
- act String Name of the action:
'on_use','on_take','on_drop','on_destroy'or the callback of a custom button - ... Vararg Extra arguments that were passed to
ItemBase:do_menu_action
Called from
Call sites
Called on the server when a player uses an item, after PlayerCanUseItem.
The hook is what performs the action: the Inventory plugin handles it by calling
the on_use callback of the item and removing the item afterward, unless the
callback returns true to keep it. It returns false when the callback cancels the
use.
Parameters
- actor Player The player using the item
- item_obj Item The item instance
- ... Vararg Extra arguments that were passed to
ItemBase:do_menu_action
Returns
- Any Any value other than nil ends the action right there: the action sound is not played and
PlayerUsedItemis not run
Called from
Call sites
PlayerUseItemEntity(caller, self, self.item)
server plugins/items/plugin/entities/entities/fl_item.lua:98Called on the server when a player briefly presses the use key on an item entity, releasing it in under half a second. Holding the key longer takes the item instead and does not run this hook. The Items plugin handles it by telling the client of the player to open the menu of the item.
Parameters
- activator Player The player who used the entity
- entity Entity The
fl_itementity - item_obj Item The item instance tied to the entity
Called from
Call sites
Called on the client to open the menu of an item. Here it is run when the server reports that the local player has pressed the use key on an item entity. The Inventory plugin runs it without the second argument when an inventory slot is clicked. The Items plugin itself handles the hook by building the menu.
Parameters
- instance_id Number Instance id of the item
- is_entity Boolean true if the item lies in the world, nil if it is in an inventory; decides between the take and the drop option
Call sites
PostDrawItemTargetID(self, item_obj, x, y, alpha, distance)
client plugins/items/plugin/entities/entities/fl_item.lua:482Called on the client every frame after the name and the description of an item entity have been drawn as its target ID. Handlers can draw more lines below them.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance tied to the entity
- x Number Screen x of the center of the target ID
- y Number Screen y right below the last line of the description
- alpha Number Opacity of the target ID from 0 to 255
- distance Number Distance between the local player and the entity
Called from
Call sites
PreDrawItemTargetID(self, item_obj, x, y, alpha, distance)
client plugins/items/plugin/entities/entities/fl_item.lua:407Called on the client every frame before the target ID of an item entity is drawn, while the local player looks at the entity from at most 150 units away.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance tied to the entity
- x Number Screen x of the center of the target ID
- y Number Screen y of the top of the target ID
- alpha Number Opacity of the target ID from 0 to 255; it fades out past 100 units
- distance Number Distance between the local player and the entity
Returns
- Boolean Return false to prevent the name and the description from being drawn;
PostDrawItemTargetIDis not run then
Called from
Call sites
Called on the server before an item instance is tied to an item entity, while the entity still has the model, skin and color it had before.
Parameters
- entity Entity The
fl_itementity - item_obj Item The item instance that is about to be set
Called from
Call sites
Lets plugins add fields to what a client is sent about an item instance. Called by
Item.to_networkable on the server whenever an instance is sent to a client. The
client builds its copy of the instance out of the template and these fields.
Handlers write their fields into fields; the Inventory plugin adds the position of
the item in its inventory.
Parameters
- item_obj Item The item that is being sent
- fields Map The fields that are going to be sent, to be modified in place
Called from
Call sites
Called on the server right before an item leaves its inventory for good: here when
a player destroys it, and also when a dying player drops their equipped weapon
items. The Inventory plugin runs the same hook for every other transfer and handles
it by calling the on_transfer callback of the item, which is how an equipped item
gets unequipped. A handler may take the item out of the inventory by itself.
Parameters
- item_obj Item The item that is about to leave
- new_inventory Inventory Always nil here: the item does not go to another inventory
- old_inventory Inventory The inventory the item is in
Called from
Call sites
PrePlayerConsumeItem(actor, self)
server plugins/items/plugin/items/bases/sh_item_consumables.lua:28Called on the server when a player uses a consumable item, before it is consumed.
Parameters
- actor Player The player using the item
- item_obj Item The consumable item
Returns
- Boolean Return false to keep
PlayerConsumeItemfrom being run. The item is removed from the inventory either way
Called from
Call sites
Defined in
- plugins/items/plugin/cl_hooks.lua
- plugins/items/plugin/sv_hooks.lua
- plugins/items/plugin/entities/entities/fl_item.lua
- plugins/items/plugin/lib/sh_item.lua
- plugins/items/plugin/items/bases/sh_item_equipable.lua
- plugins/items/plugin/lib/sv_storage.lua
- plugins/items/plugin/lib/classes/sh_item.lua
- plugins/items/plugin/items/bases/sh_item_consumables.lua