• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved addEvent troubles

Aleada

Unknown Member
Joined
Mar 14, 2013
Messages
231
Reaction score
7
Heya, I recently tried making a "woodcutting" script for a quest but I ran into a problem where if you cut down 2 trees, then only 1 will spawn back because the position is getting replaced each time.. I tried using tables but I couldn't figure it out :/ Anyone got any ideas?

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local random = math.random(1,10)
    if itemEx.itemid == 2702 or itemEx.itemid == 2705 or itemEx.itemid == 2701 or itemEx.itemid == 2703 then
        if getCreatureStorage(cid, 20004) == 2 and random == 1 then
            tree_pos = getThingPosition(itemEx.uid)
            tree_id = itemEx.itemid
            doTransformItem(itemEx.uid, 8786)
            addEvent(doRespawnTree, 10 * 1000)
        elseif getCreatureStorage(cid, 20004) == 2 and random > 1 then
            doPlayerAddItem(cid,2245,1)
        end
    end
    return true
end

function doRespawnTree()
local tree = getTileItemById(tree_pos, 8786)
    doTransformItem(tree.uid, tree_id)
end
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local random = math.random(1,10)
    if itemEx.itemid == 2702 or itemEx.itemid == 2705 or itemEx.itemid == 2701 or itemEx.itemid == 2703 then
        if getCreatureStorage(cid, 20004) == 2 and random == 1 then
            doTransformItem(itemEx.uid, 8786)
            addEvent(doRespawnTree, 10 * 1000, getThingPosition(itemEx.uid), itemEx.itemid)
        elseif getCreatureStorage(cid, 20004) == 2 and random > 1 then
            doPlayerAddItem(cid,2245,1)
        end
    end
    return true
end

function doRespawnTree(pos, id)
    local tree = getTileItemById(pos, 8786)
    if tree.uid > 0 then
        doTransformItem(tree.uid, id)
    end
end
 
Back
Top