Server version?How do i print a itemid from ground?
I've tried getThingFromPos, getTileThingByPos but Im missing something.
tfs 1.3Server version?
tfs 1.3
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.LUA:local thing = Tile(position):getTopVisibleThing() if thing and thing:isItem() then print(thing:getId()) end
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.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())
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()
:getId()
print(Tile(recipes[1]):getTopVisibleThing():getId())
Thank you dear, you should have read the topic, "Im an idiot". Kappa/noKappaI 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?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:
No clue if you want me to create another thread, but it kinda goes hand in hand. How to print the amount?
:getCount()
instead of :getId()
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
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.tile:getTopDownItem()
[if there is no item, it returns nil
, not empty Item
]tile:getItemById(itemid)
stackpos = 1
, you just want to get 1 coin from given tile.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