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
  • beginTransaction
  • collect
  • collectToSlot
  • endTransaction
  • getFirstItem
  • itemUuid
  • moveAll
  • moveAllToCarryContainer
  • quantity
  • spend
  • spendFromSlot
  • swap
  • totalQuantity

  • 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:

    TypeDescription
    booleanWhether 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:

    TypeNameDescription
    ContainercontainerThe container.
    UuiditemUuidThe uuid of the item.
    integerquantityThe number of items.
    booleanmustCollectAll=nilMust collect all items for the transaction to be valid. Defaults to true. (Optional)

    Returns:

    TypeDescription
    integerThe 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:

    TypeNameDescription
    ContainercontainerThe container.
    integerslotThe container slot.
    UuiditemUuidThe uuid of the item to be added.
    integerquantityThe number of items to be added.
    booleanmustCollectAllIf true, only add items if there is enough room. If false, add as many items as possible. Defaults to true. (Optional)

    Returns:

    TypeDescription
    integerThe number of items successfully added.

    sm.container.endTransaction()

    Server only

    Ends a transaction.

    Returns:

    TypeDescription
    booleanWhether 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:

    TypeNameDescription
    ContainercontainerThe container.

    Returns:

    TypeDescription
    tableTable containg item {uuid = Uuid, instance = integer, quantity = integer}.

    sm.container.itemUuid(container)

    Returns a table containing all item uuids in a container.

    Parameters:

    TypeNameDescription
    ContainercontainerThe container.

    Returns:

    TypeDescription
    tableThe table of item uuids {Uuid, ..}.

    sm.container.moveAll(container, container, moveAll=nil)

    Server only

    Moves the content from one container to another.

    Parameters:

    TypeNameDescription
    ContainercontainerThe source container.
    ContainercontainerThe destination container.
    booleanmoveAll=nilIf 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:

    TypeNameDescription
    ContainercontainerThe container to assign.
    PlayerplayerThe player to receive the carry content and color.
    ColorcolorThe color to assign.

    sm.container.quantity(container)

    Returns a table containing all item quantities in a container.

    Parameters:

    TypeNameDescription
    ContainercontainerThe container.

    Returns:

    TypeDescription
    tableThe 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:

    TypeNameDescription
    ContainercontainerThe container.
    UuiditemUuidThe uuid of the item.
    integerquantityThe number of items.
    booleanmustSpendAll=nilIf true, only remove items if there are enough. If false, remove as many items as possible. Defaults to true. (Optional)

    Returns:

    TypeDescription
    integerThe 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:

    TypeNameDescription
    ContainercontainerThe container.
    integerslotThe container slot.
    UuiditemUuidThe uuid of the item to be removed.
    integerquantityThe number of items to be removed.
    booleanmustSpendAll=nilIf true, only remove items if there are enough. If false, remove as many items as possible. Defaults to true. (Optional)

    Returns:

    TypeDescription
    integerThe number of items successfully removed.

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

    Server only

    Swaps two item slots.

    Parameters:

    TypeNameDescription
    ContainercontainerThe first container.
    ContainercontainerThe second container.
    integerslotFromThe first slot
    integerslotToThe second slot

    Returns:

    TypeDescription
    booleanIndicates if the action is possible.

    sm.container.totalQuantity(container, itemUuid)

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

    Parameters:

    TypeNameDescription
    ContainercontainerThe container.
    UuiditemUuidThe uuid of the item.

    Returns:

    TypeDescription
    integerThe quantity of the given item uuid.