Skip to main content

Container

Associated namespace: sm.container

A userdata object representing a container in the game.

Values:
  • allowCollect [ bool ]

    • Get: (Server-Only) Whether the container can collect items.
    • Set: (Server-Only) Sets whether the container can collect items or not.
  • allowSpend [ bool ]

    • Get: (Server-Only) Whether the container can spend items.
    • Set: (Server-Only) Sets whether the container can spend items or not.
  • id [ int ]

    • Get: The id of the container.
  • size [ int ]

    • Get: The number of slots in the container.
Operations:
OperationDescription
Container == ContainerChecks if two instances of Container refer to the same Container.

Functions

canCollect

container:canCollect( itemUuid, quantity )

Checks if sm.container.collect is allowed using the same parameters.

Arguments:
  • container [ Container ]: The container.
  • itemUuid [ Uuid ]: The uuid of the item.
  • quantity [ int ]: The number of items.
Returns:
  • [ bool ]: Whether the container can collect the item(s) or not.

canSpend

container:canSpend( itemUuid, quantity )

Checks if sm.container.spend is allowed using the same parameters.

Arguments:
  • container [ Container ]: The container.
  • itemUuid [ Uuid ]: The uuid of the item.
  • quantity [ int ]: The number of items.
Returns:
  • [ bool ]: Whether the container can spend the item(s) or not.

getAllowCollect

container:getAllowCollect()
Server-Only

Returns whether the container can collect items.

Arguments:
Returns:
  • [ bool ]: Whether the container can collect items or not.

getAllowSpend

container:getAllowSpend()
Server-Only

Returns whether the container can spend items.

Arguments:
Returns:
  • [ bool ]: Whether the container can spend items or not.

getItem

container:getItem( slot )

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

Arguments:
  • container [ Container ]: The container.
  • slot [ int ]: The slot.
Returns:
  • [ table ]: The table containing item information (see table content below).
Table Content:
  • uuid [ Uuid ]: The item UUID.
  • instance [ int ]: The instance ID, if the item is a tool.
  • quantity [ int ]: The item amount.

getMaxStackSize

container:getMaxStackSize()

Returns the max stack size in the container.

Arguments:
Returns:
  • [ int ]: The container's max stack size.

getSize

container:getSize()

Returns the number of slots in a container.

Arguments:
Returns:
  • [ int ]: The size.

hasChanged

container:hasChanged( tick )

Returns true if the given tick is lower than the tick the container was last changed.

Arguments:
  • container [ Container ]: The container.
  • tick [ int ]: The tick.
Returns:
  • [ bool ]: Whether the container has changed or not.

isEmpty

container:isEmpty()

Returns true if the container is empty.

Arguments:
Returns:
  • [ bool ]: Whether the container is empty or not.

setAllowCollect

container:setAllowCollect( state )
Server-Only

Sets whether the container can collect items.

Arguments:
  • container [ Container ]: The container.
  • state [ bool ]: Whether the container can collect items or not.

setAllowSpend

container:setAllowSpend( state )
Server-Only

Sets whether the container can spend items.

Arguments:
  • container [ Container ]: The container.
  • state [ bool ]: Whether the container can spend items or not.

setFilters

container:setFilters( filter )
Server-Only

Sets item filters.

Arguments:
  • container [ Container ]: The container.
  • filter [ table ]: The table of allowed item uuids.

setItem

container:setItem( slot, itemUuid, quantity, instance )
Server-Only

Sets the number of items stacked in a given container slot.

Arguments:
  • container [ Container ]: The container.
  • slot [ table ]: The slot.
  • itemUuid [ table ]: The uuid of the item.
  • quantity [ table ]: The number of items.
  • instance [ table ]: The instance id, if the item is a tool. (Optional)
Returns:
  • [ bool ]: Whether the action was successful or not.