Skip to content

ObjStackEntity

ObjStackEntity

Overview

An ObjStackEntity represents an collection of individual ObjEntry instances that are currently on a tile in the game world.

See ObjStackList for information on how to access ObjStackEntities.

Info

An ObjStackEntity is a Proxy usertype, which means it is safe to copy and store in your scripts.
It cannot, however, be used with any persistent storage.

Warning

Use ObjStackEntity.isValid to confirm that an entity still exists before trying to access its properties.
Entities can be removed from the client by the server for various reasons, i.e. due to moving beyond the player view distance or death.
When an entity is removed it will become invalid, and any copies of this usertype should be disposed of.

If the same entity is re-added to the client by the server, such as walking back into visibility range, then a different new ObjStackEntity will be created.

Information available within an ObjStackEntity includes:

Examples

-- Iterate all active ObjStackEntities
local allObjStacks = ObjStackList.All()
for _,objStackEntity in ipairs(allObjStacks) do
    for i = 1,objStackEntity.stackSize do
        local entry = objStackEntity:GetEntry(i)
        if entry.config == config.Obj.LOGS then
            -- ObjStack has a log in it
        end
    end
end

Constructors

Info

This usertype has no constructor, and you cannot create your own.

Methods

GetEntry

function ObjStackEntity:GetEntry(index : Integer) -> ObjEntry

Returns the ObjEntry at the given index.

Parameter Type Description
index Integer The index of the ObjEntry to return.
The value of index starts at 1.
Returns nil if no entry is found at the given index.
Returns Description
ObjEntry An ObjEntry within an ObjStackEntity.

Example

-- Find all objStacks with logs in them
local found = ObjList.ByConfig(config.Obj.LOGS);
for _,objStackEntity in ipairs(found) do
    for i=1,objStackEntity.stackSize do
        -- Get each entry in turn
        local entry = objStackEntity:GetEntry(i)
        if entry.config == config.Obj.LOGS then
            -- Found a logs entry within the stack
        end
    end
end

HasObj

function ObjStackEntity:HasObj(objType : ObjType) -> Boolean

Returns whether an ObjStackEntity contains an ObjEntry referencing the given ObjType.

Parameter Type Description
objType ObjType The ObjType to search for.
Returns Description
Boolean Whether the ObjType was found.

Example

-- Gather all objStacks
local found = ObjList.All(config.Obj.LOGS);
for _,objStackEntity in ipairs(found) do
    -- Check for logs
    if objStackEntity:HasObj(config.Obj.LOGS) then
        -- This objStack contains logs
    end
end

HasObjID

function ObjStackEntity:HasObjID(objTypeID : Integer) -> Boolean

Returns whether an ObjStackEntity contains an ObjEntry referencing the given ObjType ID.

Parameter Type Description
objTypeID Integer The ID of ObjType to search for.
Returns Description
Boolean Whether the ObjType was found.

Example

-- Gather all objStacks
local found = ObjList.All(config.Obj.LOGS);
for _,objStackEntity in ipairs(found) do
    -- Check for logs
    if objStackEntity:HasObjID(id.Obj.LOGS) then
        -- This objStack contains logs
    end
end

Properties

Info

All properties are read-only.

Name Type Description
isValid Boolean Whether this entity still exists.
Dispose of this usertype object when invalid.
position Vector3 The world position of this ObjStackEntity.
coordGrid CoordGrid Returns the CoordGrid tile this ObjStackEntity is currently on.
aabb AABB Returns the current bounding box for this ObjStackEntity.
stackSize Integer The number of ObjEntries in this ObjStackEntity.

ObjEntry

Overview

Every ObjStackEntity contains one or more instances of ObjEntry.
Each ObjEntry references a single ObjType config and a count of how many there are.

Info

For objects that cannot stack, like logs, there will be a separate entry for each one.
For stackable objects, like arrowheads, there will be a single entry with a total count of how many there are.

Stackable objects do not merge.
If another object of the same stackable type was dropped into the stack, it will remain a separate object.

Example

Entry 1: config.Obj.LOGS (count: 1)
Entry 2: config.Obj.LOGS (count: 1)
Entry 3: config.Obj.LOGS (count: 1)
Entry 4: config.Obj.BRONZE_ARROWHEADS (count: 20)
Entry 5: config.Obj.BRONZE_ARROWHEADS (count: 50)

Constructors

Info

This usertype has no constructor, and you cannot create your own.

Properties

Info

All properties are read-only.

Name Type Description
config ObjType The config that describes this entry.
configID Integer The config ID that describes this entry.
count Integer How many of this object are in this specific entry.
This will always be 1 for ObjTypes that cannot stack.