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
local success = 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 processed.
A transaction must be ended with sm.container.endTransaction.
This returns false if another transaction was already started.
Returns:
success(boolean): Whether a new transaction was started or not.
collect
local amount = sm.container.collect(container, itemUuid, quantity, mustCollectAll)
Server-Only
Adds a quantity of a given item to a Container.
A transaction must be started before using this.
Parameters:
container(Container): The container.itemUuid(Uuid): The item UUID.quantity(int): The item amount.mustCollectAll(boolean, optional): Whether all items must be collected to make the transaction valid. Defaults to true.
Returns:
amount(int): The amount of collected items.
collectToSlot
local amount = sm.container.collectToSlot(container, slot, itemUuid, quantity, mustCollectAll)
Server-Only
Performs an sm.container.collect operation on a specific slot.
A transaction must be started before using this.
Parameters:
container(Container): The container.slot(int): The slot.itemUuid(Uuid): The item UUID.quantity(int): The item amount.mustCollectAll(boolean, optional): Whether all items must be collected to make the transaction valid. Defaults to true.
Returns:
amount(int): The amount of collected items.
endTransaction
sm.container.endTransaction()
Server-Only
Ends a transaction.
Returns:
- (boolean): Whether the transaction was ended successfully or not.
getFirstItem
local item = sm.container.getFirstItem(container)
Returns a table containing item UUID, quantity (and instance id for tools) at the first available slot.
Parameters:
container(Container): The container.
Returns:
item(table): The table of item data.
itemUuid
local items = sm.container.itemUuid(container)
Returns an array containing all item UUIDs in a Container.
Parameters:
container(Container): The container.
Returns:
items(table): The array containing the item UUIDs.
moveAll
sm.container.moveAll(container, container, moveAll)
Server-Only
Moves the content from one Container to another.
A transaction must be started before using this.
Parameters:
container(Container): The source container.container(Container): The target container.moveAll(boolean): 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's carry container and assigns the carry item color.
A transaction must be started before using this.
Parameters:
container(Container): The container to assign.player(Player): The player to receive the carry content and color.color(Color): The color to assign.
quantity
local quantities = sm.container.quantity(container)
Returns a table containing all item quantities in a container.
Parameters:
container(Container): The container.
Returns:
quantities(table): The table of item quantities.
spend
local spent = sm.container.spend(container, itemUuid, quantity, mustSpendAll)
Server-Only
Removes a quantity of a given item from a Container.
A transaction must be started before using this.
Parameters:
container(Container): The container.itemUuid(Uuid): The item UUID.quantity(int): The item amount.mustSpendAll(boolean): True = Only remove items if there are enough. False = Remove as many as possible. Defaults to true.
Returns:
spent(int): The amount of successfully removed items.
spendFromSlot
local spend = sm.container.spendFromSlot(container, slot, itemUuid, quantity, mustSpendAll)
Server-Only
Performs an sm.container.spend operation on a specific slot.
A transaction must be started before using this.
Parameters:
container(Container): The container.slot(int): The slot.itemUuid(Uuid): The item UUID.quantity(int): The item amount.mustSpendAll(boolean): True = Only remove items if there are enough. False = Remove as many as possible. Defaults to true.
Returns:
spent(int): The amount of successfully removed items.
swap
local success = sm.container.swap(container, container, sourceSlot, targetSlot)
Server-Only
Swaps two item slots.
A transaction must be started before using this.
Parameters:
container(Container): The first container.container(Container): The second container.sourceSlot(int): The first slot.targetSlot(int): The second slot.
Returns:
- (boolean): Whether the action was successful or not.
totalQuantity
local quantity = sm.container.totalQuantity(container, uuid)
Returns the total number of a given item UUID in a Container.
Parameters:
Returns:
quantity(int): The total quantity of the given item UUID.