sm.container
Associated object type: Container
A container keeps track of items and stores them in slots. Each slot holds one item type and a quantity, if the item is stackable.
Functions:
sm.container.abortTransaction()
Server only
Aborts a transaction.
sm.container.beginTransaction()
Server only
Starts a new transaction shared across all containers. A transaction is a collection of all changes of container items will be collected and processed
A transaction must be ended with sm.container.endTransaction.
Returns:
Type | Description |
---|---|
boolean | Whether starting a transaction was successful. |
sm.container.collect(container, itemUuid, quantity, mustCollectAll=nil)
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=nil | Must collect all items for the transaction to be valid. Defaults to true. (Optional) |
Returns:
Type | Description |
---|---|
integer | The number of items successfully added. |
sm.container.collectToSlot(container, slot, itemUuid, quantity, mustCollectAll)
Server only
Performs a sm.container.collect operation to a specific slot.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
integer | slot | The container slot. |
Uuid | itemUuid | The uuid of the item to be added. |
integer | quantity | The number of items to be added. |
boolean | mustCollectAll | If true, only add items if there is enough room. If false, add as many items as possible. Defaults to true. (Optional) |
Returns:
Type | Description |
---|---|
integer | The number of items successfully added. |
sm.container.endTransaction()
Server only
Ends a transaction.
Returns:
Type | Description |
---|---|
boolean | Whether ending a transaction was successful. |
sm.container.getFirstItem(container)
Returns a table containing item uuid, quantity (and instance id for tools) at first available slot
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
Returns:
Type | Description |
---|---|
table | Table containg item {uuid = Uuid, instance = integer, quantity = integer}. |
sm.container.itemUuid(container)
Returns a table containing all item uuids in a container.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
Returns:
Type | Description |
---|---|
table | The table of item uuids {Uuid, ..}. |
sm.container.moveAll(container, container, moveAll=nil)
Server only
Moves the content from one container to another.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The source container. |
Container | container | The destination container. |
boolean | moveAll=nil | If true, requires that all items can be moved. |
sm.container.moveAllToCarryContainer(container, player, color)
Server only
Moves the content of input container to the player carry container and assigns the carry color.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container to assign. |
Player | player | The player to receive the carry content and color. |
Color | color | The color to assign. |
sm.container.quantity(container)
Returns a table containing all item quantities in a container.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
Returns:
Type | Description |
---|---|
table | The table of item quantities {integer, ..}. |
sm.container.spend(container, itemUuid, quantity, mustSpendAll=nil)
Server only
Removes a quantity of a given item from a container.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
Uuid | itemUuid | The uuid of the item. |
integer | quantity | The number of items. |
boolean | mustSpendAll=nil | If true, only remove items if there are enough. If false, remove as many items as possible. Defaults to true. (Optional) |
Returns:
Type | Description |
---|---|
integer | The number of items successfully removed. |
sm.container.spendFromSlot(container, slot, itemUuid, quantity, mustSpendAll=nil)
Server only
Performs a sm.container.spend operation from a specific slot.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
integer | slot | The container slot. |
Uuid | itemUuid | The uuid of the item to be removed. |
integer | quantity | The number of items to be removed. |
boolean | mustSpendAll=nil | If true, only remove items if there are enough. If false, remove as many items as possible. Defaults to true. (Optional) |
Returns:
Type | Description |
---|---|
integer | The number of items successfully removed. |
sm.container.swap(container, container, slotFrom, slotTo)
Server only
Swaps two item slots.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The first container. |
Container | container | The second container. |
integer | slotFrom | The first slot |
integer | slotTo | The second slot |
Returns:
Type | Description |
---|---|
boolean | Indicates if the action is possible. |
sm.container.totalQuantity(container, itemUuid)
Returns the total number of a given item uuid in a container.
Parameters:
Type | Name | Description |
---|---|---|
Container | container | The container. |
Uuid | itemUuid | The uuid of the item. |
Returns:
Type | Description |
---|---|
integer | The quantity of the given item uuid. |