• 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!

Lua Array lua script error(removeItem)

xKrazyx

Old School
Joined
Oct 23, 2012
Messages
904
Solutions
6
Reaction score
683
So heres my problem..
AddEvent removeItem ......................

Because of the way you have to write RemoveItem in a function in an AddEvent to fking get it to work over time... Its created a problem for me where the AddEvents will Store the tree ID to Create it even tho I run the script again....
But the stumpID does not separately save when trying to remove... Im guessing its overwriting the stumpID variable the 2nd time I run it.

I've tried for a minute. changing code around. can't get it still.. AddEvent and removeItem do not like each other...

Maybe you might have better luck, or have done this before. The for loops are there because im adding more info to the array eventually.

I don't want to have to put a delay :(.. I wanna be a lumberjack on HGH

cjflEQXnAD.gif

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
--Time the tree re-appears
local backTime=5*1000
local thisTreePos=toPosition
local trees = {
[2700] = {12669},
[2701] = {12674},
[2702] = {12670},
[2703] = {12669},
[2704] = {12671},
[2705] = {12670},
[2706] = {12671},
[2707] = {12669},
[2708] = {12669},
[2712] = {12669}
}




--Loop to find tree in array Trees
    for tree, stump in pairs(trees) do
        --doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..tree.."")           
local itemOnGround = getTileItemById(toPosition, tree)
        if itemOnGround.itemid==tree then
        doSendMagicEffect(toPosition, 12)    
            if(itemOnGround.actionid < 8000 or itemOnGround.actionid > 8002) then
                doSetItemActionId(itemOnGround.uid, 8000)
            elseif(itemOnGround.actionid == 8000) then
                doPlayerAddItem(cid, 5901, 1)
                doSetItemActionId(itemOnGround.uid, 8001)
            elseif(itemOnGround.actionid == 8001) then
                doSetItemActionId(itemOnGround.uid, 8002)
            elseif(itemOnGround.actionid == 8002) then
                doPlayerAddItem(cid, 5901, 1)
                doRemoveItem(getTileItemById(toPosition, tree).uid, 1)
                            for indx, positionCoords in ipairs(stump) do
        --    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..positionCoords.."")
                        stumpID=positionCoords
                            end
                doCreateItem(stumpID, toPosition)
       

            --remove the stump before next tree is placed
                addEvent (
                function ()
   
                local tree1 = getTileItemById(toPosition, stumpID)
                    doRemoveItem(tree1.uid, 1)
                end, (backTime-10)
                )
                --respawn the tree
            addEvent(doCreateItem, backTime, tree, toPosition)
            end
            break
        else
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        end
    end
return true
end
 
Last edited:
So heres my problem..
AddEvent removeItem ......................

Because of the way you have to write RemoveItem in a function in an AddEvent to fking get it to work over time... Its created a problem for me where the AddEvents will Store the tree ID to Create it even tho I run the script again....
But the stumpID does not separately save when trying to remove... Im guessing its overwriting the stumpID variable the 2nd time I run it.

I've tried for a minute. changing code around. can't get it still.. AddEvent and removeItem do not like each other...

Maybe you might have better luck, or have done this before. The for loops are there because im adding more info to the array eventually.

I don't want to have to put a delay :(.. I wanna be a lumberjack on HGH

cjflEQXnAD.gif

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
--Time the tree re-appears
local backTime=5*1000
local thisTreePos=toPosition
local trees = {
[2700] = {12669},
[2701] = {12674},
[2702] = {12670},
[2703] = {12669},
[2704] = {12671},
[2705] = {12670},
[2706] = {12671},
[2707] = {12669},
[2708] = {12669},
[2712] = {12669}
}




--Loop to find tree in array Trees
    for tree, stump in pairs(trees) do
        --doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..tree.."")         
local itemOnGround = getTileItemById(toPosition, tree)
        if itemOnGround.itemid==tree then
        doSendMagicEffect(toPosition, 12)  
            if(itemOnGround.actionid < 8000 or itemOnGround.actionid > 8002) then
                doSetItemActionId(itemOnGround.uid, 8000)
            elseif(itemOnGround.actionid == 8000) then
                doPlayerAddItem(cid, 5901, 1)
                doSetItemActionId(itemOnGround.uid, 8001)
            elseif(itemOnGround.actionid == 8001) then
                doSetItemActionId(itemOnGround.uid, 8002)
            elseif(itemOnGround.actionid == 8002) then
                doPlayerAddItem(cid, 5901, 1)
                doRemoveItem(getTileItemById(toPosition, tree).uid, 1)
                            for indx, positionCoords in ipairs(stump) do
        --    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..positionCoords.."")
                        stumpID=positionCoords
                            end
                doCreateItem(stumpID, toPosition)
     

            --remove the stump before next tree is placed
                addEvent (
                function ()
 
                local tree1 = getTileItemById(toPosition, stumpID)
                    doRemoveItem(tree1.uid, 1)
                end, (backTime-10)
                )
                --respawn the tree
            addEvent(doCreateItem, backTime, tree, toPosition)
            end
            break
        else
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        end
    end
return true
end

Why don't you use "doTransformItem" instead of removing and replacing the tree?
 
Same problem as RemoveItem.. cant find the item unless I put it into that function in the AddEvent... then if I put it in the function in the addEvent and I run the script again before the tree respawns... it replaces the new Stump vars in the previous running of the script....

I can do just
doTransformItem

But I cant do AddEvent(DoTransform) without putting it into the function to find the item..
CANT DO THIS DOESNT WORK addEvent(doTransformItem, 5*1000, tree1.uid, tree)
It cant find the item.. has to be in a function


I get the same issue no matter if I use transform or remove/create

Do you understand??

Technically there's no errors in the script...

My issue is.. When I run the script twice before tree respawns.. The 2nd instance replaces my variables of the first script for placing the stump, but not the tree??
I can't code the remove/transform out of the function because then it cant find the item... so im stuckk.......... dunno what to do.
 
Last edited:
There is no need to act like cool with titles such as:

I edited your title.

Your other thread got deleted because it broke a rule which can be found here:
https://otland.net/threads/rules-for-the-support-board.217087/


I mean there's no need to be sitting on a dead support forum deleting peoples help threads either
when most of the titles are so vague you wont even know the error until you open it up read it anyways.. but you know..

If you can edit titles why didn't you do it before? lol

Thanks for deleting my threads and editing my title rather than try helping with my problem
 
Last edited:
Cause you are not using it properly, but i'll fix your code:
Code:
addEvent (function (toPosition, stumpID)

                local tree1 = getTileItemById(toPosition, stumpID)
                    doRemoveItem(tree1.uid, 1)
                end, (backTime-10), toPosition, stumpID)
 
Tried that.. same thing... Tried a lot of diff ways.... x.x can't figure it out...

Its because your invoking it twice before the prev tree position has respawned....

What I don't understand is why AddEvent(CreateItem will save the previous toPosition and item id in mem... but the addEvent(Function will not, when you run the script twice...

^ thats my prob
 
Last edited:
Tried that.. same thing... Tried a lot of diff ways.... x.x can't figure it out...

Its because your invoking it twice before the prev tree position has respawned....

What I don't understand is why AddEvent(CreateItem will save the previous toPosition and item id in mem... but the addEvent(Function will not, when you run the script twice...

You didn't try it properly, I have just tested it and it fixed your problem.

If you do addEvent(function() end, time) ofcourse its not going to save the previous toPosition and itemid because its going to run the function only in the time you set there, thats why u have to add the parameters in addEvent.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
--Time the tree re-appears
local backTime=5*1000
local thisTreePos=toPosition
local trees = {
[2700] = {12669},
[2701] = {12674},
[2702] = {12670},
[2703] = {12669},
[2704] = {12671},
[2705] = {12670},
[2706] = {12671},
[2707] = {12669},
[2708] = {12669},
[2712] = {12669}
}




--Loop to find tree in array Trees
    for tree, stump in pairs(trees) do
        --doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..tree.."")         
local itemOnGround = getTileItemById(toPosition, tree)
        if itemOnGround.itemid==tree then
        doSendMagicEffect(toPosition, 12)  
            if(itemOnGround.actionid < 8000 or itemOnGround.actionid > 8002) then
                doSetItemActionId(itemOnGround.uid, 8000)
            elseif(itemOnGround.actionid == 8000) then
                doPlayerAddItem(cid, 5901, 1)
                doSetItemActionId(itemOnGround.uid, 8001)
            elseif(itemOnGround.actionid == 8001) then
                doSetItemActionId(itemOnGround.uid, 8002)
            elseif(itemOnGround.actionid == 8002) then
                doPlayerAddItem(cid, 5901, 1)
                doRemoveItem(getTileItemById(toPosition, tree).uid, 1)
                            for indx, positionCoords in ipairs(stump) do
        --    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..positionCoords.."")
                        stumpID=positionCoords
                            end
                doCreateItem(stumpID, toPosition)
     

            --remove the stump before next tree is placed
                addEvent(function (toPosition, stumpID)

                local tree1 = getTileItemById(toPosition, stumpID)
                    doRemoveItem(tree1.uid, 1)
                end, (backTime-10), toPosition, stumpID)
                --respawn the tree
            addEvent(doCreateItem, backTime, tree, toPosition)
            end
            break
        else
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        end
    end
return true
end
 
Fixed thnx :D
I had local tree1 = getTileItemById(toPosition, stumpID) out of the function thats why lol
If I could Rep I would

I miss some of the easiest shit sometimes.............-.-
 
Last edited:
Back
Top