ItemContainer is the base class for items that hold other items, such as bags. A derived item sets inventory_data, the settings of the inventory inside: width, height, type and optionally infinite_width and infinite_height; it is a 4x4 inventory of the 'item_container' type by default. default_inventory is an optional list of { id = ..., amount = ..., data = ... } entries that every new container is filled with.

The base class adds the open button to the menu of the item. The inventory is created when the container is opened for the first time, filled on creation, or when its contents are loaded from the database, and belongs to the item through its instance_id field. The contents are saved as being inside of the item, and are loaded and unloaded along with it. A derived item can override can_contain(item_obj) and return false to refuse an item, calling the base method to keep the container out of itself and out of the containers inside of it.

Summary

Methods

Called on the server by the 'CanItemTransfer' hook before an item is put into the container.
Creates the inventory that stores the contents of the container and puts it into the 'inventory' field of the item.
Returns the settings that the inventory of the container is created with.
Called on the server by the 'OnItemCreated' hook right after an instance of the item is created.
Called on the server when a player presses the open button in the item's menu.

Methods

ItemContainer:can_contain(item_obj)

shared plugins/inventory/plugin/items/bases/sh_item_container.lua:71

Called on the server by the 'CanItemTransfer' hook before an item is put into the container. Prevents the container from being put inside of itself, and a container item from being put inside of a container that it holds itself.

Parameters

  • item_obj Item the item that is being put into the container

Returns

  • Boolean false to prevent the transfer, nil otherwise

ItemContainer:create_inventory()

shared plugins/inventory/plugin/items/bases/sh_item_container.lua:93

Creates the inventory that stores the contents of the container and puts it into the 'inventory' field of the item.

ItemContainer:get_inventory_data()

shared plugins/inventory/plugin/items/bases/sh_item_container.lua:50

Returns the settings that the inventory of the container is created with.

Returns

  • Map table with width, height, type and multislot fields, and optionally infinite_width and infinite_height

Called on the server by the 'OnItemCreated' hook right after an instance of the item is created. Fills the container with the items listed in default_inventory.

Called on the server when a player presses the open button in the item's menu. Creates the inventory of the container if it does not exist yet and opens it for the player.

Parameters

  • actor Player

Defined in