Container
Associated namespace: sm.container
Represents a container
Values:
Functions:
- bindOnTransaction
- canCollect
- canCollectAll
- canSpend
- clear
- collect
- getAllowCollect
- getAllowSpend
- getItem
- getMaxStackSize
- getRevision
- getSize
- hasChanged
- isEmpty
- isFull
- resize
- setAllowCollect
- setAllowSpend
- setFilters
- setItem
Operations:
| Operation | Return type | Description |
|---|---|---|
| Container == Container | boolean | Checks if two instances of Container refer to the same Container. |
allowCollect boolean
Get:
Server only
Returns whether the container can collect items.
Set:
Server only
Sets whether the container can collect items.
allowSpend boolean
Get:
Server only
Returns whether the container can spend items.
Set:
Server only
Sets whether the container can spend items.
id integer
Get:
Returns the id of a container.
size integer
Get:
Returns the number of slots in a container.
bindOnTransaction(container, callback, object?)
Server only
Binds a container's onTransaction event to a custom callback. The event is triggered when a transaction is completed.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container instance. |
| string | callback | The name of the Lua function to bind. |
| table | object? | The object that will receive the callback. (optional) |
canCollect(container, itemUuid, quantity)
Checks if sm.container.collect is allowed using the same parameters.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| Uuid | itemUuid | The uuid of the item. |
| integer | quantity | The number of items. |
Returns:
| Type | Description |
|---|---|
| boolean | Indicates if the action is possible. |
canCollectAll(container, uuids, quantities)
Checks if the container can collect a set of items.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| table | uuids | The uuids of items to check. |
| table | quantities | The number of items of each uuid. Needs to match the number of uuids. |
Returns:
| Type | Description |
|---|---|
| boolean | Indicates if the action is possible. |
canSpend(container, itemUuid, quantity)
Checks if sm.container.spend is allowed.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| Uuid | itemUuid | The uuid of the item. |
| integer | quantity | The number of items. |
Returns:
| Type | Description |
|---|---|
| boolean | Indicates if the action is possible. |
clear(container)
Server only
Clears out the contents of the container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
collect(container, itemUuid, quantity, mustCollectAll?)
Server only
Adds a quantity of a given item to a container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| Uuid | itemUuid | The uuid of the item. |
| integer | quantity | The number of items. |
| boolean | mustCollectAll? | Must collect all items for the transaction to be valid. Defaults to true. (Optional) |
Returns:
| Type | Description |
|---|---|
| integer | The number of items successfully added. |
getAllowCollect(container)
Server only
Returns whether the container can collect items.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| boolean | Returns true if the container can collect. |
getAllowSpend(container)
Server only
Returns whether the container can spend items.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| boolean | Returns true if the container can spend. |
getItem(container, slot)
Returns a table containing item uuid, quantity (and instance id for tools) at given slot.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| integer | slot | The slot. |
Returns:
| Type | Description |
|---|---|
| table | Table containg item {uuid = Uuid, instance = integer, quantity = integer}. |
getMaxStackSize(container)
Returns the max stack size in the container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| integer | The max stack size. |
getRevision(container)
Returns the network revision number of the container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| number | The revision |
getSize(container)
Returns the number of slots in a container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| integer | The size. |
hasChanged(container, tick)
Server only
Returns true if the given tick is lower than the tick the container was last changed.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| integer | tick | The tick. |
Returns:
| Type | Description |
|---|---|
| boolean | Returns true if the container has been changed. |
isEmpty(container)
Returns true if the container is empty.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| boolean | Returns true if the container is empty. |
isFull(container)
Returns true if all container slots in the container is at max capacity.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
Returns:
| Type | Description |
|---|---|
| boolean | Returns true if the container is empty. |
resize(container, size, stackSize?)
Server only
Resize a container.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container instance. |
| integer | size | The new size of the container. |
| integer | stackSize? | The stack size. Defaults to maximum possible stack size(65535). |
setAllowCollect(container, allow)
Server only
Sets whether the container can collect items.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| boolean | allow | True if the container can collect. |
setAllowSpend(container, allow)
Server only
Sets whether the container can spend items.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| boolean | allow | True if the container can spend. |
setFilters(container, filter)
Server only
Set item filter.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| table | filter | A table of the item uuid's {Uuid, ...} allowed to be stored in the container. |
setItem(container, slot, itemUuid, quantity, instance?)
Server only
Sets the number of items stacked in a given container slot.
Parameters:
| Type | Name | Description |
|---|---|---|
| Container | container | The container. |
| integer | slot | The slot. |
| Uuid | itemUuid | The uuid of the item. |
| integer | quantity | The number of items. |
| integer | instance? | The instance id, if the item is a tool. (Optional) |
Returns:
| Type | Description |
|---|---|
| boolean | Indicates if the action is possible. |