sm.container

Server + Client

getFirstItem

sm.container.getFirstItem( container )

Returns a table containing item uuid, quantity (and instance id for tools) at first available slot

Parameters:

Name Type Description
container Container The container.

Returns:

Type Description
table Table containg item {uuid = Uuid, instance = integer, quantity = integer}.

itemUuid

sm.container.itemUuid( container )

Returns a table containing all item uuids in a container.

Parameters:

Name Type Description
container Container The container.

Returns:

Type Description
table The table of item uuids {Uuid, ..}.

quantity

sm.container.quantity( container )

Returns a table containing all item quantities in a container.

Parameters:

Name Type Description
container Container The container.

Returns:

Type Description
table The table of item quantities {integer, ..}.

totalQuantity

sm.container.totalQuantity( container, itemUuid )

Returns the total number of a given item uuid in a container.

Parameters:

Name Type Description
container Container The container.
itemUuid Uuid The uuid of the item.

Returns:

Type Description
integer The quantity of the given item uuid.

uniqueItemUuids

sm.container.uniqueItemUuids( container )

Returns a table containing all item uuids in a container.

Parameters:

Name Type Description
container Container The container.

Returns:

Type Description
table The table of item uuids {Uuid, ..}.

Server-only

abortTransaction

sm.container.abortTransaction(  )

Aborts a transaction.

beginTransaction

sm.container.beginTransaction(  )

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.

collectToSlot

sm.container.collectToSlot(
    container,
    slot,
    itemUuid,
    quantity,
    mustCollectAll
)

Performs a collect operation to a specific slot.

Parameters:

Name Type Description
container Container The container.
slot integer The container slot.
itemUuid Uuid The uuid of the item to be added.
quantity integer The number of items to be added.
mustCollectAll boolean 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.

endTransaction

sm.container.endTransaction(  )

Ends a transaction.

Returns:

Type Description
boolean Whether ending a transaction was successful.

moveAll

sm.container.moveAll( container, container, moveAll )

Moves the content from one container to another.

Parameters:

Name Type Description
container Container The source container.
container Container The destination container.
moveAll (optional) boolean If true, requires that all items can be moved. Defaults to true. (Optional)

moveAllToCarryContainer

sm.container.moveAllToCarryContainer( container, player, color )

Moves the content of input container to the player carry container and assigns the carry color.

Parameters:

Name Type Description
container Container The container to assign.
player Player The player to receive the carry content and color.
color Color The color to assign.

spend

sm.container.spend( container, itemUuid, quantity, mustSpendAll, avoidSlot )

Removes a quantity of a given item from a container.

Parameters:

Name Type Description
container Container The container.
itemUuid Uuid The uuid of the item.
quantity integer The number of items.
mustSpendAll (optional) boolean If true, only remove items if there are enough. If false, remove as many items as possible. Defaults to true. (Optional)
avoidSlot (optional) integer If the spending should try and avoid a specific inventory slot if the resource is available in inventory. (Optional)

Returns:

Type Description
integer The number of items successfully removed.

spendFromSlot

sm.container.spendFromSlot( container, slot, itemUuid, quantity, mustSpendAll )

Performs a sm.container.spend operation from a specific slot.

Parameters:

Name Type Description
container Container The container.
slot integer The container slot.
itemUuid Uuid The uuid of the item to be removed.
quantity integer The number of items to be removed.
mustSpendAll (optional) boolean 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.

swap

sm.container.swap( container, container, slotFrom, slotTo )

Swaps two item slots.

Parameters:

Name Type Description
container Container The first container.
container Container The second container.
slotFrom integer The first slot
slotTo integer The second slot

Returns:

Type Description
boolean Indicates if the action is possible.