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