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

Count Item? (pos)

viniciusturko

New Member
Joined
Jun 23, 2009
Messages
94
Reaction score
2
Location
Brasil
I have to do a script that have to count how much itens of id (Ex.: 1528), there is in the tile pos (x= 15 y= 15 z= 15)

Is there a function that count it?
 
i dunno remember if TFS has one already, but try this:
Lua:
function getTileItemCountByPos(pos, item)
    local i = 0
    for j = 1, 255 do
        pos.stackpos = j
        if getTileThingByPos(pos).itemid == item then
            i = i + 1
        end
    end
    return i
end

example:
Code:
local position = {x=100, y=100, z=7}
local sword = 2395
doPlayerSendCancel(cid, 'There are '.. getTileItemCountByPos(position, sword)..' swords there.')
 
Last edited:
Cyber, sorry, but it do not work...

I create the script normaly, but when I execute the action, Nothing happens, Any errors, Any errors in console too =/...

here is the code I'm using to test :

function getTileItemCountByPos(pos, item)
local i = 0
for j = 1, 255 do
pos.stackpos = j
if getTileThingByPos(pos).itemid == item then
i = i + 1
break
end
end
return i
end

function onStepIn(cid, item, pos)
if item.uid == 1586 then
if getTileItemCountByPos({x=1416, y=1041, z=7}, 2393) >= 3 then
doPlayerSendTextMessage(cid, 22, "You can plant here")
else
doPlayerSendTextMessage(cid, 22, "You can not plant here")
end
end
end
 
which TFS?
Lua:
function getTileItemCountByPos(pos, item)
    local i = 0
    for j = 1, 255 do
        pos.stackpos = j
        if getTileThingByPos(pos).itemid == item then
            i = i + 1
            break
        end
    end
    return i
end

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if getTileItemCountByPos({x=1416, y=1041, z=7}, 2393) >= 3 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You can plant here.')
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You can not plant here.')
    end
    return true
end
 
try
Lua:
function getTileItemCountByPos(pos, item)
    local i = 0
    for j = 1, 255 do
        pos.stackpos = j
        local thing = getTileThingByPos(pos).itemid
        if thing == 0 then
            break
        elseif thing == item then
            i = i + 1
        end
    end
    return i
end
 
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if getTileItemCountByPos({x=1416, y=1041, z=7}, 2393) >= 3 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You can plant here.')
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You can not plant here.')
    end
    return true
end
 
check if you are doing smth wrong and reload, it worked fine for me
post the xml line of the script
 
Back
Top