Skip to main content

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

abortTransaction

sm.container.abortTransaction()
Server-Only

Aborts a transaction.


beginTransaction

sm.container.beginTransaction()
Server-Only

Starts a new transaction shared across all containers.
A transaction is a collection of all changes of container items that will be collected and processed.

A transaction must be ended with sm.container.endTransaction.

Returns:
  • [ bool ]: Whether the transaction was successfully started or not.

collect

sm.container.collect( container, itemUuid, quantity, mustCollectAll )
Server-Only

Adds a quantity of a given item to a container.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The container.
  • itemUuid [ Uuid ]: The item uuid.
  • quantity [ int ]: The item amount.
  • mustCollectAll [ bool ]: Whether all items must be collected to make the transaction valid. Defaults to true.
Returns:
  • [ int ]: The amount of collected items.

collectToSlot

sm.container.collectToSlot( container, slot, itemUuid, quantity, mustCollectAll )
Server-Only

Performs an sm.container.collect operation on a specific slot.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The container.
  • slot [ int ]: The slot.
  • itemUuid [ Uuid ]: The item uuid.
  • quantity [ int ]: The item amount.
  • mustCollectAll [ bool ]: Whether all items must be collected to make the transaction valid. Defaults to true.
Returns:
  • [ int ]: The amount of collected items.

endTransaction

sm.container.endTransaction()
Server-Only

Ends a transaction.

Returns:
  • [ bool ]: Whether the transaction was ended successfully or not.

getFirstItem

sm.container.getFirstItem( container )

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

Arguments:
Returns:
  • [ table ]: The table containing the item data.

itemUuid

sm.container.itemUuid( container )

Returns a table containing all item uuids in a container.

Arguments:
Returns:
  • [ table ]: The table containing the item uuids.

moveAll

sm.container.moveAll( container, container, moveAll )
Server-Only

Moves the content from one container to another.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The source container.
  • container [ Container ]: The target container.
  • moveAll [ bool ]: Whether all items are required to be movable.

moveAllToCarryContainer

sm.container.moveAllToCarryContainer( container, player, color )
Server-Only

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

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The container to assign.
  • player [ Player ]: The player to receive the carry content and color.
  • color [ Color ]: The color to assign.

quantity

sm.container.quantity( container )

Returns a table containing all item quantities in a container.

Arguments:
Returns:
  • [ table ]: The table of item quantities.

spend

sm.container.spend( container, itemUuid, quantity, mustSpendAll )
Server-Only

Removes a quantity of a given item from a container.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The container.
  • itemUuid [ Uuid ]: The item uuid.
  • quantity [ int ]: The item amount.
  • mustSpendAll [ bool ]: True = Only remove items if there are enough. False = Remove as many as possible. Defaults to true.
Returns:
  • [ int ]: The amount of successfully removed items.

spendFromSlot

sm.container.spendFromSlot( container, slot, itemUuid, quantity, mustSpendAll )
Server-Only

Performs an sm.container.spend operation on a specific slot.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The container.
  • slot [ int ]: The slot.
  • itemUuid [ Uuid ]: The item uuid.
  • quantity [ int ]: The item amount.
  • mustSpendAll [ bool ]: True = Only remove items if there are enough. False = Remove as many as possible. Defaults to true.
Returns:
  • [ int ]: The amount of successfully removed items.

swap

sm.container.swap( container, container, sourceSlot, targetSlot )
Server-Only

Swaps two item slots.

note

A transaction must be started before using this.

Arguments:
  • container [ Container ]: The first container.
  • container [ Container ]: The second container.
  • sourceSlot [ int ]: The first slot.
  • targetSlot [ int ]: The second slot.
Returns:
  • [ bool ]: Whether the action was successful or not.

totalQuantity

sm.container.totalQuantity( container, uuid )

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

Arguments:
Returns:
  • [ int ]: The quantity of the given item uuid.