Shared hooks of the Inventory plugin: turns the slot binds into the PlayerSelectSlot hook, which selects the weapon of the item in that hotbar slot or uses the item.

Summary

Hooks

Adds the inventory to the tab menu, if the player has inventories.
Prevents opening the menu of items that are stored inside of container items.
Checks whether the item can be moved inside of the inventory: asks the can_move callback of the item and prevents moving items in disabled inventories.
Checks whether the item can be transferred to the inventory: equipment and pockets restrictions, the can_transfer callback of the item, the can_contain callback of the container the inventory belongs to, and whether the inventory is disabled.
Creates the default set of the player's inventories: main inventory, hotbar, pockets and the equipment slots.
Closes the inventory of a transferred container item for the players who were viewing it and do not have the container anymore.
Unloads the items of the character that the player drops, takes its inventories away from the player, leaving them without inventories as they were before they loaded a character, and tells their client to forget its copies of them.
Unloads the items of the player's previous character, if they had one, and recreates their inventories for the new character, which loads its items.
Deletes the items of a character that is about to be deleted.
Removes the hotbar when the context menu closes.
Shows the hotbar and makes it interactive while the context menu is open, if the player has one; a player without a character, such as a gamemaster in gamemaster mode, has none.
Closes, once a second, every inventory for the receivers who are no longer entitled to it, so that staying a receiver does not depend on the client reporting that it has closed the window.
Keeps the pockets panel no wider than the main inventory panel of the local player shown in the same view, if there is one.
Marks the item instance that has just been created as not rotated.
Tells the client to rebuild the player model preview when a wearable item is equipped.
Tells the client to rebuild the player model preview when a wearable item is unequipped.
Puts the contents of the container items of the map into the inventories of their container items once the items of the map have been loaded.
Closes the windows of all opened container items when a tab menu panel opens.
Calls the 'PlayerSelectSlot' plugin hook when the player presses one of the slot binds.
Unloads the items of the disconnected player's character and deletes their inventories from the server cache.
Takes the items out of their inventory and spawns them in front of the player.
Selects the weapon of the item in the specified hotbar slot, or uses the item if it is not an equipable one.
Puts an item lying in the world into one of the player's inventories and removes its entity.
Takes the equipped throwable items away from the player who has thrown a grenade.
Synchronizes the inventory of an item after a menu action has been performed on it.
Calls the on_use callback of the item, then takes the item out of its inventory and removes it, along with its entity if it lies in the world, unless the callback returned true to keep it or false to cancel the use.
Adds the items tab to the spawn menu.
Marks a character that has just been created as one that still has to get its starting items, which happens the first time it is loaded.
Adds the position of the item in its inventory and its rotation to what a client is sent about the item.
Calls the on_transfer callback of the item before it changes its inventory.

Functions

all()shared
Returns all the inventory classes currently loaded on the server.
find(id)shared
Finds a specific inventory by its id.
Checks whether a player is close enough to an entity to use an inventory that belongs to it: the player has to be alive, and the nearest point of the entity's bounds has to be within 128 units of their eyes.
Puts items that have been loaded from the database where they belong: items inside of a container item into the inventory of the container item, which is created if needed, and items of a character into the inventory of the player of the type they were saved in, or into the default inventory if the player has no such inventory.

Methods

Creates a panel for the local player's hotbar at the bottom of the screen.
Shows the hotbar for a short time, fading it out gradually.
Fills the items tab of the spawn menu with a node for every item category.

Hooks

Inventories:AddTabMenuItems(menu)

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

Implements hook AddTabMenuItems

Adds the inventory to the tab menu, if the player has inventories. A player without a character, such as a gamemaster in gamemaster mode, has none; the inventory is then also forgotten as the page to reopen, since the tab menu expects the page it reopens to exist.

Parameters

  • menu Panel the tab menu

Inventories:CanItemMenuOpen(item_obj)

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

Implements hook CanItemMenuOpen

Prevents opening the menu of items that are stored inside of container items.

Parameters

  • item_obj Item

Returns

  • Boolean false to prevent the menu from opening, nil otherwise

Inventories:CanItemMove(item_obj, inventory, x, y)

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

Implements hook CanItemMove

Checks whether the item can be moved inside of the inventory: asks the can_move callback of the item and prevents moving items in disabled inventories.

Parameters

  • item_obj Item
  • inventory Inventory
  • x Number target slot
  • y Number target slot

Returns

  • Boolean false to prevent the move
  • String text of the error; nothing to allow it

Inventories:CanItemTransfer(item_obj, inventory, x, y)

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

Implements hook CanItemTransfer

Checks whether the item can be transferred to the inventory: equipment and pockets restrictions, the can_transfer callback of the item, the can_contain callback of the container the inventory belongs to, and whether the inventory is disabled.

Parameters

  • item_obj Item
  • inventory Inventory the inventory the item is being transferred 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
  • String text of the error; nothing to allow it

Inventories:CreatePlayerInventories(_owner, inventories)

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

Implements hook CreatePlayerInventories

Creates the default set of the player's inventories: main inventory, hotbar, pockets and the equipment slots.

Parameters

  • _owner Player
  • inventories Map table to put the new inventories into, keyed by inventory type

Inventories:ItemTransferred(item_obj, _new_inventory, _old_inventory)

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

Implements hook ItemTransferred

Closes the inventory of a transferred container item for the players who were viewing it and do not have the container anymore.

Parameters

  • item_obj Item
  • _new_inventory Inventory where the item went, or nil if it was dropped or used up
  • _old_inventory Inventory where the item was, or nil if it was picked up

Inventories:OnActiveCharacterCleared(owner, _character)

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

Implements hook OnActiveCharacterCleared

Unloads the items of the character that the player drops, takes its inventories away from the player, leaving them without inventories as they were before they loaded a character, and tells their client to forget its copies of them.

Parameters

  • owner Player
  • _character Character the character that is being dropped

Inventories:OnActiveCharacterSet(owner, _character)

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

Implements hook OnActiveCharacterSet

Unloads the items of the player's previous character, if they had one, and recreates their inventories for the new character, which loads its items.

Parameters

  • owner Player
  • _character Character

Inventories:OnCharacterDelete(_actor, id, _character)

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

Implements hook OnCharacterDelete

Deletes the items of a character that is about to be deleted.

Parameters

  • _actor Player
  • id Number ID of the character
  • _character Character

Inventories:OnContextMenuClose()

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

Removes the hotbar when the context menu closes.

Inventories:OnContextMenuOpen()

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

Shows the hotbar and makes it interactive while the context menu is open, if the player has one; a player without a character, such as a gamemaster in gamemaster mode, has none.

Inventories:OneSecond()

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

Implements hook OneSecond

Closes, once a second, every inventory for the receivers who are no longer entitled to it, so that staying a receiver does not depend on the client reporting that it has closed the window. The inventories that one entity owns are closed for a receiver together, so that the 'OnInventoryClosed' hook runs once when, for example, a player walks away from another player whose inventories they were viewing.

See also

Inventories:OnInventoryRebuild(panel)

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

Implements hook OnInventoryRebuild

Keeps the pockets panel no wider than the main inventory panel of the local player shown in the same view, if there is one.

Parameters

  • panel Panel the fl_inventory panel that has been rebuilt

Inventories:OnItemCreated(item_obj)

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

Implements hook OnItemCreated

Marks the item instance that has just been created as not rotated.

Parameters

  • item_obj Item

Inventories:OnItemEquipped(owner, item_obj)

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

Implements hook OnItemEquipped

Tells the client to rebuild the player model preview when a wearable item is equipped.

Parameters

  • owner Player
  • item_obj Item

Inventories:OnItemUnequipped(owner, item_obj)

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

Implements hook OnItemUnequipped

Tells the client to rebuild the player model preview when a wearable item is unequipped.

Parameters

  • owner Player
  • item_obj Item

Inventories:OnMapItemsLoaded(items)

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

Implements hook OnMapItemsLoaded

Puts the contents of the container items of the map into the inventories of their container items once the items of the map have been loaded. Contents that do not fit are unloaded again.

Parameters

  • items List<Item>

Inventories:OnMenuPanelOpen(_menu_panel, _active_panel)

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

Implements hook OnMenuPanelOpen

Closes the windows of all opened container items when a tab menu panel opens.

Parameters

  • _menu_panel Panel the tab menu
  • _active_panel Panel the panel that has been opened

Inventories:PlayerBindPress(client, bind, pressed)

shared plugins/inventory/plugin/sh_hooks.lua:10

Calls the 'PlayerSelectSlot' plugin hook when the player presses one of the slot binds.

Parameters

  • client Player
  • bind String
  • pressed Boolean

Inventories:PlayerDisconnected(actor)

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

Implements hook PlayerDisconnected

Unloads the items of the disconnected player's character and deletes their inventories from the server cache. The items are unloaded on the next tick, once the character has been saved.

Parameters

  • actor Player

Inventories:PlayerDropItem(actor, instance_ids)

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

Implements hook PlayerDropItem

Takes the items out of their inventory and spawns them in front of the player. Does nothing if the first item does not exist, is not in an inventory or its inventory is disabled; stops at the first item that is not in that inventory. An item that a 'PreItemTransfer' handler takes out of the inventory by itself is not spawned.

Parameters

  • actor Player
  • instance_ids Number/List<Number> instance id(s) of items from the same inventory

Inventories:PlayerSelectSlot(client, slot)

shared plugins/inventory/plugin/sh_hooks.lua:32

Implements hook PlayerSelectSlot

Selects the weapon of the item in the specified hotbar slot, or uses the item if it is not an equipable one. Switches to fists if the slot is empty. Does nothing for a player without a hotbar, such as a gamemaster in gamemaster mode.

Parameters

  • client Player
  • slot Number hotbar slot from 1 to 8

Inventories:PlayerTakeItem(actor, item_obj, ...)

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

Implements hook PlayerTakeItem

Puts an item lying in the world into one of the player's inventories and removes its entity. Nothing happens if the player has no inventory of the requested type; the player is notified if the 'CanItemTransfer' hook refuses the inventory or the item does not fit.

Parameters

  • actor Player
  • item_obj Item
  • ... Vararg optional hashes; an inv_type field in one of them sets the inventory type

Inventories:PlayerThrewGrenade(actor, _entity)

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

Implements hook PlayerThrewGrenade

Takes the equipped throwable items away from the player who has thrown a grenade.

Parameters

  • actor Player
  • _entity Entity the grenade

Inventories:PlayerUsedItem(_actor, item_obj, _act, ...)

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

Implements hook PlayerUsedItem

Synchronizes the inventory of an item after a menu action has been performed on it.

Parameters

  • _actor Player
  • item_obj Item
  • _act String name of the menu action
  • ... Vararg extra arguments of the action

Inventories:PlayerUseItem(actor, item_obj, ...)

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

Implements hook PlayerUseItem

Calls the on_use callback of the item, then takes the item out of its inventory and removes it, along with its entity if it lies in the world, unless the callback returned true to keep it or false to cancel the use.

Parameters

  • actor Player
  • item_obj Item
  • ... Vararg extra arguments of the action

Returns

  • Boolean false if the use was canceled, nil otherwise

Inventories:PopulateSpawnMenu()

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

Implements hook PopulateSpawnMenu

Adds the items tab to the spawn menu.

Inventories:PostCreateCharacter(_owner, char, _char_data)

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

Implements hook PostCreateCharacter

Marks a character that has just been created as one that still has to get its starting items, which happens the first time it is loaded.

Parameters

  • _owner Player
  • char Character
  • _char_data Map data the character was created from

Inventories:PreItemNetwork(item_obj, fields)

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

Implements hook PreItemNetwork

Adds the position of the item in its inventory and its rotation to what a client is sent about the item.

Parameters

  • item_obj Item
  • fields Map fields of the item that are going to be sent

Inventories:PreItemTransfer(item_obj, new_inventory, old_inventory)

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

Implements hook PreItemTransfer

Calls the on_transfer callback of the item before it changes its inventory.

Parameters

  • item_obj Item
  • new_inventory Inventory where the item goes, or nil if it is dropped or used up
  • old_inventory Inventory where the item was, or nil if it is picked up

Functions

Returns all the inventory classes currently loaded on the server.

Returns

  • Map inventories

Finds a specific inventory by its id.

Parameters

  • id Number

Returns

  • Inventory

Inventories.is_in_reach(actor, entity)

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

Checks whether a player is close enough to an entity to use an inventory that belongs to it: the player has to be alive, and the nearest point of the entity's bounds has to be within 128 units of their eyes. Server-side only.

Parameters

  • actor Player
  • entity Entity

Returns

  • Boolean false if the entity is invalid, too far away, or the player is dead

Inventories.place_items(items, owner)

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

Puts items that have been loaded from the database where they belong: items inside of a container item into the inventory of the container item, which is created if needed, and items of a character into the inventory of the player of the type they were saved in, or into the default inventory if the player has no such inventory. Items that already are in an inventory and items that belong elsewhere are skipped. Server-side only.

Parameters

  • items List<Item>
  • owner Player optional, defaults to nil the player whose character the items belong to

Returns

  • List<Item> the items that did not fit anywhere

Methods

Inventories:create_hotbar()

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

Creates a panel for the local player's hotbar at the bottom of the screen.

Returns

  • Panel the fl_inventory panel

Inventories:spawnmenu_populate_items(content_panel, tree, _node)

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

Fills the items tab of the spawn menu with a node for every item category.

Parameters

  • content_panel Panel the content panel of the tab
  • tree Panel the navigation tree of the tab
  • _node Panel

Defined in