Hooks called by Inventory

Summary

Hooks

Called on the server the first time a character is loaded after it has been created, so that plugins can give it its starting items.
Called on the server before an item is moved to another slot of the inventory it is in.
Called on the server before an item is transferred from one inventory to another.
Called on the server before a player drops an item from an inventory into the world, once for every item of a dropped stack.
Called on the server to build the inventories of a player, every time their active character is set.
Called on the server right after an item has changed its inventory.
Called on the server once the items of a player's active character have been loaded from the database and put into the inventories of the player, which have been synchronized.
Called on the client when an fl_inventory_container panel has been set up to show an inventory next to those of the local player.
Called on the server when a player has closed the inventories that were opened for them, such as a container or the inventories of another player.
Called on the client when an fl_inventory panel has recreated its slots, which happens when it is set up and every time its inventory is synchronized.
Called on the client when an inventory has been received from the server.
Called on the server when an item has been put into an inventory by Inventory:add_item: when it is given, picked up, or loaded along with the inventories of a character.
Called on the server for every item that Inventory:give_item has created and added to an inventory, after OnItemAdded.
Called on the server after a player has moved items to an inventory slot by dragging them and the inventories have been synchronized.
Called on the server when an item has been taken out of an inventory by one of the take_ functions: when it is dropped, used up or taken away.
Called on the server when a player asks to move items to an inventory slot by dragging them, before anything is moved.
Called on the server when a player drops items by dragging them out of an inventory panel.
Called on the client when the local player presses one of the slot binds, slot1 and so on.
Called on the client when the local player clicks an inventory slot that has an item in it, to open the menu of the item.
Called on the server right before an item changes its inventory.

Hooks

AddDefaultItems(self, character)

server plugins/inventory/plugin/lib/sh_inventory.lua:454

Called on the server the first time a character is loaded after it has been created, so that plugins can give it its starting items. The inventories of the player exist and the items of the character are in them by then, so handlers give items with Player:give_item. It is run with Plugin.call, so gamemode functions do not receive it.

function PLUGIN:AddDefaultItems(owner, char)
  owner:give_item('bandage', 2)
end

Parameters

  • owner Player The player who has loaded the character
  • char Character The new character

Called from

Call sites

CanItemMove(item_obj, self, x, y)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:825

Called on the server before an item is moved to another slot of the inventory it is in. The Inventory plugin uses it to ask the can_move callback of the item and to keep items in disabled inventories where they are.

Parameters

  • item_obj Item The item that is being moved
  • inventory Inventory The inventory the item is in
  • x Number Column of the target slot; a free position is looked for when it is nil or out of bounds
  • y Number Row of the target slot

Returns

  • Boolean Return false to prevent the move
  • String Error phrase that Inventory:move_item then returns to its caller

Called from

Call sites

CanItemTransfer(item_obj, inventory, x, y)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:924

Called on the server before an item is transferred from one inventory to another. The Inventory plugin also runs it, without a target slot, before a player picks an item up from the world into one of their inventories. The Inventory plugin uses it to enforce what equipment slots, pockets, container items and disabled inventories accept, and to ask the can_transfer callback of the item.

Parameters

  • item_obj Item The item that is being transferred
  • inventory Inventory The inventory the item is being transferred to
  • x Number Column of the target slot; a free position is looked for when it is nil or out of bounds
  • y Number Row of the target slot

Returns

  • Boolean Return false to prevent the transfer
  • String Error phrase that Inventory:transfer_item then returns to its caller, or that the player who picks the item up is notified with

Called from

Call sites

CanPlayerDropItem(actor, item_obj)

server plugins/inventory/plugin/sv_hooks.lua:306

Called on the server before a player drops an item from an inventory into the world, once for every item of a dropped stack. The Items plugin uses it to ask the on_drop callback 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; the items of the stack that come after this one are not dropped either

Called from

Call sites

CreatePlayerInventories(self, inventories)

server plugins/inventory/plugin/lib/sh_inventory.lua:373

Called on the server to build the inventories of a player, every time their active character is set. Handlers create their inventories with Inventory.new and put them into inventories under the type of each one; the Inventory plugin adds the main inventory, the hotbar, the pockets and the equipment slots this way. Afterward every inventory in the table gets the player as its owner and receiver and the character as the holder of its items, the inventories are synchronized, and the items of the character are loaded into them.

function PLUGIN:CreatePlayerInventories(owner, inventories)
  local wallet = Inventory.new()
  wallet.title = 'Wallet'
  wallet.type = 'wallet'
  wallet:set_size(2, 1)
  inventories[wallet.type] = wallet
end

Parameters

  • owner Player The player the inventories are created for
  • inventories Map The inventories of the player, keyed by inventory type, to be filled in place

Called from

Call sites

ItemTransferred(item_obj, inventory, self)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:1025

Called on the server right after an item has changed its inventory. It is run in the same cases as PreItemTransfer: a transfer between two inventories, as here, a pickup from the world (without old_inventory, and only if the item did fit) and a drop or a removal after use (with nil as new_inventory).

Parameters

  • item_obj Item The item that has been moved
  • new_inventory Inventory The inventory the item is in now, or nil if it has left for the world or has been removed
  • old_inventory Inventory The inventory the item was in, or nil if it came from the world

Called from

Call sites

OnCharacterItemsLoaded(self, character, items)

server plugins/inventory/plugin/lib/sh_inventory.lua:426

Called on the server once the items of a player's active character have been loaded from the database and put into the inventories of the player, which have been synchronized. The Items plugin calls the on_loadout callbacks of the items here if the player is alive.

Parameters

  • owner Player
  • character Character the active character of the player
  • items List<Item> the items of the character, along with the contents of its container items

Call sites

OnContainerOpened(self, inventory_id)

client plugins/inventory/plugin/views/cl_inventory_container.lua:143

Called on the client when an fl_inventory_container panel has been set up to show an inventory next to those of the local player. It is not run when the panel shows the inventories of another player.

Parameters

Called from

Call sites

OnInventoryClosed(self, closed_inventory)

server plugins/inventory/plugin/sv_hooks.lua:678

Called on the server when a player has closed the inventories that were opened for them, such as a container or the inventories of another player. The player has been removed from the receivers of every closed inventory by now. The hook is run once per request, with the first of the closed inventories; the player's own inventories and inventories that do not exist or were not open for the player are skipped, and the hook is not run when none is left. Player:close_inventories runs the same hook when the server closes inventories for a player, which it does by itself once the player is no longer entitled to them.

Parameters

  • actor Player The player who closed the inventories
  • inventory Inventory The first of the inventories that were closed

Called from

Call sites

OnInventoryRebuild(self)

client plugins/inventory/plugin/views/cl_inventory.lua:372

Called on the client when an fl_inventory panel has recreated its slots, which happens when it is set up and every time its inventory is synchronized. Handlers can use it to resize the panel or to attach their own panels to it.

Parameters

Called from

Call sites

OnInventorySync(inventory)

client plugins/inventory/plugin/cl_hooks.lua:172

Called on the client when an inventory has been received from the server. The local copy of the inventory has been updated by now and its panel, if it has one, has been rebuilt.

Parameters

  • inventory Inventory The inventory that has been updated

Call sites

OnItemAdded(item_obj, self, x, y)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:650

Called on the server when an item has been put into an inventory by Inventory:add_item: when it is given, picked up, or loaded along with the inventories of a character. It is not run when an item arrives from another inventory through Inventory:transfer_item.

Parameters

  • item_obj Item The item that has been added
  • inventory Inventory The inventory the item is in now
  • x Number Column of the slot the item has been placed in
  • y Number Row of the slot the item has been placed in

Called from

Call sites

OnItemGiven(item_obj, self, data)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:703

Called on the server for every item that Inventory:give_item has created and added to an inventory, after OnItemAdded.

Parameters

  • item_obj Item The new item instance
  • inventory Inventory The inventory the item has been added to
  • data Map The fields that were overridden on the item, or nil if there are none

Called from

Call sites

OnItemMoved(actor, item_obj, instance_ids, inventory_id, x, y)

server plugins/inventory/plugin/sv_hooks.lua:622

Called on the server after a player has moved items to an inventory slot by dragging them and the inventories have been synchronized. It is not run when the items could not be moved or when PlayerCanMoveItem has prevented the move.

Parameters

  • actor Player The player who moved the items
  • item_obj Item The first of the items
  • instance_ids List<Number> Instance ids of the items
  • inventory_id Number Id of the inventory the items were moved to
  • x Number Column of the target slot
  • y Number Row of the target slot

Call sites

Called on the server when an item has been taken out of an inventory by one of the take_ functions: when it is dropped, used up or taken away. The item no longer has its inventory_id, inventory_type, x and y fields at this point. It is not run when an item leaves for another inventory through Inventory:transfer_item.

Parameters

  • item_obj Item The item that has been taken
  • inventory Inventory The inventory the item was in

Called from

Call sites

PlayerCanMoveItem(actor, item_obj, instance_ids, inventory_id, x, y)

server plugins/inventory/plugin/sv_hooks.lua:591

Called on the server when a player asks to move items to an inventory slot by dragging them, before anything is moved. The target can be the inventory the items are in or another one. Requests that name items or inventories that do not exist, the same item twice, items from more than one inventory, an inventory that is not open for the player or that they are no longer entitled to, or a slot that is not a number are dropped before the hook is run, and so are the requests of a player who is dead or lies on the ground as a ragdoll.

Parameters

  • actor Player The player moving the items
  • item_obj Item The first of the items that are being moved
  • instance_ids List<Number> Instance ids of the items: one item, or several from the same stack
  • inventory_id Number Id of the inventory the items are being moved to
  • x Number Column of the target slot
  • y Number Row of the target slot

Returns

  • Boolean Return false to prevent the move

Call sites

PlayerDropItem(actor, stack)

server plugins/inventory/plugin/sv_hooks.lua:647

Called on the server when a player drops items by dragging them out of an inventory panel. The hook is what performs the drop: the Inventory plugin handles it by taking the items out of their inventory and spawning them in front of the player. Requests that name items that do not exist, the same item twice, items from more than one inventory, or an inventory that is not open for the player or that they are no longer entitled to are dropped before the hook is run, and so are the requests of a player who is dead or lies on the ground as a ragdoll. The Items plugin runs the same hook with a single instance id instead of a list when a player uses the drop option of an item's menu, so a handler has to accept both.

Parameters

  • actor Player The player dropping the items
  • instance_ids List<Number> Instance ids of the items, all from one inventory

Call sites

PlayerSelectSlot(client, n)

client plugins/inventory/plugin/sh_hooks.lua:22

Called on the client when the local player presses one of the slot binds, slot1 and so on. The Inventory plugin handles it by selecting the weapon of the item in that hotbar slot, or using the item. It is run with Plugin.call, so gamemode functions do not receive it.

Parameters

  • client Player The local player
  • slot Number Number of the slot taken from the bind

Called from

Call sites

PlayerUseItemMenu(self.instance_ids[#self.instance_ids])

client plugins/inventory/plugin/views/cl_inventory_item.lua:233

Called on the client when the local player clicks an inventory slot that has an item in it, to open the menu of the item. The Items plugin handles the hook by building the menu; it also runs the hook itself, with true as a second argument, for items that lie in the world.

Parameters

  • instance_id Number Instance id of the item; the last one of the stack if the slot holds several items

Called from

Call sites

PreItemTransfer(item_obj, inventory, self)

server plugins/inventory/plugin/lib/classes/sh_inventory.lua:971

Called on the server right before an item changes its inventory. Besides a transfer between two inventories, as here, the Inventory plugin runs it when a player picks an item up from the world (without old_inventory, and only if the item fits) and when an item is dropped or removed after use (with nil as new_inventory). The Inventory plugin uses it to call the on_transfer callback of the item, which is how equipable items get equipped and unequipped.

Parameters

  • item_obj Item The item that is about to be moved
  • new_inventory Inventory The inventory the item goes to, or nil if it leaves for the world or is removed
  • old_inventory Inventory The inventory the item is in, or nil if it comes from the world

Called from

Call sites

Defined in