• 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 How to get item ID from tile and then remove it?

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,452
Solutions
1
Reaction score
625
Location
Estonia
I have a tile where i want to reSpawn bucket every hour.
but every time the script starts i want it to first remove the all items from that tile before.
then create bucket there.

working script
Code:
local pos1 = {x=558,y=654,z=7}

function onThink()
local items = Tile(pos1):getItems()

    for i = 1, #items do
        addEvent(function() items[i]:remove() end, 1000)
    end
    addEvent(doCreateItem, 2000, 2005, 0, pos1)
return true
end

sidenote*
you don't have to use addEvent, but my script actually continues, that is why you see them here.

Code:
local pos1 = {x=558,y=654,z=7}
This is the tile position i want to change.
Code:
function onThink()
you can use any function you like. I use onThink because i have a globalEvent.
You can make things clean and create items for onUse or whatever else function.
Code:
local items = Tile(pos1):getItems()
under items i collect all the items what are located in position
Code:
    for i = 1, #items do
        addEvent(function() items[i]:remove() end, 1000)
    end
for every item i found in that tile: remove them all 1 sec later
Code:
addEvent(doCreateItem, 2000, 2005, 0, pos1)
2 seconds after using script (and 1 seconds after deleting all items)
makes item in the position i defined earlier
2005 is bucket and 0 means its empty.
1 would mean its water in it, etc
 
Last edited:
You need to define itemId, if itemId has no value then it will return nil.
Also why the parentheses around item in doRemoveItem?
 
You need to define itemId, if itemId has no value then it will return nil.
Also why the parentheses around item in doRemoveItem?
im trying to get the item id!
This item id can be ANY of the items listed in items.xml
so definining it my own would be a hassle
 
also this
Code:
addEvent(function() doRemoveItem((item).uid) end, 5000)
should be this
Code:
addEvent(doRemoveItem, 5000, item.uid)

addEvent works like this
Code:
addEvent(function name, time, arguments)
 
arguements are already set inside the function..
ir works both ways imo. same result
Arguments are something that is passed to a function, a parameter would be something that you find in a function you know during the function definition?
 
Arguments are something that is passed to a function, a parameter would be something that you find in a function you know during the function definition?
i don't understand you..
addEvent is working.

Question is how i get item Id from the position i show and then remove that item he found.
 
I already knew the function.. i don't know how to use it..
You didn't answer any of my questions..
 
Question 1:
How to get item ID from tile and then remove it?
your answer:
You need to define itemId

Did i ask What i have to do with this function??

Question2:
can you post the entire script?
Your answer:
I just answered your question.

>.>
 
Code:
local thing = Tile(pos):getItemById(1387)
if thing then
     thing:remove()
end

To remove it with addEvent
Code:
local function doRemoveSomething(pos)
     local thing = Tile(pos):getItemById(1387)
     if thing then
         thing:remove()
     end
     return true
end

addEvent(doRemoveSomething, 10 * 1000, pos)
 
Code:
local thing = Tile(pos):getItemById(1387)
if thing then
     thing:remove()
end

yeah i know i can remove item like that, but problem is:
i want to get the id of the item what is on that tile.
This can be any of the items from item.xml (i have no control over what players drop on that tile)
 
Will this item be at the top on the tile? Then you can use getTopVisibleThing.
Code:
local thing = Tile(pos):getTopVisibleThing()
if thing and thing:isItem() and thing:getType():isMovable() then
     thing:remove()
end

To get the id incase it's needed.
Code:
thing:getId()
 
Last edited:
ye i was messing with the getTopVisible thing, but didnt know how insert the tile position.


Code:
function onThink()
local thing = Tile(pos1):getTopVisibleThing(player)

if thing:isItem() then
    addEvent(function() thing:remove(tonumber(param) or -1) end, 5000)
end

this is working, BUT it even removes the tile itself xD (making it a void area, that was funny but also not what i had in mind)
 
Use tile:getItems()
Code:
local items = tile:getItems()
for i = 1, #items do
    items[i]:remove()
end
 
script with getItems()
Result: attempt to call getItems() a nil value

Code:
local pos1 = {x=558,y=654,z=7}

function onThink()
local items = pos1:getItems()

    for i = 1, #items do
        addEvent(function() items[i]:remove() end, 5000)
    end
    addEvent(doCreateItem, 6000, 2005, 0, pos1)
return true
end

script with doCleanTile
result: attempt to call global doCleanTile (a nil value)
Code:
local pos1 = {x=558,y=654,z=7}

function onThink()
    addEvent(function() doCleanTile(pos1) end, 5000)
    addEvent(doCreateItem, 6000, 2005, 0, pos1)
return true
end
 
Back
Top