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
Functions
Methods
Hooks
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
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
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:443Implements 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:105Implements 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:363Implements 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:90Implements 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
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:189Implements 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
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.
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
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
Implements hook OnItemCreated
Marks the item instance that has just been created as not rotated.
Parameters
- item_obj Item
Implements hook OnItemEquipped
Tells the client to rebuild the player model preview when a wearable item is equipped.
Parameters
- owner Player
- item_obj Item
Implements hook OnItemUnequipped
Tells the client to rebuild the player model preview when a wearable item is unequipped.
Parameters
- owner Player
- item_obj Item
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:122Implements 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
Calls the 'PlayerSelectSlot' plugin hook when the player presses one of the slot binds.
Parameters
- client Player
- bind String
- pressed Boolean
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
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
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
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
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:336Implements 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
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
Implements hook PopulateSpawnMenu
Adds the items tab to the spawn menu.
Inventories:PostCreateCharacter(_owner, char, _char_data)
server plugins/inventory/plugin/sv_hooks.lua:62Implements 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
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:352Implements 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
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
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
nilthe player whose character the items belong to
Returns
- List<Item> the items that did not fit anywhere
Methods
Creates a panel for the local player's hotbar at the bottom of the screen.
Returns
- Panel the fl_inventory panel
Shows the hotbar for a short time, fading it out gradually. Makes the hotbar fully opaque again if it is on the screen already.