• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Count items on specific tile

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,812
Solutions
582
Reaction score
5,372
0.3.7

I know how to find if an item is on a tile, but how can I count how many of an item are on a tile, no matter how many and/or what stackpos they are in?

I've used a couple things in the past, but they are very specific in their requirements.. such as
Code:
getTileItemById(beetroot_pos, beetroot_id).type
This will find items on the position, and count them, but only if the item is stackable.
If I add .uid to the end, it will find non-stackable items.
And of course if there is non-stackable and stackable items together, then it usually will just error instead of doing anything.
And this function doesn't give the count back to me, it only allows you to check if the specified amount is ==/</>

Does anyone have a custom function they created to count how many of an item is on a tile?

Thanks for viewing my topic.

Cheers.
 
I've come up with a solution in case anyone wants to use it in the future.
Code:
local function getItemCountOnPosition(item, pos)
    local item_pos = {x = pos.x, y = pos.y, z = pos.z}
    local item_count = 0
    for i = 1, 255 do
        local check_pos = {x = item_pos.x, y = item_pos.y, z = item_pos.z, stackpos = i}
        if getThingFromPos(check_pos).itemid <= 0 then
            break
        elseif getThingFromPos(check_pos).itemid == item then
            if isItemStackable(getThingFromPos(check_pos).itemid) == true then
                item_count = item_count + getThingFromPos(check_pos).type
            else
                item_count = item_count + 1
            end
        end
    end  
    return item_count
end
Code:
local item_id = 2544
local item_pos = {x = 1397, y = 1422, z = 7}
 
if getItemCountOnPosition(item_id, item_pos) >= 5 then
    print(">= 5 or more items on position!")
else
    print("< 5 items on position.")
end

@Limos I promise I'm learning, albeit slowly. :rolleyes:
 
Last edited:
Back
Top