• 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 transformBack (blueberry bush etc)

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 making it possible to pluck fruits from certain trees but running into a problem when I want the trees to transform back after x times to be full with fruits again.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if itemEx.itemid == 4006 then
        local rand = math.random(1, 50)
        if rand < 2 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 5)
        doCreatureSay(cid, "You collected 5 oranges.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 50000)
        elseif rand < 8 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 4)
        doCreatureSay(cid, "You collected 4 oranges.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 40000)
        elseif rand < 19 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 3)
        doCreatureSay(cid, "You collected 3 oranges.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 30000)
        elseif rand < 30 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 2)
        doCreatureSay(cid, "You collected 2 oranges.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 20000)
        elseif rand < 45 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 1)
        doCreatureSay(cid, "You collected 1 orange.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 10000)
    else
        doTransformItem(itemEx.uid, 4008)
        doCreatureSay(cid, "You failed to collect any oranges.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 5000)
        end
    end
end

Any help is welcome.

Thanks in advance.
 
Code:
local function doTransformBack(pos, itemid, transformid)
     return doTransformItem(getTileItemById(pos, transformid).uid, itemid)
end

Code:
addEvent(doTransformBack, 30 * 1000, toPosition, item.itemid, 4008)
 
Thx man! fixed it :)

note that the 30 * 1000 does not work

if you want 30 minutes set it to 30000. And just leave the '* 1000 out'.
 
[05/08/2014 18:26:07] Lua Script Error: [Action Interface]
[05/08/2014 18:26:07] in a timer event called from:
[05/08/2014 18:26:07] data/actions/scripts/tools/fruits.lua:eek:nUse

[05/08/2014 18:26:07] luaDoTransformItem(). Item not found


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformBack(pos, itemid, transformid)
     return doTransformItem(getTileItemById(pos, transformid).uid, itemid)
end

    if itemEx.itemid == 4006 then
        local rand = math.random(1, 50)
        if rand < 2 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 5)
        doCreatureSay(cid, "You collected 5 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 50000, toPosition, item.itemid, 4008)
        elseif rand < 8 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 4)
        doCreatureSay(cid, "You collected 4 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 40000, toPosition, item.itemid, 4008)
        elseif rand < 19 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 3)
        doCreatureSay(cid, "You collected 3 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 30000, toPosition, item.itemid, 4008)
        elseif rand < 30 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 2)
        doCreatureSay(cid, "You collected 2 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 20000, toPosition, item.itemid, 4008)
        elseif rand < 45 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 1)
        doCreatureSay(cid, "You collected 1 orange.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 10000, toPosition, item.itemid, 4008)
    else
        doTransformItem(itemEx.uid, 4008)
        doCreatureSay(cid, "You failed to collect any oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 5000, toPosition, item.itemid, 4008)
        end

    elseif itemEx.itemid == 6176 then
        local rand = math.random(1, 5)
        if rand < 2 then
        doTransformItem(itemEx.uid, 1218)
        doPlayerAddItem(cid, 2681, 2)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 40000, toPosition, item.itemid, 6176)
        elseif rand < 5 then
        doTransformItem(itemEx.uid, 1218)
        doPlayerAddItem(cid, 2681, 1)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 35000, toPosition, item.itemid, 6176)
    else
        doTransformItem(itemEx.uid, 1218)
        doCreatureSay(cid, "You failed to collect any grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 20000, toPosition, item.itemid, 6176)
        end

    elseif itemEx.itemid == 6177 then
        local rand = math.random(1, 5)
        if rand < 2 then
        doTransformItem(itemEx.uid, 5324)
        doPlayerAddItem(cid, 2681, 2)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 10)
        addEvent(doTransformBack, 40000, toPosition, item.itemid, 6177)
        elseif rand < 5 then
        doTransformItem(itemEx.uid, 5324)
        doPlayerAddItem(cid, 2681, 1)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 10)
        addEvent(doTransformBack, 35000, toPosition, item.itemid, 6177)
    else
        doTransformItem(itemEx.uid, 5324)
        doCreatureSay(cid, "You failed to collect any grapes.", TALKTYPE_ORANGE_1)
        addEvent(transformBack, 10)
        addEvent(doTransformBack, 20000, toPosition, item.itemid, 6177)
        end
        end
end
 
The 30 * 1000 works fine for me, also on TFS 0.2.7.

Change item.itemid to itemEx.itemid, since the item that should transform is the itemEx.
Code:
addEvent(doTransformBack, 30 * 1000, toPosition, itemEx.itemid, 4008)
 
[05/08/2014 21:13:02] Lua Script Error: [Action Interface]
[05/08/2014 21:13:02] in a timer event called from:
[05/08/2014 21:13:02] data/actions/scripts/tools/fruits.lua:eek:nUse

[05/08/2014 21:13:02] luaDoTransformItem(). Item not found

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformBack(pos, itemid, transformid)
     return doTransformItem(getTileItemById(pos, transformid).uid, itemid)
end

    if itemEx.itemid == 4006 then
        local rand = math.random(1, 50)
        if rand < 2 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 5)
        doCreatureSay(cid, "You collected 5 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 50000, toPosition, itemEx.itemid, 4008)
        elseif rand < 8 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 4)
        doCreatureSay(cid, "You collected 4 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 40000, toPosition, itemEx.itemid, 4008)
        elseif rand < 19 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 3)
        doCreatureSay(cid, "You collected 3 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 30000, toPosition, itemEx.itemid, 4008)
        elseif rand < 30 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 2)
        doCreatureSay(cid, "You collected 2 oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 20000, toPosition, itemEx.itemid, 4008)
        elseif rand < 45 then
        doTransformItem(itemEx.uid, 4008)
        doPlayerAddItem(cid, 2675, 1)
        doCreatureSay(cid, "You collected 1 orange.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 10000, toPosition, itemEx.itemid, 4008)
    else
        doTransformItem(itemEx.uid, 4008)
        doCreatureSay(cid, "You failed to collect any oranges.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 5000, toPosition, itemEx.itemid, 4008)
        end

    elseif itemEx.itemid == 6176 then
        local rand = math.random(1, 5)
        if rand < 2 then
        doTransformItem(itemEx.uid, 1218)
        doPlayerAddItem(cid, 2681, 2)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 40000, toPosition, itemEx.itemid, 6176)
        elseif rand < 5 then
        doTransformItem(itemEx.uid, 1218)
        doPlayerAddItem(cid, 2681, 1)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 35000, toPosition, itemEx.itemid, 6176)
    else
        doTransformItem(itemEx.uid, 1218)
        doCreatureSay(cid, "You failed to collect any grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 20000, toPosition, itemEx.itemid, 6176)
        end

    elseif itemEx.itemid == 6177 then
        local rand = math.random(1, 5)
        if rand < 2 then
        doTransformItem(itemEx.uid, 5324)
        doPlayerAddItem(cid, 2681, 2)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 40000, toPosition, itemEx.itemid, 6177)
        elseif rand < 5 then
        doTransformItem(itemEx.uid, 5324)
        doPlayerAddItem(cid, 2681, 1)
        doCreatureSay(cid, "You collected some grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 35000, toPosition, itemEx.itemid, 6177)
    else
        doTransformItem(itemEx.uid, 5324)
        doCreatureSay(cid, "You failed to collect any grapes.", TALKTYPE_ORANGE_1)
        addEvent(doTransformBack, 20000, toPosition, itemEx.itemid, 6177)
        end
        end
end
 
Found the problem switched some of the item ids on my lower part of the script

Code:
addEvent(doTransformBack, 40000, toPosition, itemEx.itemid, 6176)

had to be
Code:
addEvent(doTransformBack, 40000, toPosition, itemEx.itemid, 1218)

But the '* 1000' does not work with me so i'll just keep using the big numbers.
 
Back
Top