• 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 Decay item on top

Exoltes

Novia OTserv Developer
Joined
Jul 2, 2009
Messages
563
Reaction score
47
Location
Belgium
I'm working on a 8.54 Open Tibia Server using The Forgotten Server - Version 0.2.7 (Mystic Spirit).

I'm trying to some special actions to my hydras nests. What I'm trying to create is an action where you use the hydra nest and you get either an egg or you spawn a couple hydras.
After that a fire spawns on top of the hydras nest (item id: 1500.) while this fire is spawned on top, the nest can no longer be used. After this the fire on top should decay (<-- no clue how to get this part working) to (item id: 1501 then to 1502 and then to 0) once the fire is completely gone the nest will have returned to normal and can be used again.

So does anyone here have any idea how to decay an item which spawned on top of another item?
Also if any of you know how to make it impossible to use an item once you spawned something on top of it, that would be great also. Because now I'm making a duplicate of the existing item in the bottom and changing it back afterwards.

Thanks in advance.
 
This item already decays in items.xml, you can change the time there, or if you removed it in items.xml because you only want it to decay on the hydra nest, you can do it like this.
Code:
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 10000, pos, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end
Code:
addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
 
Well I was hoping it would decay automatically since it decays if its placed in my map, but when I summon it with an action it does not decay and when I use the sqm I keep using the nest below instead of the fire itself.

But I guess it should get working with your script. Will test soon.
 
Trying your script but not quite sure if I'm doing it right since i find it a bit confusing how to add it exactly. Tried it this way:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 10000, pos, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end


    if itemEx.itemid == 4875 then
        doCreateItem(1500, 1, fromPosition)
        addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
        doCreatureSay(cid, "Test.", TALKTYPE_ORANGE_1)
end
end

Also getting the following error a couple seconds after I use the hydra nest:
Code:
[14/08/2014 14:09:53] Lua Script Error: [Action Interface] 
[14/08/2014 14:09:53] in a timer event called from: 
[14/08/2014 14:09:53] data/actions/scripts/tools/hydra nest.lua:onUse

[14/08/2014 14:09:53] attempt to index a nil value
[14/08/2014 14:09:53] stack traceback:
[14/08/2014 14:09:53]     [C]: in function 'getTileItemById'
[14/08/2014 14:09:53]     data/actions/scripts/tools/hydra nest.lua:3: in function <data/actions/scripts/tools/hydra nest.lua:2>
 
addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
Change topos to toPosition, since you are using that as parameter in function onUse here.

Btw, better add local functions above the main function.
So local function doTransformTimeItem above function onUse.
Everything above function onUse is loaded at startup/reload, everything inside function onUse at the moment the script is executed, so things that don't have to be in the main function, better add them above/outside it.
 
Code:
[14/08/2014 21:37:26] Lua Script Error: [Action Interface]
[14/08/2014 21:37:26] in a timer event called from:
[14/08/2014 21:37:26] data/actions/scripts/tools/hydra nest.lua:onUse

[14/08/2014 21:37:26] attempt to index a nil value
[14/08/2014 21:37:26] stack traceback:
[14/08/2014 21:37:26]     [C]: in function 'getTileItemById'
[14/08/2014 21:37:26]     data/actions/scripts/tools/hydra nest.lua:2: in function <data/actions/scripts/tools/hydra nest.lua:1>

Code:
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 10000, toPosition, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if itemEx.itemid == 4875 then
        doCreateItem(1500, 1, fromPosition)
        addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
        doCreatureSay(cid, "Test.", TALKTYPE_ORANGE_1)
end
end

Also if I use the nest again while the fire is on it I still get thet test msg.
 
Change toPosition back to pos in the local function doTransformTimeItem, toPosition isn't a parameter in that function what makes it nil.
Change topos to toPosition
Code:
addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
To
Code:
addEvent(doTransformTimeItem, 10000, toPosition, 1500, 1501)

The reason for this is because you use toPosition as parameter, which makes topos nil.
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
I should get learn to check these things :D Sorry for the trouble once again.

Now it decays one stage already but still I am possible to keep restarting the whole cycle (guess i'll have to replace the nest with a look alike id for the whole fire cycle) and around the time of the 2nd decay I get this error in my console.
Code:
[15/08/2014 11:07:51] Lua Script Error: [Action Interface]
[15/08/2014 11:07:51] in a timer event called from:
[15/08/2014 11:07:51] data/actions/scripts/tools/hydra nest.lua:onUse

[15/08/2014 11:07:51] attempt to index a nil value
[15/08/2014 11:07:51] stack traceback:
[15/08/2014 11:07:51]     [C]: in function 'getTileItemById'
[15/08/2014 11:07:51]     data/actions/scripts/tools/hydra nest.lua:2: in function <data/actions/scripts/tools/hydra nest.lua:1>

Code:
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 10000, toPosition, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if itemEx.itemid == 4875 then
        doCreateItem(1500, 1, fromPosition)
        addEvent(doTransformTimeItem, 10000, toPosition, 1500, 1501)
        doCreatureSay(cid, "Test.", TALKTYPE_ORANGE_1)
end
end

Made some edits and added the changed nest id.

Now I sometimes get the small flame and sometimes the middle flame.
Code:
[15/08/2014 11:20:00] Lua Script Error: [Action Interface] 
[15/08/2014 11:20:00] in a timer event called from: 
[15/08/2014 11:20:00] data/actions/scripts/tools/hydra nest.lua:onUse

[15/08/2014 11:20:00] attempt to index a nil value
[15/08/2014 11:20:00] stack traceback:
[15/08/2014 11:20:00]     [C]: in function 'getTileItemById'
[15/08/2014 11:20:00]     data/actions/scripts/tools/hydra nest.lua:2: in function <data/actions/scripts/tools/hydra nest.lua:1>

Code:
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 5*60*1000, toPosition, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformBack(pos, itemid, transformid)
     return doTransformItem(getTileItemById(pos, transformid).uid, itemid)
end

    if itemEx.itemid == 4875 then
    doTransformItem(itemEx.uid, 4330)
        doCreateItem(1500, 1, fromPosition)
        addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1500, 1501)
        addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1501, 1502)
        addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1502, 0)
        doCreatureSay(cid, "Test.", TALKTYPE_ORANGE_1)
    addEvent(doTransformBack, 15*60*1000, toPosition, itemEx.itemid, 4330)
end
end
 
Last edited by a moderator:
You forgot to change toPosition to pos in this line: addEvent(doTransformTimeItem, 5*60*1000, toPosition, itemid + 1, transformid + 1)
Code:
addEvent(doTransformTimeItem, 5*60*1000, pos, itemid + 1, transformid + 1)

toPosition is not a parameter in function doTransformTimeItem, the position parameter is called pos there, that's why you need to use pos.
local function doTransformTimeItem(pos, itemid, transformid)
 
Only add this line
Code:
addEvent(doTransformTimeItem, 10000, topos, 1500, 1501)
So remove
Code:
addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1501, 1502)
addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1502, 0)

The function already transforms the others.
 
Works now!

Here is the full script if someone ever needs it :)
Code:
local function doTransformTimeItem(pos, itemid, transformid)
     local thing = getTileItemById(pos, itemid).uid
     if thing > 0 then
         if transformid == 1501 or transformid == 1502 then
             doTransformItem(thing, transformid)
             doSendMagicEffect(pos, CONST_ME_POFF)
             addEvent(doTransformTimeItem, 5*60*1000, pos, itemid + 1, transformid + 1)
         else
             doRemoveItem(thing)
         end
     end
     return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformBack(pos, itemid, transformid)
     return doTransformItem(getTileItemById(pos, transformid).uid, itemid)
end

    if itemEx.itemid == 4875 then
    doTransformItem(itemEx.uid, 4330)
        doCreateItem(1500, 1, fromPosition)
    addEvent(doTransformTimeItem, 5*60*1000, toPosition, 1500, 1501)
        doCreatureSay(cid, "Test.", TALKTYPE_ORANGE_1)
    addEvent(doTransformBack, 15*60*1000, toPosition, itemEx.itemid, 4330)
end
end
 
Back
Top