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

Im an idiot, how to print a itemid from ground?

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,444
Solutions
16
Reaction score
181
Location
Sweden
How do i print a itemid from ground?
I've tried getThingFromPos, getTileThingByPos but Im missing something.
 
LUA:
local thing = Tile(position):getTopVisibleThing()
if thing and thing:isItem() then
    print(thing:getId())
end
That is printing userdata and when adding .itemId im getting "attempt to index a nil val" or nil.

Edit: maybe i should remove stackpos? nvm no change

Part of script:

LUA:
local recipesFloor = 15
local recipes = {
{x=1005,y=(835+(count*6)),z=recipesFloor},
{x=1004,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(837+(count*6)),z=recipesFloor,stackpos=255},
{x=1005,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(838+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(839+(count*6)),z=recipesFloor,stackpos=255},
{x=1006,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(838+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(839+(count*6)),z=recipesFloor,stackpos=255}
}

print(Tile(recipes[1]):getTopVisibleThing())


secondEdit: I might have an too old repo of 1.3?
 
Last edited:
That is printing userdata and when adding .itemId im getting "attempt to index a nil val".

Edit: maybe i should remove stackpos? nvm no change

Part of script:

LUA:
local recipesFloor = 15
local recipes = {
{x=1005,y=(835+(count*6)),z=recipesFloor},
{x=1004,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(837+(count*6)),z=recipesFloor,stackpos=255},
{x=1005,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(838+(count*6)),z=recipesFloor,stackpos=255}, {x=1005,y=(839+(count*6)),z=recipesFloor,stackpos=255},
{x=1006,y=(837+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(838+(count*6)),z=recipesFloor,stackpos=255}, {x=1006,y=(839+(count*6)),z=recipesFloor,stackpos=255}
}

print(Tile(recipes[1]):getTopVisibleThing())
I tested it with this, and it's working as intended.
LUA:
local actions_test_script = Action()

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local thing = Tile(Position(250, 250, 7)):getTopVisibleThing()
    if thing and thing:isItem() then
        print(thing:getId())
    end
    return true
end

actions_test_script:id(2173)
actions_test_script:register()

Oh, yeah you aren't following what I posted. to get the itemid use :getId()
Like this.
LUA:
print(Tile(recipes[1]):getTopVisibleThing():getId())
 
I tested it with this, and it's working as intended.
LUA:
local actions_test_script = Action()

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local thing = Tile(Position(250, 250, 7)):getTopVisibleThing()
    if thing and thing:isItem() then
        print(thing:getId())
    end
    return true
end

actions_test_script:id(2173)
actions_test_script:register()

Oh, yeah you aren't following what I posted. to get the itemid use :getId()
Like this.
LUA:
print(Tile(recipes[1]):getTopVisibleThing():getId())
Thank you dear, you should have read the topic, "Im an idiot". Kappa/noKappa
Post automatically merged:

I tested it with this, and it's working as intended.
LUA:
local actions_test_script = Action()

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local thing = Tile(Position(250, 250, 7)):getTopVisibleThing()
    if thing and thing:isItem() then
        print(thing:getId())
    end
    return true
end

actions_test_script:id(2173)
actions_test_script:register()

Oh, yeah you aren't following what I posted. to get the itemid use :getId()
Like this.
LUA:
print(Tile(recipes[1]):getTopVisibleThing():getId())
No clue if you want me to create another thread, but it kinda goes hand in hand. How to print the amount?
 
Last edited:
testing tfs 1.5 and many scripts with getThingFromPos, function ain't working no more
how is this function called in the newer tfs? the script does not wor but does not print error in console either
LUA:
function onStepIn(cid, item, pos)

    coin = {x=33098, y=32816, z=13, stackpos=1}
    newpos = {x=33093, y=32824, z=13}

    getcoin = getThingfromPos(coin)
    
    if item.actionid == 6000 and getcoin.itemid == 2159 then
        doTeleportThing(cid,newpos)
        doRemoveItem(getcoin.uid,1)
        doSendMagicEffect(coin, CONST_ME_MAGIC_RED)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)   
        else
    end
    
    if item.actionid == 5999 then
    doTeleportThing(cid, {x=33097, y=32815, z=13})
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)   
    end
    return true
end

--getThingPosition = getThingPos
 
testing tfs 1.5 and many scripts with getThingFromPos, function ain't working no more
LUA:
coin = {x=33098, y=32816, z=13, stackpos=1}
stackpos should not be used in Lua scripts. It's common bug in old Lua scripts.
It's attribute for communication between Tibia client and OTS, not for getting item from given position 'stack'.

Function you should use to get top movable item is: tile:getTopDownItem() [if there is no item, it returns nil, not empty Item]
If you are looking for first item with given ID on tile, you should use: tile:getItemById(itemid)
Ex. this coin script: You don't care, if coin is on stackpos = 1, you just want to get 1 coin from given tile.

I made some functions to read items from position:

EDIT:
Coin script using new TFS functions for items:
LUA:
local coinPosition = {x=33098, y=32816, z=13}
local coinItemId = 2159
local newPosition = {x=33093, y=32824, z=13}

function onStepIn(cid, item, pos)
   if item.actionid == 6000 then
      local coinItem = Tile(coinPosition):getItemById(coinItemId)
      if coinItem then
         coinItem:remove(1)
         doTeleportThing(cid,newPosition)
         doSendMagicEffect(coinPosition, CONST_ME_MAGIC_RED)
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
      end
   end

   if item.actionid == 5999 then
      doTeleportThing(cid, {x=33097, y=32815, z=13})
      doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
   end

   return true
end
 
Last edited:
Back
Top