Summary

Methods

Returns whether an item may be put into the player's open storage.
Returns whether an item may be taken out of the player's open storage.
Closes the player's open storage.
GetCash()client
Returns the cash in the open storage.
Returns the entity whose storage the player has open.
Returns the inventory of the open storage.
Returns whether the open storage hides the local player's inventory side.
GetName()client
Returns the name of the open storage.
Returns whether cash takes no space in the open storage.
Returns whether cash adds no weight to the open storage.
Returns the storage window.
Returns the total space taken by the cash and items in the player's open storage.
Returns the storage table of the storage the player has open.
Returns the total weight of the cash and items in the player's open storage.
Moves an item from the player's inventory into their open storage.
Returns whether the player's open storage contains an item instance.
Returns whether the storage window is open and visible.
Opens a storage menu for the player.
Returns a value from the storage table of the player's open storage.
Sends the player's cash to everyone who has the player's inventory open as storage.
Sends an item change in the player's inventory to everyone who has it open as storage.
Moves an item from the player's open storage into their inventory.
Sends every instance of an item type in the player's open storage to their client.
Sets the cash of the player's open storage for everyone viewing the same inventory.
Sets the maximum space of the player's open storage for everyone viewing the same inventory.
Sets the maximum weight of the player's open storage for everyone viewing the same inventory.

Methods

cw.storage:CanGiveTo(player, itemTable)

shared gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:308

On the server

Returns whether an item may be put into the player's open storage.

Checks the item's allowStorage, allowGive, allowPlayerStorage, allowPlayerGive, allowEntityStorage and allowEntityGive fields against whether the storage belongs to a player. Shipments accept every item.

Parameters

  • player Player The player who has the storage open
  • itemTable Item The item instance

Returns

  • Boolean true if the item is allowed, otherwise nil

See also

On the client

Returns whether the local player may put an item into the open storage.

Checks the item's allowStorage, allowGive and the player or entity variants (allowPlayerStorage, allowPlayerGive, allowEntityStorage, allowEntityGive) depending on whether the storage belongs to a player. Shipments accept every item.

Parameters

  • itemTable Item The item to give

Returns

  • Boolean true if the item may be given, nil otherwise

See also

Defined in

cw.storage:CanTakeFrom(player, itemTable)

shared gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:339

On the server

Returns whether an item may be taken out of the player's open storage.

Checks the item's allowStorage, allowTake, allowPlayerStorage, allowPlayerTake, allowEntityStorage and allowEntityTake fields against whether the storage belongs to a player. Items in shipments can always be taken.

Parameters

  • player Player The player who has the storage open
  • itemTable Item The item instance

Returns

  • Boolean true if the item is allowed, otherwise nil

See also

On the client

Returns whether the local player may take an item out of the open storage.

Checks the item's allowStorage, allowTake and the player or entity variants (allowPlayerStorage, allowPlayerTake, allowEntityStorage, allowEntityTake) depending on whether the storage belongs to a player. Every item can be taken from shipments.

Parameters

  • itemTable Item The item to take

Returns

  • Boolean true if the item may be taken, nil otherwise

See also

Defined in

cw.storage:Close(player, bServer)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:83

Closes the player's open storage.

Calls the storage's OnClose(player, storageTable, entity) callback first.

Parameters

  • player Player The player
  • bServer Boolean optional, defaults to false Only close it on the server, without telling the client to close the menu

See also

Returns the cash in the open storage.

Returns

  • Number The cash, or 0 when the cash_enabled config is off

On the server

Returns the entity whose storage the player has open.

Parameters

  • player Player The player

Returns

  • Entity The storage entity, or nil if no storage is open or the entity is no longer valid

On the client

Returns the entity the open storage belongs to.

Parameters

  • player

Returns

  • Entity The storage entity, which may be a player, or nil if no storage is open

Defined in

Returns the inventory of the open storage.

Returns

  • Inventory The storage inventory, or nil if no storage is open

Returns whether the open storage hides the local player's inventory side.

Returns

  • Boolean The isOneSided option the storage was opened with

Returns the name of the open storage.

Returns

  • String The name shown in the storage window

Returns whether cash takes no space in the open storage.

Returns

  • Boolean The noCashSpace option the storage was opened with

Returns whether cash adds no weight to the open storage.

Returns

  • Boolean The noCashWeight option the storage was opened with

Returns the storage window.

Returns

  • Panel The panel, or nil if it has not been created

On the server

Returns the total space taken by the cash and items in the player's open storage.

Items count their storageSpace if they have one, otherwise their space. Cash counts unless the storage was opened with noCashSpace.

Parameters

  • player Player The player

Returns

  • Number The space, or 0 if no storage is open

On the client

Returns the maximum space of the open storage.

Parameters

  • player

Returns

  • Number Space limit, or nil if no storage is open

Defined in

Returns the storage table of the storage the player has open.

Parameters

  • player Player The player

Returns

  • Map The storage table passed to cw.storage:Open, or nil if no storage is open

On the server

Returns the total weight of the cash and items in the player's open storage.

Items count their storageWeight if they have one, otherwise their weight. Cash counts unless the storage was opened with noCashWeight.

Parameters

  • player Player The player

Returns

  • Number The weight, or 0 if no storage is open

On the client

Returns the maximum weight of the open storage.

Parameters

  • player

Returns

  • Number Weight limit, or nil if no storage is open

Defined in

cw.storage:GiveTo(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:429

Moves an item from the player's inventory into their open storage.

Fails if the storage can no longer be used (it is closed in that case), the storage does not allow the item (cw.storage:CanGiveTo), the item is the container whose contents are open, the player does not have it, the PlayerCanGiveToStorage hook does not return true, a non-player storage would exceed its weight or space, or the item's CanGiveStorage or the storage's CanGiveItem returns false. Fires PlayerGiveToStorage before and PostPlayerGiveToStorage after the move, and updates everyone viewing the same inventory. The storage closes if OnGiveItem or the item's OnStorageGive returns true.

Parameters

  • player Player The player who has the storage open
  • itemTable Item The item instance to give

Returns

  • Boolean Whether the item was moved

See also

cw.storage:HasItem(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:50

Returns whether the player's open storage contains an item instance.

Parameters

  • player Player The player
  • itemTable Item The item instance to look for

Returns

  • Boolean Whether the storage contains the item

Returns whether the storage window is open and visible.

Returns

  • Boolean true if it is open, nil otherwise

Opens a storage menu for the player.

Any storage the player already has open is closed through its OnClose callback first. Missing fields of data get defaults, then the table becomes the player's storage table and its contents are sent to the client.

data may contain: name (defaults to '#Storage_Default'), inventory (the storage's inventory, defaults to an empty one), entity (defaults to the player), weight and space (default to the default_inv_weight and default_inv_space configs), cash (removed when cash is disabled), isOneSided, noCashWeight, noCashSpace, and the callbacks OnClose(player, storageTable, entity), CanGiveItem and CanTakeItem ((player, storageTable, itemTable), return false to block) and OnGiveItem and OnTakeItem (same arguments, return true to close the storage). Other keys, such as distance, OnGiveCash and OnTakeCash, are kept in the table for other code to read.

cw.storage:Open(player, {
  name = 'Locker',
  weight = 20,
  space = 50,
  entity = entity,
  inventory = entity.cwInventory,
  cash = entity.cwCash,
  OnClose = function(player, storageTable, entity)
    if IsValid(entity) then
      entity.cwCash = storageTable.cash
    end
  end
})

Parameters

  • player Player The player to open the storage for
  • data Map The storage table; it is modified and kept

See also

cw.storage:Query(player, key, default)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:67

Returns a value from the storage table of the player's open storage.

Parameters

  • player Player The player
  • key String Key in the storage table, such as 'inventory', 'entity' or 'cash'
  • default Any optional, defaults to nil Value to return if no storage is open or the value is nil or false

Returns

  • Any The value, or default

Sends the player's cash to everyone who has the player's inventory open as storage.

Only sets their storage cash when cash is enabled.

Parameters

  • player Player The player whose cash changed

cw.storage:SyncItem(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:388

Sends an item change in the player's inventory to everyone who has it open as storage.

The item is added to their storage menus if the player still has it, and removed otherwise.

Parameters

  • player Player The player whose inventory changed
  • itemTable Item The item instance that was given or taken

cw.storage:TakeFrom(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:522

Moves an item from the player's open storage into their inventory.

Fails if the storage can no longer be used (it is closed in that case), the storage does not allow it (cw.storage:CanTakeFrom), the PlayerCanTakeFromStorage hook does not return true, the storage does not contain the item, or the item's CanTakeStorage or the storage's CanTakeItem returns false. If the player cannot carry the item, they are notified of the reason. Fires PlayerTakeFromStorage and PostPlayerTakeFromStorage, and updates everyone viewing the same inventory. The storage closes if OnTakeItem or the item's OnStorageTake returns true.

Parameters

  • player Player The player who has the storage open
  • itemTable Item The item instance to take

Returns

  • Boolean true if the item was moved, false if a check failed, nil if the player could not carry it

See also

cw.storage:UpdateByID(player, uniqueID)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:591

Sends every instance of an item type in the player's open storage to their client.

Does nothing if no storage is open or the storage has no items of that type.

Parameters

  • player Player The player who has the storage open
  • uniqueID String Unique ID of the item type

cw.storage:UpdateCash(player, cash)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:240

Sets the cash of the player's open storage for everyone viewing the same inventory.

Does nothing when cash is disabled.

Parameters

  • player Player A player who has the storage open
  • cash Number The new amount of cash

cw.storage:UpdateSpace(player, space)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:282

Sets the maximum space of the player's open storage for everyone viewing the same inventory.

Parameters

  • player Player A player who has the storage open
  • space Number The new maximum space

cw.storage:UpdateWeight(player, weight)

server gamemodes/catwork/gamemode/core/libraries/sv_storage.lua:263

Sets the maximum weight of the player's open storage for everyone viewing the same inventory.

Parameters

  • player Player A player who has the storage open
  • weight Number The new maximum weight

Defined in