Defines the container_base item for containers, items that carry their own inventory and cash and open as storage when used.

The contents live in the instance's Inventory and Cash data and are converted with cw.inventory:ToSaveable and cw.inventory:ToLoadable when the item is saved and loaded. storageWeight and storageSpace limit what fits, and ITEM:OpenFor opens the storage through cw.storage:Open.

Summary

Methods

Adds an item instance to the container's inventory.
GetCash()server
Returns the cash stored in the container.
Returns the container's inventory, creating an empty one in the item data if it has none.
Returns whether the container holds an item.
Returns the container's contents as a flat list.
Called when a player drops the container; does nothing, so dropping is allowed.
Converts the saved inventory back into item instances after the item is loaded.
Converts the container's inventory into its saveable form before the item data is saved.
Opens the container for the player and keeps the item in their inventory.
Opens the container's inventory and cash as storage for a player.
Removes an item from the container's inventory.

Methods

Adds an item instance to the container's inventory.

Parameters

  • itemTable Item The item instance to add

Returns the cash stored in the container.

Returns

  • Number The stored cash

Returns the container's inventory, creating an empty one in the item data if it has none.

Returns

  • Inventory The items stored in the container

Returns whether the container holds an item.

Parameters

  • itemTable Item The item instance, or an item unique ID string to match any instance

Returns

  • Boolean Whether the item is in the container

Returns the container's contents as a flat list.

Returns

  • List<Item> Every item instance in the container

Called when a player drops the container; does nothing, so dropping is allowed.

Parameters

  • player
  • position

Converts the saved inventory back into item instances after the item is loaded.

Converts the container's inventory into its saveable form before the item data is saved.

Parameters

  • newData

Opens the container for the player and keeps the item in their inventory.

Parameters

  • player
  • itemEntity

Returns

  • Boolean Always false

ITEM:OpenFor(player, itemEntity)

shared gamemodes/catwork/gamemode/core/items/sh_container_base.lua:106

Opens the container's inventory and cash as storage for a player.

Uses storageWeight and storageSpace as the limits and keeps the item's Cash data in step with cash put in or taken out. Relies on the server-only ITEM:GetInventory and ITEM:GetCash, so call it on the server.

Parameters

  • player Player The player to open the storage for
  • itemEntity Entity optional, defaults to nil The container's item entity, if it is opened from the world

ITEM:RemoveFromInventory(itemTable)

server gamemodes/catwork/gamemode/core/items/sh_container_base.lua:65

Removes an item from the container's inventory.

Parameters

  • itemTable Item The item instance, or an item unique ID string to remove by ID

Defined in