Container
Associated namespace: sm.container
A userdata object representing a container in the game.
Values:
allowCollect[ bool ]Get: (Server-Only) Whether the container can collect items.Set: (Server-Only) Sets whether the container can collect items or not.
allowSpend[ bool ]Get: (Server-Only) Whether the container can spend items.Set: (Server-Only) Sets whether the container can spend items or not.
id[ int ]Get: The id of the container.
size[ int ]Get: The number of slots in the container.
Operations:
| Operation | Description |
|---|---|
Container == Container | Checks if two instances of Container refer to the same Container. |
Functions
canCollect
container:canCollect( itemUuid, quantity )
Checks if sm.container.collect is allowed using the same parameters.
Parameters:
container(Container): The container.itemUuid(Uuid): The uuid of the item.quantity(int): The number of items.
Returns:
- (boolean): Whether the container can collect the item(s) or not.
canSpend
container:canSpend( itemUuid, quantity )
Checks if sm.container.spend is allowed using the same parameters.
Parameters:
container(Container): The container.itemUuid(Uuid): The uuid of the item.quantity(int): The number of items.
Returns:
- (boolean): Whether the container can spend the item(s) or not.
getAllowCollect
container:getAllowCollect()
Server-Only
Returns whether the container can collect items.
Parameters:
container(Container): The container.
Returns:
- (boolean): Whether the container can collect items or not.
getAllowSpend
container:getAllowSpend()
Server-Only
Returns whether the container can spend items.
Parameters:
container(Container): The container.
Returns:
- (boolean): Whether the container can spend items or not.
getItem
container:getItem( slot )
Returns a table containing item uuid, quantity (and instance id for tools) at the given slot.
Parameters:
container(Container): The container.slot(int): The slot.
Returns:
- (table): The table containing item information (see table content below).
Table Content:
uuid(Uuid): The item UUID.instance(int): The instance ID, if the item is a tool.quantity(int): The item amount.
getMaxStackSize
container:getMaxStackSize()
Returns the max stack size in the container.
Parameters:
container(Container): The container.
Returns:
- (int): The container's max stack size.
getSize
container:getSize()
Returns the number of slots in a container.
Parameters:
container(Container): The container.
Returns:
- (int): The size.
hasChanged
container:hasChanged( tick )
Returns true if the given tick is lower than the tick the container was last changed.
Parameters:
container(Container): The container.tick(int): The tick.
Returns:
- (boolean): Whether the container has changed or not.
isEmpty
container:isEmpty()
Returns true if the container is empty.
Parameters:
container(Container): The container.
Returns:
- (boolean): Whether the container is empty or not.
setAllowCollect
container:setAllowCollect( state )
Server-Only
Sets whether the container can collect items.
Parameters:
container(Container): The container.state(boolean): Whether the container can collect items or not.
setAllowSpend
container:setAllowSpend( state )
Server-Only
Sets whether the container can spend items.
Parameters:
container(Container): The container.state(boolean): Whether the container can spend items or not.
setFilters
container:setFilters( filter )
Server-Only
Sets item filters.
Parameters:
container(Container): The container.filter(table): The table of allowed item uuids.
setItem
container:setItem( slot, itemUuid, quantity, instance )
Server-Only
Sets the number of items stacked in a given container slot.
Parameters:
container(Container): The container.slot(table): The slot.itemUuid(table): The uuid of the item.quantity(table): The number of items.instance(table): The instance id, if the item is a tool. (Optional)
Returns:
- (boolean): Whether the action was successful or not.