• 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 error in item decay. Help

adrianokk

New Member
Joined
Jan 22, 2019
Messages
43
Reaction score
1
I am using a script to collect plants.
However, when the original plant returns, the former does not disappear and is full of bugs.

Code:
function onUse(cid, item, frompos, itemEx, topos)

    local chance = 1 -- chance de cortar
    local madeiras = {17170} -- item que o player irá ganhar
    local premio = madeiras[math.random(1, #madeiras)]
    local ItemQuebrado = 8786
    local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
    local random = texts[math.random(1,#texts)]
    local time = 20 --- segundos
       
    local outfit = 2209                  -- ID da Outfit Male.
    local outfit2 = 2210                  -- ID da Outfit Female.
   
       if getPlayerSex(cid) == 1 then
          doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
       else
           doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover
   
    if itemEx.itemid == 2768 then
        if math.random(1,100) >= chance then
        addEvent(doPlayerAddItem, 3*500, cid, premio, math.random(2, 10))
        addEvent(doPlayerSendTextMessage, 3*500, cid, 22, "Voce coletou Esvas.")
        doTransformItem(itemEx.uid, ItemQuebrado)
        doDecayItem(itemEx.uid) --ok ?
        addEvent(doCreateItem, time*1000, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        else
        doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
        addEvent(doPlayerSendTextMessage, 3*1000, cid,22,"Voce nao conseguiu cortar.")
        end
        end
        return true
    end

Sem título.png
 
Solution
i think this will work with you
Code:
function onUse(cid, item, frompos, itemEx, topos)

    local chance = 1 -- chance de cortar
    local madeiras = {17170} -- item que o player irá ganhar
    local premio = madeiras[math.random(1, #madeiras)]
    local ItemQuebrado = 8786
    local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
    local random = texts[math.random(1,#texts)]
    local time = 20 --- segundos
   
    local outfit = 2209                  -- ID da Outfit Male.
    local outfit2 = 2210                  -- ID da Outfit Female.

       if getPlayerSex(cid) == 1 then
          doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
       else...
I am using a script to collect plants.
However, when the original plant returns, the former does not disappear and is full of bugs.

Code:
function onUse(cid, item, frompos, itemEx, topos)

    local chance = 1 -- chance de cortar
    local madeiras = {17170} -- item que o player irá ganhar
    local premio = madeiras[math.random(1, #madeiras)]
    local ItemQuebrado = 8786
    local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
    local random = texts[math.random(1,#texts)]
    local time = 20 --- segundos
      
    local outfit = 2209                  -- ID da Outfit Male.
    local outfit2 = 2210                  -- ID da Outfit Female.
  
       if getPlayerSex(cid) == 1 then
          doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
       else
           doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover
  
    if itemEx.itemid == 2768 then
        if math.random(1,100) >= chance then
        addEvent(doPlayerAddItem, 3*500, cid, premio, math.random(2, 10))
        addEvent(doPlayerSendTextMessage, 3*500, cid, 22, "Voce coletou Esvas.")
        doTransformItem(itemEx.uid, ItemQuebrado)
        doDecayItem(itemEx.uid) --ok ?
        addEvent(doCreateItem, time*1000, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        else
        doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
        addEvent(doPlayerSendTextMessage, 3*1000, cid,22,"Voce nao conseguiu cortar.")
        end
        end
        return true
    end

View attachment 34175
Why are you creating a new item within the addEvent with the itemid of the already transformed item?

It seems that you may be actually decaying the original item but then you are creating another item that has the say id as the one you want to be decayed.

Correct me if I'm misunderstanding but the best way imo to do this is have item 8786 decay into id 2768 (through items.xml) so you don't have to create an item with addEvent at all.
 
1- then what part of the script do I have to (remove or edit)?
2-could you show me how? I tried to do it once, but it bugged everything.
 
1- then what part of the script do I have to (remove or edit)?
2-could you show me how? I tried to do it once, but it bugged everything.
I'm not sure what distro you are using so hopefully this is similar in yours.
But first remove this line:
Lua:
addEvent(doCreateItem, time*1000, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
Then in items.xml replace 8786 with this:
XML:
    <item id="8786" article="a" name="tree stump">
        <attribute key="duration" value="20" />
        <attribute key="decayTo" value="2768" />
    </item>
 
if I replace
Lua:
addEvent (doCreateItem, hora * 1000, itemEx.uid, itemEx.itemid, 1, getThingPos (itemEx.uid))

and put it this way
Lua:
addEvent (doTransformItem, hora * 1000, ItemExtreme.uid, itemEx.itemid, 1, getThingPos (itemEx.uid))
Will it work?
because I have to create several plants that will turn into the same item when they are cut.
 
if I replace
Lua:
addEvent (doCreateItem, hora * 1000, itemEx.uid, itemEx.itemid, 1, getThingPos (itemEx.uid))

and put it this way
Lua:
addEvent (doTransformItem, hora * 1000, ItemExtreme.uid, itemEx.itemid, 1, getThingPos (itemEx.uid))
Will it work?
because I have to create several plants that will turn into the same item when they are cut.
No, doTransformItem has different parameters. If you wanted to do it that way I suggest you do this:
Lua:
addEvent(function()
    if getThing(itemEx.uid) then
        doTransformItem(itemEx.uid, 2768)
    end
end, time * 1000)
But if all items with itemid 2768 you want to be able to chop down and have it turn into itemid 8786 then after 20 seconds have it turn back into itemid 2768 then do what I posted.

If you want better help, always post what distro you are using.
 
i think this will work with you
Code:
function onUse(cid, item, frompos, itemEx, topos)

    local chance = 1 -- chance de cortar
    local madeiras = {17170} -- item que o player irá ganhar
    local premio = madeiras[math.random(1, #madeiras)]
    local ItemQuebrado = 8786
    local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
    local random = texts[math.random(1,#texts)]
    local time = 20 --- segundos
      
    local outfit = 2209                  -- ID da Outfit Male.
    local outfit2 = 2210                  -- ID da Outfit Female.
  
       if getPlayerSex(cid) == 1 then
          doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
       else
           doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover
  
    if itemEx.itemid == 2768 then
        if math.random(1,100) >= chance then
        addEvent(doPlayerAddItem, 3*500, cid, premio, math.random(2, 10))
        addEvent(doPlayerSendTextMessage, 3*500, cid, 22, "Voce coletou Esvas.")
        doTransformItem(itemEx.uid, ItemQuebrado)
        addEvent(doRemoveItem, time*990, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        addEvent(doCreateItem, time*1000, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        else
        doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
        addEvent(doPlayerSendTextMessage, 3*1000, cid,22,"Voce nao conseguiu cortar.")
        end
        end
        return true
    end
 
i think this will work with you
Code:
function onUse(cid, item, frompos, itemEx, topos)

    local chance = 1 -- chance de cortar
    local madeiras = {17170} -- item que o player irá ganhar
    local premio = madeiras[math.random(1, #madeiras)]
    local ItemQuebrado = 8786
    local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
    local random = texts[math.random(1,#texts)]
    local time = 20 --- segundos
   
    local outfit = 2209                  -- ID da Outfit Male.
    local outfit2 = 2210                  -- ID da Outfit Female.

       if getPlayerSex(cid) == 1 then
          doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
       else
           doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover

    if itemEx.itemid == 2768 then
        if math.random(1,100) >= chance then
        addEvent(doPlayerAddItem, 3*500, cid, premio, math.random(2, 10))
        addEvent(doPlayerSendTextMessage, 3*500, cid, 22, "Voce coletou Esvas.")
        doTransformItem(itemEx.uid, ItemQuebrado)
        addEvent(doRemoveItem, time*990, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        addEvent(doCreateItem, time*1000, itemEx.uid, itemEx.itemid, 1, getThingPos(itemEx.uid))
        else
        doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
        addEvent(doPlayerSendTextMessage, 3*1000, cid,22,"Voce nao conseguiu cortar.")
        end
        end
        return true
    end
This is an inefficient solution, if it even works. If you can remove and then create the item, why not just transform it back into the original id. My first solution is the correct way to decay items back into originals, it's used that way in any good distro, thats why items.xml includes that attribute. I don't see why you wouldn't just want to do that, the only reason why it wouldnt work is if this distro has bugs with decaying.
 
Last edited:
Solution
This is an inefficient solution, if it even works. If you can remove and then create the item, why not just transform it back into the original id. My first solution is the correct way to decay items back into originals, it's used that way in any good distro, thats why items.xml includes that attribute. I don't see why you wouldn't just want to do that, the only reason why it wouldnt work is if this distro has bugs with decaying.
if the distro have no bugs it would work before posting here that is why i changed my way of think to another fucking doing the same property :)
 
Poketibia
HuatsonOT(DXPv3)
TFS 0.3.6

View attachment 34186
We worked it out on Discord, here's the solution:
Lua:
local trees = {
    [17153] = 17154, -- [TREE] = FRUIT
    [17155] = 17156,
    [17157] = 17158,
    [17159] = 17160,
    [17161] = 17162,
    [17163] = 17164,
    [17165] = 17166,
    [17167] = 17168
}
local ItemQuebrado = 8786
local herb = 17170
local time = 20 --- segundos
local chance = 1 -- chance de cortar
local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
local outfit = 2209                  -- ID da Outfit Male.
local outfit2 = 2210                  -- ID da Outfit Female.

function onUse(cid, item, frompos, itemEx, topos)
    if getPlayerSex(cid) == 1 then
        doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
    else
        doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover

    local fruit = trees[itemEx.itemid]
    if fruit then
        local random = texts[math.random(1,#texts)]
        if math.random(1,100) >= chance then
            doPlayerAddItem(cid, fruit, 1)
            doPlayerAddItem(cid, herb, 1)
            local old_id, old_pos = itemEx.itemid, getThingPos(itemEx.uid)
            doTransformItem(itemEx.uid, ItemQuebrado)
            addEvent(function()
                local stump = getTileItemById(old_pos, ItemQuebrado)
                if stump.uid then
                    doTransformItem(stump.uid, old_id)
                end
            end, 10 * 1000)
            doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
            doPlayerSendTextMessage(cid, 22, "Voce coletou Esvas.")
        else
            doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
            doPlayerSendTextMessage(cid, 22, "Voce nao conseguiu cortar.")
        end
    end
    return true
end
 
Many thanks Apollo,
you really helped a lot :D

We worked it out on Discord, here's the solution:
Lua:
local trees = {
    [17153] = 17154, -- [TREE] = FRUIT
    [17155] = 17156,
    [17157] = 17158,
    [17159] = 17160,
    [17161] = 17162,
    [17163] = 17164,
    [17165] = 17166,
    [17167] = 17168
}
local ItemQuebrado = 8786
local herb = 17170
local time = 20 --- segundos
local chance = 1 -- chance de cortar
local texts = {"Toc!"}  -- texto que irá aparecer quando usar o item
local outfit = 2209                  -- ID da Outfit Male.
local outfit2 = 2210                  -- ID da Outfit Female.

function onUse(cid, item, frompos, itemEx, topos)
    if getPlayerSex(cid) == 1 then
        doSetCreatureOutfit(cid, {lookType = outfit}, 5000)  --  Tempo em que a outfit estará trocada.
    else
        doSetCreatureOutfit(cid, {lookType = outfit2}, 5000)  --  Tempo em que a outfit estará trocada.
    end
    doCreatureSetNoMove(cid, true)
    addEvent(function()
        if not isPlayer(cid) then return true end
        doCreatureSetNoMove(cid, false)
    end, 5000)  --- Tempo que o jogador não pode se mover

    local fruit = trees[itemEx.itemid]
    if fruit then
        local random = texts[math.random(1,#texts)]
        if math.random(1,100) >= chance then
            doPlayerAddItem(cid, fruit, 1)
            doPlayerAddItem(cid, herb, 1)
            local old_id, old_pos = itemEx.itemid, getThingPos(itemEx.uid)
            doTransformItem(itemEx.uid, ItemQuebrado)
            addEvent(function()
                local stump = getTileItemById(old_pos, ItemQuebrado)
                if stump.uid then
                    doTransformItem(stump.uid, old_id)
                end
            end, 10 * 1000)
            doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
            doPlayerSendTextMessage(cid, 22, "Voce coletou Esvas.")
        else
            doSendAnimatedText(topos, ""..random.."", TEXTCOLOR_RED)
            doPlayerSendTextMessage(cid, 22, "Voce nao conseguiu cortar.")
        end
    end
    return true
end
 
Back
Top