• 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 TFS 0.2.14 doTransformItem bug

Drakkhan

Illuria Project Lead
Joined
Oct 3, 2013
Messages
141
Reaction score
22
It appears that this function:

doTransformItem(uid, toitemid, <optional> count/subtype)

cannot be called in a function called using "addEvent(...)" or in a global function.

If I use the "doTransformItem(...)" inside a global function or a function called using "addEvent(...)" I get an error:

"in doTransformItem() item not found."

Yes I AM feeding it proper uid and toitemid values. This has been checked, double checked, and checked again times a billion.. it's definitely the fact that the function is called inside of one of these two types of functions.

Anyone have any idea what I can do?
 
I have never looked in 0.2.14 source but you can try this
Code:
addEvent(
function()
doTransformItem(getTileItemById(itempos, 1386).uid)
end,
5 * 1000)
 
What version do you use? Does this work for you?

When I run the code you gave me I get:
Code:
LuaScriptInterface::luaDoTransformItem(). Item not found

... That looks like a source code bug, huh? :/
 
I feel like the problem is that the script that adds an event continues on without the event and then ends while DoTransformItem() is expecting the original function to be waiting around for it.. I'm not sure though..
 
What are you trying to transform?

This is from a script I made for someone, which transforms a stair hole to ground.
If you also want to transform an item in the map you can do it like this.
Code:
local function removeStairs(pos, sId, gId)
     doTransformItem(getTileItemById(pos, sId).uid, gId)
     doSendMagicEffect(pos, CONST_ME_POFF)
     return true
end

-- under the main function

addEvent(removeStairs, 30 * 1000, stairPos, stairId, groundId)
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        --code that doesn't pertain to my problem, here.
        if(itemEx.itemid == 2702) then
                doTransformItem(itemEx.uid, 18574)
                doDecayItem(itemEx.uid)
        end
end

The above code works. It transforms a willow tree to a willow stump. I made the stump myself. On the other hand, this code:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        --code that doesn't pertain to my problem, here.
        if(itemEx.itemid == 2702) then
                addEvent(doChopTree, 1000, itemEx)
        end
end

function doChopTree(pitemEx)
        doTransformItem(itemEx.uid, 18574)
        doDecayItem(itemEx.uid)
end

... doesn't work. I've also tried creating a variable for itemid and uid and passing those to doChopTree instead of the whole item. I've also tried storing the itemid and itemuid as a player storage variable and passing the cid to the doChopTree function. Always I get the same error mentioned before.

For the sake of argument lets say I NEED doTransformItem() inside an added event and not in the onUse function or a standard function call. Any ideas?

(the reason I need it inside an add event is because my actual code that is too messy to post here calls a repeater event that calls itself every 2 seconds until a random variable says that doChopTree should be called instead of itself.)
 
I'm not trying to insult your intelligence, I just don't think you want to parse through hundreds of lines of code to get at my problem, but here's my "woodcutting.lua" (in two posts because it's big and messy atm):

Code:
--"local, cross-function variables"
local treeType1Ids = {2767, 2785, 2786, 2708, 2710, 2697, 2709, 2707, 2703, 2704, 2706, 2705, 2768, 2712, 2700, 2698, 2717, 7023, 2718, 7020, 2719, 7021, 2720, 7022, 2722, 2701, 2702, 2699, 7024}

local lcid = 0
local litem = 0
local lfromPosition = 0
local litemEx
local litemExID = 0
local litemExUID = 0
local ltoPosition = 0
local lName = "player"
local storageIDX = (SKILL_WOODCUTTING*10) + 1
local storageIDY = (SKILL_WOODCUTTING*10) + 2
local storageIDZ = (SKILL_WOODCUTTING*10) + 3
local storageIDDir = (SKILL_WOODCUTTING*10) + 4
local storageIDisChopping = (SKILL_WOODCUTTING*10) + 5
local storageIDChopped = (SKILL_WOODCUTTING*10) + 6
local storageIDitemid = (SKILL_WOODCUTTING*10) + 7
local storageIDitemuid = (SKILL_WOODCUTTING*10) + 8

function doChopTree()

    pitemExID = getPlayerStorageValue(lcid, storageIDitemid)
    pitemExUID = getPlayerStorageValue(lcid, storageIDitemuid)
    doCreatureSay(lcid, string.format("itemEx1: %d %d", pitemExID, pitemExUID), TALKTYPE_SAY)

    if pitemExID == 2767 then

        doTransformItem(pitemExUID, 18548)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2785 then

        doTransformItem(pitemExUID, 18549)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2786 then

        doTransformItem(pitemExUID, 18549)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2708 then

        doTransformItem(pitemExUID, 18550)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2710 then

        doTransformItem(pitemExUID, 18551)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2697 then

        doTransformItem(pitemExUID, 18552)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2709 then

        doTransformItem(pitemExUID, 18553)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2707 then

        doTransformItem(pitemExUID, 18554)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2703 then

        doTransformItem(pitemExUID, 18555)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2704 then

        doTransformItem(pitemExUID, 18556)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2706 then

        doTransformItem(pitemExUID, 18557)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2705 then

        doTransformItem(pitemExUID, 18558)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2768 then

        doTransformItem(pitemExUID, 18559)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2711 then

        doTransformItem(pitemExUID, 18560)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2712 then

        doTransformItem(pitemExUID, 18561)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2700 then

        doTransformItem(pitemExUID, 18562)

        doDecayItem(pitemExUID)


    elseif pitemExID == 2698 then

        doTransformItem(pitemExUID, 18563)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2717 then

        doTransformItem(pitemExUID, 18564)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 7023 then

        doTransformItem(pitemExUID, 18565)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2718 then

        doTransformItem(pitemExUID, 18566)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 7020 then

        doTransformItem(pitemExUID, 18567)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2719 then

        doTransformItem(pitemExUID, 18568)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 7021 then

        doTransformItem(pitemExUID, 18569)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2720 then

        doTransformItem(pitemExUID, 18570)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 7022 then

        doTransformItem(pitemExUID, 18571)

        doDecayItem(pitemExUID)
       

    elseif pitemExID == 2722 then

        doTransformItem(pitemExUID, 18572)

        doDecayItem(pitemExUID)

    elseif pitemExID == 2701 then

        doTransformItem(pitemExUID, 18573)

        doDecayItem(pitemExUID)

    elseif pitemExID == 2702 then

        doCreatureSay(lcid, string.format("tree!: %d %d", pitemExID, pitemExUID), TALKTYPE_SAY)
        doTransformItem(pitemExUID, 18574)

        doDecayItem(pitemExUID)


    elseif pitemExID == 2699 then

        doTransformItem(pitemExUID, 18575)

        doDecayItem(pitemExUID)

    elseif pitemExID == 7024 then

        doTransformItem(pitemExUID, 18592)

        doDecayItem(pitemExUID)
   

    end

end

function repeater()

    local randStop = math.random(45)
    local plGUID = getPlayerGUID(lcid)
    local isChopped = getPlayerStorageValue(lcid, storageIDChopped)

    local oldX = getPlayerStorageValue(lcid, storageIDX)
    local oldY = getPlayerStorageValue(lcid, storageIDY)
    local oldZ = getPlayerStorageValue(lcid, storageIDZ)
    local oldDir = getPlayerStorageValue(lcid, storageIDDir)

    local plPos = getCreaturePosition(lcid)

    local newX = plPos.x
    local newY = plPos.y
    local newZ = plPos.z
    local newDir = getPlayerLookDir(lcid)

    local freeCap = getPlayerFreeCap(lcid)

    if((oldX == newX) and (oldY == newY) and (oldZ == newZ) and (oldDir == newDir) and (freeCap >= 10.0) and (randStop ~= 1) and (isChopped == 0)) then
        doWoodcutting()
        if(isPlayer(lcid)) then
            addEvent(repeater, 2000, lcid)
        else
            return 0
        end
    else
        if(freeCap < 10.0) then
            doCreatureSay(lcid, string.format("%s is too encumbered to continue.", lName), TALKTYPE_ORANGE_2)
        end
        if(randStop == 1) then
            doCreatureSay(lcid, string.format("%s stops to wipe sweat from his eyes.", lName), TALKTYPE_ORANGE_2)
        else
            doCreatureSay(lcid, string.format("%s stops chopping1.", lName), TALKTYPE_ORANGE_2)
            doCreatureSay(lcid, string.format("oldX: %d", oldX), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("oldY: %d", oldY), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("oldZ: %d", oldZ), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("oldDir: %d", oldDir), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("newX: %d", newX), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("newY: %d", newY), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("newZ: %d", newZ), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("newDir: %d", newDir), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("freeCap: %d", freeCap), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("randStop: %d", randStop), TALKTYPE_SAY)
            doCreatureSay(lcid, string.format("isChopped: %d", isChopped), TALKTYPE_SAY)

        end
        setPlayerStorageValue(lcid, storageIDX, 0)
        setPlayerStorageValue(lcid, storageIDY, 0)
        setPlayerStorageValue(lcid, storageIDZ, 0)
        setPlayerStorageValue(lcid, storageIDDir, 0)
        setPlayerStorageValue(lcid, storageIDisChopping, 0)
        if(isChopped == 1) then
            doChopTree()
        end
    end
end

--Continued on next post
 
Code:
function doWoodcutting()
    local rand = math.random(100)
    local woodcuttingSkillTries = math.max(getPlayerStorageValue(lcid, SKILL_WOODCUTTING), 0)
    local woodcuttingSkillTriesStart = woodcuttingSkillTries
    local woodcuttingSkill = getCustomSkill(SKILL_WOODCUTTING, woodcuttingSkillTries)
    local skillBuffer1 = 0
    local skillBuffer2 = 0
    local skillBuffer3 = 0
    local treeLvlBuffer1 = 0
    local treeLvlBuffer2 = 0
    local treeLvlBuffer3 = 0
    local woodTypeID = 18547

    if woodcuttingSkill < SKILL_STATE_NOVICE then
        skillBuffer1 = 40
        skillBuffer2 = 5
        skillBuffer3 = 1
    elseif woodcuttingSkill >= SKILL_STATE_NOVICE and woodcuttingSkill < SKILL_STATE_APPRENTICE then
        skillBuffer1 = 50
        skillBuffer2 = 15
        skillBuffer3 = 3
    elseif woodcuttingSkill >= SKILL_STATE_APPRENTICE and woodcuttingSkill < SKILL_STATE_JOURNEYMAN then
        skillBuffer1 = 60
        skillBuffer2 = 25
        skillBuffer3 = 5
    elseif woodcuttingSkill >= SKILL_STATE_JOURNEYMAN and woodcuttingSkill < SKILL_STATE_EXPERT then
        skillBuffer1 = 70
        skillBuffer2 = 35
        skillBuffer3 = 10
    elseif woodcuttingSkill >= SKILL_STATE_EXPERT and woodcuttingSkill < SKILL_STATE_MASTER then
        skillBuffer1 = 85
        skillBuffer2 = 55
        skillBuffer3 = 10
    elseif woodcuttingSkill >= SKILL_STATE_MASTER and woodcuttingSkill < SKILL_STATE_GRANDMASTER then
        skillBuffer1 = 95
        skillBuffer2 = 70
        skillBuffer3 = 15
    elseif woodcuttingSkill >= SKILL_STATE_GRANDMASTER then
        skillBuffer1 = 100
        skillBuffer2 = 80
        skillBuffer3 = 20
    end

    if getTreeLvl(litemEx.itemid) == 1 then
        woodTypeID = 18547
        treeLvlBuffer1 = 0
        treeLvlBuffer2 = 0
        treeLvlBuffer3 = 5
    elseif getTreeLvl(litemEx.itemid) == 3 then
        woodTypeID = 18547
        if woodcuttingSkill >= SKILL_STATE_MASTER then
            treeLvlBuffer1 = 20
            treeLvlBuffer2 = -30
            treeLvlBuffer3 = 7
        elseif woodcuttingSkill < SKILL_STATE_MASTER then
            treeLvlBuffer1 = 20
            treeLvlBuffer2 = 10
            treeLvlBuffer3 = 7
        end
    elseif getTreeLvl(litemEx.itemid) == 0 then
        return destroyItem(lcid, litemEx, ltoPosition)
    end
  
    if rand <= (skillBuffer1 - treeLvlBuffer1) then
        if rand  <= (skillBuffer2 - treeLvlBuffer2) then
            doPlayerAddItem(lcid, woodTypeID, 1)
            woodcuttingSkillTries = woodcuttingSkillTries + (treeLvlBuffer3*SKILL_MULTIPLIER_WOODCUTTING)
            checkCustomSkillLevelGain(lcid, woodcuttingSkillTriesStart, woodcuttingSkillTries, SKILL_WOODCUTTING)
            setPlayerStorageValue(lcid, SKILL_WOODCUTTING, woodcuttingSkillTries)
        elseif rand > (skillBuffer2 - treeLvlBuffer2) then
            setPlayerStorageValue(lcid, storageIDChopped, 1)
            doPlayerAddItem(lcid, woodTypeID, 1)
            woodcuttingSkillTries = woodcuttingSkillTries + (treeLvlBuffer3*SKILL_MULTIPLIER_WOODCUTTING)
            checkCustomSkillLevelGain(lcid, woodcuttingSkillTriesStart, woodcuttingSkillTries, SKILL_WOODCUTTING)
            setPlayerStorageValue(lcid, SKILL_WOODCUTTING, woodcuttingSkillTries)
        end
        doCreatureSay(lcid, "*Chop*", TALKTYPE_ORANGE_1)
        return TRUE
    else
        doSendMagicEffect(ltoPosition, CONST_ME_POFF)
        woodcuttingSkillTries = woodcuttingSkillTries + (1*SKILL_MULTIPLIER_WOODCUTTING)
        checkCustomSkillLevelGain(lcid, woodcuttingSkillTriesStart, woodcuttingSkillTries, SKILL_WOODCUTTING)
        doCreatureSay(lcid, "Chop", TALKTYPE_ORANGE_1)
        return TRUE
    end
    return destroyItem(lcid, litemEx, ltoPosition)
end

function doChopTree()

    pitemExID = getPlayerStorageValue(lcid, storageIDitemid)
    pitemExUID = getPlayerStorageValue(lcid, storageIDitemuid)
    doCreatureSay(lcid, string.format("itemEx1: %d %d", pitemExID, pitemExUID), TALKTYPE_SAY)

    if pitemExID == 2767 then

        doTransformItem(pitemExUID, 18548)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2785 then

        doTransformItem(pitemExUID, 18549)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2786 then

        doTransformItem(pitemExUID, 18549)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2708 then

        doTransformItem(pitemExUID, 18550)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2710 then

        doTransformItem(pitemExUID, 18551)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2697 then

        doTransformItem(pitemExUID, 18552)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2709 then

        doTransformItem(pitemExUID, 18553)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2707 then

        doTransformItem(pitemExUID, 18554)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2703 then

        doTransformItem(pitemExUID, 18555)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2704 then

        doTransformItem(pitemExUID, 18556)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2706 then

        doTransformItem(pitemExUID, 18557)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2705 then

        doTransformItem(pitemExUID, 18558)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2768 then

        doTransformItem(pitemExUID, 18559)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2711 then

        doTransformItem(pitemExUID, 18560)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2712 then

        doTransformItem(pitemExUID, 18561)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2700 then

        doTransformItem(pitemExUID, 18562)

        doDecayItem(pitemExUID)


    elseif pitemExID == 2698 then

        doTransformItem(pitemExUID, 18563)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2717 then

        doTransformItem(pitemExUID, 18564)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 7023 then

        doTransformItem(pitemExUID, 18565)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2718 then

        doTransformItem(pitemExUID, 18566)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 7020 then

        doTransformItem(pitemExUID, 18567)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2719 then

        doTransformItem(pitemExUID, 18568)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 7021 then

        doTransformItem(pitemExUID, 18569)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2720 then

        doTransformItem(pitemExUID, 18570)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 7022 then

        doTransformItem(pitemExUID, 18571)

        doDecayItem(pitemExUID)
      

    elseif pitemExID == 2722 then

        doTransformItem(pitemExUID, 18572)

        doDecayItem(pitemExUID)

    elseif pitemExID == 2701 then

        doTransformItem(pitemExUID, 18573)

        doDecayItem(pitemExUID)

    elseif pitemExID == 2702 then

        doCreatureSay(lcid, string.format("tree!: %d %d", pitemExID, pitemExUID), TALKTYPE_SAY)
        doTransformItem(pitemExUID, 18574)

        doDecayItem(pitemExUID)


    elseif pitemExID == 2699 then

        doTransformItem(pitemExUID, 18575)

        doDecayItem(pitemExUID)

    elseif pitemExID == 7024 then

        doTransformItem(pitemExUID, 18592)

        doDecayItem(pitemExUID)
  

    end

end

function getTreeLvl(treeid)
    if isInArray(treeType1Ids, treeid) == TRUE then
        return 1
    elseif treeid == 2711 then
        return 3
    else
        return 0
    end
end

--continued on next post
 
Sorry, it took 3 posts.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)


    ---Setup cross function variables   
    lcid = cid
    litem = item
    lfromPosition = fromPosition
    litemEx = itemEx
    litemExID = itemEx.itemid
    litemExUID = itemEx.uid
    ltoPosition = toPosition
    lName = getPlayerName(cid)

    setPlayerStorageValue(cid, storageIDitemid, itemEx.itemid)
    setPlayerStorageValue(cid, storageIDitemuid, itemEx.uid)


    ---Check if we are chopping a tree or not.
    if isInArray(treeType1Ids, itemEx.itemid) then
        --Nothing
    else
        return destroyItem(cid, itemEx, toPosition)
    end
   

    --Check if we are facing the tree in question


    ---Get Player Position and Direction---
    local playerPos = getCreaturePosition(cid)
    local playerDir = getPlayerLookDir(cid)

    ---Player GUID for naming them in starts and stops
    local playerGUID = getPlayerGUID(cid)

    ---Indicator that says whether we're currently chopping or not.
    local choppingStatus = getPlayerStorageValue(lcid, storageIDisChopping)

    ---Make sure the player isn't currently chopping
    if (choppingStatus == 0) then
        doCreatureSay(lcid, string.format("%s begins chopping the tree.", lName), TALKTYPE_ORANGE_2)
    else
        doCreatureSay(lcid, string.format("%s stops chopping.", lName), TALKTYPE_ORANGE_2)
        setPlayerStorageValue(lcid, storageIDisChopping, 0)
        return destroyItem(lcid, litemEx, ltoPosition)
    end

    --Setup North, West, East, and South Item Locations
    ---Item2: North
    local item2pos = {}
    item2pos.x = playerPos.x
    item2pos.y = playerPos.y - 1
    item2pos.z = playerPos.z

    ---Item4: West
    local item4pos = {}
    item4pos.x = playerPos.x - 1
    item4pos.y = playerPos.y
    item4pos.z = playerPos.z

    ---Item5: East
    local item5pos = {}
    item5pos.x = playerPos.x + 1
    item5pos.y = playerPos.y
    item5pos.z = playerPos.z

    ---Item7: South
    local item7pos = {}
    item7pos.x = playerPos.x
    item7pos.y = playerPos.y + 1
    item7pos.z = playerPos.z

    --Based on the players direction, check if the identified tree is in front of them and chop if it is.
    if(playerDir == 0) then -----North
        local item2 = getTileItemById(item2pos, itemEx.itemid)
        if(item2.itemid ~= 0) then
            if(item2.uid == itemEx.uid) then
                setPlayerStorageValue(cid, storageIDX, playerPos.x)
                setPlayerStorageValue(cid, storageIDY, playerPos.y)
                setPlayerStorageValue(cid, storageIDZ, playerPos.z)
                setPlayerStorageValue(cid, storageIDDir, playerDir)
                setPlayerStorageValue(cid, storageIDisChopping, 1)
                setPlayerStorageValue(cid, storageIDChopped, 0)
           
                TreeChopEvent = addEvent(repeater, 0)
            else
                doPlayerSendCancel(cid, string.format("You are not facing the tree."))
            end
        else
            doPlayerSendCancel(cid, string.format("You are not facing the tree."))
        end
    elseif(playerDir == 1) then -----East
        local item5 = getTileItemById(item5pos, itemEx.itemid)
        if(item5.itemid ~= 0) then
            if(item5.uid == itemEx.uid) then
                setPlayerStorageValue(cid, storageIDX, playerPos.x)
                setPlayerStorageValue(cid, storageIDY, playerPos.y)
                setPlayerStorageValue(cid, storageIDZ, playerPos.z)
                setPlayerStorageValue(cid, storageIDDir, playerDir)
                setPlayerStorageValue(cid, storageIDisChopping, 1)
                setPlayerStorageValue(cid, storageIDChopped, 0)
           
                TreeChopEvent = addEvent(repeater, 0)
            else
                doPlayerSendCancel(cid, string.format("You are not facing the tree."))
            end
        else
            doPlayerSendCancel(cid, string.format("You are not facing the tree."))
        end
    elseif(playerDir == 2) then -----South
        local item7 = getTileItemById(item7pos, itemEx.itemid)
        if(item7.itemid ~= 0) then
            if(item7.uid == itemEx.uid) then
                setPlayerStorageValue(cid, storageIDX, playerPos.x)
                setPlayerStorageValue(cid, storageIDY, playerPos.y)
                setPlayerStorageValue(cid, storageIDZ, playerPos.z)
                setPlayerStorageValue(cid, storageIDDir, playerDir)
                setPlayerStorageValue(cid, storageIDisChopping, 1)
                setPlayerStorageValue(cid, storageIDChopped, 0)
           
                TreeChopEvent = addEvent(repeater, 0)
            else
                doPlayerSendCancel(cid, string.format("You are not facing the tree."))
            end
        else
            doPlayerSendCancel(cid, string.format("You are not facing the tree."))
        end
    elseif(playerDir == 3) then -----West
        local item4 = getTileItemById(item4pos, itemEx.itemid)
        if(item4.itemid ~= 0) then
            if(item4.uid == itemEx.uid) then
                setPlayerStorageValue(cid, storageIDX, playerPos.x)
                setPlayerStorageValue(cid, storageIDY, playerPos.y)
                setPlayerStorageValue(cid, storageIDZ, playerPos.z)
                setPlayerStorageValue(cid, storageIDDir, playerDir)
                setPlayerStorageValue(cid, storageIDisChopping, 1)
                setPlayerStorageValue(cid, storageIDChopped, 0)

                doCreatureSay(cid, string.format("itemEx: %d %d", litemExID, litemExUID), TALKTYPE_SAY)
           
                TreeChopEvent = addEvent(repeater, 0)
            else
                doPlayerSendCancel(cid, string.format("You are not facing the tree."))
            end
        else
            doPlayerSendCancel(cid, string.format("You are not facing the tree."))
        end
    end
    return true
end
 
It doesn't work with item.uid or itemEx.uid in the function addEvent (unless this item has an uniqueid), you can do it with the function getTileItemById in your local function like I showed in the example.
 
item.uid for items without real unique ids (from map editor) are temporary references to items, because anything could have happened with that item between the time you created the event and the time the event is called, we can't even know if it exists anymore. If you know that the item will be at a location on the map, you can use getTileItemById to get the a new uid reference to the item like Limos suggested.

If there's an item that should always change id to another id after a certain amount of time, you can use duration and decayTo in items.xml.
 
Is there a reason why the trees wouldn't decay from:
Code:
        doTransformItem(getTileItemById(ltoPosition, litemExID).uid, 18574)

        doDecayItem(getTileItemById(ltoPosition, litemExID).uid)

items.xml:
Code:
    <item id="18574" article="a" name="willow stump">
        <attribute key="decayTo" value="2702" />

        <attribute key="duration" value="1000" />

    </item>
 
Sorry.. but.. BUMP.

Is there a reason why doDecayItem(...) wouldn't have any effect if it's called within an added event ( via addEvent(...) )?
 
Back
Top