Container

Associated namespace: sm.container

Represents a container

Values:

Functions:

Operations:

OperationReturn typeDescription
Container == ContainerbooleanChecks if two instances of Container refer to the same Container.

allowCollect boolean

Get:

Server only

Returns whether the container can collect items.

Set:

Server only

Sets whether the container can collect items.


allowSpend boolean

Get:

Server only

Returns whether the container can spend items.

Set:

Server only

Sets whether the container can spend items.


id integer

Get:

Returns the id of a container.


size integer

Get:

Returns the number of slots in a container.


bindOnTransaction(container, callback, object?)

Server only

Binds a container's onTransaction event to a custom callback. The event is triggered when a transaction is completed.

Parameters:

TypeNameDescription
ContainercontainerThe container instance.
stringcallbackThe name of the Lua function to bind.
tableobject?The object that will receive the callback. (optional)

canCollect(container, itemUuid, quantity)

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

Parameters:

TypeNameDescription
ContainercontainerThe container.
UuiditemUuidThe uuid of the item.
integerquantityThe number of items.

Returns:

TypeDescription
booleanIndicates if the action is possible.

canCollectAll(container, uuids, quantities)

Checks if the container can collect a set of items.

Parameters:

TypeNameDescription
ContainercontainerThe container.
tableuuidsThe uuids of items to check.
tablequantitiesThe number of items of each uuid. Needs to match the number of uuids.

Returns:

TypeDescription
booleanIndicates if the action is possible.

canSpend(container, itemUuid, quantity)

Checks if sm.container.spend is allowed.

Parameters:

TypeNameDescription
ContainercontainerThe container.
UuiditemUuidThe uuid of the item.
integerquantityThe number of items.

Returns:

TypeDescription
booleanIndicates if the action is possible.

clear(container)

Server only

Clears out the contents of the container.

Parameters:

TypeNameDescription
ContainercontainerThe container.

collect(container, itemUuid, quantity, mustCollectAll?)

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?Must collect all items for the transaction to be valid. Defaults to true. (Optional)

Returns:

TypeDescription
integerThe number of items successfully added.

getAllowCollect(container)

Server only

Returns whether the container can collect items.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
booleanReturns true if the container can collect.

getAllowSpend(container)

Server only

Returns whether the container can spend items.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
booleanReturns true if the container can spend.

getItem(container, slot)

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

Parameters:

TypeNameDescription
ContainercontainerThe container.
integerslotThe slot.

Returns:

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

getMaxStackSize(container)

Returns the max stack size in the container.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
integerThe max stack size.

getRevision(container)

Returns the network revision number of the container.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
numberThe revision

getSize(container)

Returns the number of slots in a container.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
integerThe size.

hasChanged(container, tick)

Server only

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

Parameters:

TypeNameDescription
ContainercontainerThe container.
integertickThe tick.

Returns:

TypeDescription
booleanReturns true if the container has been changed.

isEmpty(container)

Returns true if the container is empty.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
booleanReturns true if the container is empty.

isFull(container)

Returns true if all container slots in the container is at max capacity.

Parameters:

TypeNameDescription
ContainercontainerThe container.

Returns:

TypeDescription
booleanReturns true if the container is empty.

resize(container, size, stackSize?)

Server only

Resize a container.

Parameters:

TypeNameDescription
ContainercontainerThe container instance.
integersizeThe new size of the container.
integerstackSize?The stack size. Defaults to maximum possible stack size(65535).

setAllowCollect(container, allow)

Server only

Sets whether the container can collect items.

Parameters:

TypeNameDescription
ContainercontainerThe container.
booleanallowTrue if the container can collect.

setAllowSpend(container, allow)

Server only

Sets whether the container can spend items.

Parameters:

TypeNameDescription
ContainercontainerThe container.
booleanallowTrue if the container can spend.

setFilters(container, filter)

Server only

Set item filter.

Parameters:

TypeNameDescription
ContainercontainerThe container.
tablefilterA table of the item uuid's {Uuid, ...} allowed to be stored in the container.

setItem(container, slot, itemUuid, quantity, instance?)

Server only

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

Parameters:

TypeNameDescription
ContainercontainerThe container.
integerslotThe slot.
UuiditemUuidThe uuid of the item.
integerquantityThe number of items.
integerinstance?The instance id, if the item is a tool. (Optional)

Returns:

TypeDescription
booleanIndicates if the action is possible.