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

RevScripts Add item decay to script TFS 1.3

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys,

I would like for the target item (27956) to decay to (28059) when I use the pick (27809), but I didn't managed to make it work. I try to copy and edit from some other script I have here with similar ending, but I end up having errors on TFS.

What I tried to add was this:

Lua:
    local transform = true
    
    if table.contains({27956}, target.itemid) then
    target:transform(28059)
    target:decay()
    end

But I end up with this error:
Lua Script Error: [Scripts Interface]
C:\opentibia\data\scripts\newmining.lua:callback
C:\opentibia\data\scripts\newmining.lua:108: attempt to index a nil value
stack traceback:
[C]: in function '__index'
C:\opentibia\data\scripts\newmining.lua:108: in function <C:\opentibia\data\scripts\newmining.lua:106>

Can somebody help me out?
 
Try
Lua:
local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 27956 then
        target:transform(28059)
    end
    return false
end

action:id(27809)
action:register()
 
It did decay, but not like I wanted. It stop working the mining script (no errors on TFS), and it only decay when I click use on the stone, not when I use the item on it.
Post automatically merged:

Describe what you intend to do, what the result will be, each step.
Sorry I should have done that from the beggining

That's the mining script, it works fine, but I wish to remove the cooldown the script has and add the decay option when the player mine. For example, the player mine a stone, the stone will then decay to debris and after a while, it will transform back to a stone again. (the transform part I already have set on item.xml and it did work with my old script)

Lua:
local mining = Action()

local config = {
maxmininglevel = 120,
storagemining = 100000,
expperlevel = 1000,
experiencemining = 125
}

local stone = {
    blue = {27956},
    green = {8640, 8636, 1353, 11534},
    lightblue = {8638, 8634, 1354, 35263},
    red = {8639, 8635, 1355, 25820},
}

local stones = {
    crystal = {stone.blue[1], stone.green[1], stone.lightblue[1], stone.red[1]},
    lcrystal = {stone.blue[2], stone.green[2], stone.lightblue[2], stone.red[2]},
    pcrystal = {stone.blue[3], stone.green[3], stone.lightblue[3], stone.red[3]},
    scrystal = {stone.blue[4], stone.green[4], stone.lightblue[4], stone.red[4]},
}

local ore = {
    blue = {27978},
    green = {2155, 2158, 37457, 37458},
    lightblue = {2156, 37604, 34699, 34698},
    red = {9980, 37606, 37605, 38615},
}

local ores = { ore.blue[1], ore.blue[2], ore.blue[3], ore.blue[4], ore.green[1], ore.green[2], ore.green[3], ore.green[4], ore.lightblue[1], ore.lightblue[2], ore.lightblue[3], ore.lightblue[4], ore.red[1], ore.red[2], ore.red[3], ore.red[4]}

local levels = {
    {
    level = {0,25},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4]},
    items = {ores[1],ores[5], ores[9], ores[13]},
    iselect = 0,
    bstart = 1,
    gstart = 2,
    lbstart = 3,
    rstart = 5,
    chance = 8, -- 30
    qtdmax = 1,
    expgainmin = 20, --15
    expgainmax = 30 --50
    },
    {
    level = {26,55},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4]},
    items = {ores[1],ores[2], ores[5], ores[6], ores[9],ores[10], ores[13], ores[14]},
    iselect = 1,
    bstart = 1,
    gstart = 3,
    lbstart = 5,
    rstart = 8,
    chance = 7,
    qtdmax = 1,
    expgainmin = 30,
    expgainmax = 50
    },
    {
    level = {56,69},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[5], ores[6], ores[7], ores[9],ores[10], ores[11], ores[13], ores[14], ores[15]},
    iselect = 2,
    bstart = 1,
    gstart = 4,
    lbstart = 7,
    rstart = 10,
    chance = 5,
    qtdmax = 1,
    expgainmin = 50,
    expgainmax = 70
    },
    {
    level = {70,89},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4], stones.scrystal[1], stones.scrystal[2], stones.scrystal[3], stones.scrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[4], ores[5], ores[6], ores[7], ores[8], ores[9],ores[10], ores[11], ores[12], ores[13], ores[14], ores[15], ores[16]},
    iselect = 3,
    bstart = 1,
    gstart = 5,
    lbstart = 9,
    rstart = 13,
    chance = 3,
    qtdmax = 1,
    expgainmin = 70,
    expgainmax = 90
    },
    {
    level = {90,125},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4], stones.scrystal[1], stones.scrystal[2], stones.scrystal[3], stones.scrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[4], ores[5], ores[6], ores[7], ores[8], ores[9],ores[10], ores[11], ores[12], ores[13], ores[14], ores[15], ores[16]},
    iselect = 3,
    bstart = 1,
    gstart = 7,
    lbstart = 12,
    rstart = 18,
    chance = 2,
    qtdmax = 1,
    expgainmin = 90,
    expgainmax = 110
    }
}

function mining.onUse(cid, item, fromPosition, itemEx, toPosition)


local getMiningLevel = getPlayerStorageValue(cid, config.storagemining)
local getMiningExp = getPlayerStorageValue(cid, config.experiencemining)
local cooldown = 2

    if getMiningLevel == -1 then
        setPlayerStorageValue(cid, config.storagemining, 0)
    end
    if getMiningExp < 0 then
        setPlayerStorageValue(cid, config.experiencemining, 0)
    end

    if (isInArray(stones.crystal, itemEx.itemid) or isInArray(stones.lcrystal, itemEx.itemid) or isInArray(stones.pcrystal, itemEx.itemid) or isInArray(stones.scrystal, itemEx.itemid))  then
        
        for a = 1, #levels do
            min = levels[a].level[1]; max = levels[a].level[2]

            if (getMiningLevel >= min and getMiningLevel <= max) then
                if isInArray(levels[a].stone, itemEx.itemid) then
                        if (math.random(1, 100) <= levels[a].chance) then
                            quantity = math.random(1, levels[a].qtdmax)
                            experience = math.random(levels[a].expgainmin, levels[a].expgainmax)
                                if isInArray(stone.blue, itemEx.itemid) then
                                    iselection = math.random(levels[a].bstart, levels[a].bstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.green, itemEx.itemid) then
                                    iselection = math.random(levels[a].gstart, levels[a].gstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.lightblue, itemEx.itemid) then
                                    iselection = math.random(levels[a].lbstart, levels[a].lbstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.red, itemEx.itemid) then
                                    iselection = math.random(levels[a].rstart, levels[a].rstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                            
                            if getMiningLevel == 125 then
                            doSendMagicEffect(toPosition, 9)
                            doPlayerSendTextMessage(cid, 22, text)
                            doPlayerAddItem(cid, collect, quantity)
                            
                            elseif getMiningLevel <= 124 then
                            
                                if getMiningExp >= config.expperlevel then
                                    doSendMagicEffect(getCreaturePosition(cid), 49)
                                    setPlayerStorageValue(cid, config.storagemining, getMiningLevel + 1)
                                    setPlayerStorageValue(cid, config.experiencemining, getMiningExp - config.expperlevel)
                                    text = "You collected " ..quantity.. " mineral" ..(quantity > 1 and "s" or "").. ". \n You have gained " ..experience.. " experience points in Mining. \n You advanced from mining skill level " ..getMiningLevel.. " to mining skill level " ..(getMiningLevel + 1).. "."
                                else
                                    setPlayerStorageValue(cid, config.experiencemining, getMiningExp + experience)
                                    text = "You collected " ..quantity.. " mineral" ..(quantity > 1 and "s" or "").. ". \n You have gained " ..experience.. " experience points in Mining. \n" ..(config.expperlevel - getMiningExp - experience).. " experience points left to next level. \nCurrent Mining Skill: " ..getMiningLevel.. "."
                                end
                                doSendMagicEffect(toPosition, 9)
                                doPlayerSendTextMessage(cid, 22, text)
                                doPlayerAddItem(cid, collect, quantity)
                            end
                            
                        else
                            doPlayerSendTextMessage(cid, 22, "You are Mining on crystal...")
                        end
                else
                    doPlayerSendTextMessage(cid, 22, "You need to get better in Mining to mining this.")
                end
            end

        end

    else
        doSendMagicEffect(getCreaturePosition(cid), 2)
        doPlayerSendTextMessage(cid, 22, "You can't mining this.")
    end

    
end

mining:id(27809)
mining:register()
 
Last edited:
it sounds like this mby?

in items.xml id: debris id
XML:
<attribute key="decayto" value="123" /> <!-- stone id -->
<attribute key="duration" value="100" />

and in lua
Lua:
if target:getId() == 123 then -- stone id
    target:transform(123) -- debris id
    target:decay()
end
 
it sounds like this mby?, altho im not sure about it ;p

in items.xml id: 27956
XML:
<attribute key="decayto" value="28059" />
<attribute key="duration" value="100" />

and in lua
Lua:
if target:getId() == 27956 then
    target:decay()
end

I did put the decay part on the item.xml, but still, the item doesn't decay when I use the pick

That's the item the player is mining: (this part ain't working)

Lua:
    <item id="27956" article="a" name="Clay Vein">
    <attribute key="DecayTo" value="28059" />
</item>

That's the transform part in item.xml and this part is working:

Lua:
<item id="28059" article="a" name="debris">
    <attribute key="duration" value="120" />
    <attribute key="decayTo" value="27956" />
</item>
 
here is how the script is with the addition to what you suggest:

Lua:
local mining = Action()

local config = {
maxmininglevel = 120,
storagemining = 100000,
expperlevel = 1000,
experiencemining = 125
}

local stone = {
    blue = {27956},
    green = {8640, 8636, 1353, 11534},
    lightblue = {8638, 8634, 1354, 35263},
    red = {8639, 8635, 1355, 25820},
}

local stones = {
    crystal = {stone.blue[1], stone.green[1], stone.lightblue[1], stone.red[1]},
    lcrystal = {stone.blue[2], stone.green[2], stone.lightblue[2], stone.red[2]},
    pcrystal = {stone.blue[3], stone.green[3], stone.lightblue[3], stone.red[3]},
    scrystal = {stone.blue[4], stone.green[4], stone.lightblue[4], stone.red[4]},
}

local ore = {
    blue = {27978},
    green = {2155, 2158, 37457, 37458},
    lightblue = {2156, 37604, 34699, 34698},
    red = {9980, 37606, 37605, 38615},
}

local ores = { ore.blue[1], ore.blue[2], ore.blue[3], ore.blue[4], ore.green[1], ore.green[2], ore.green[3], ore.green[4], ore.lightblue[1], ore.lightblue[2], ore.lightblue[3], ore.lightblue[4], ore.red[1], ore.red[2], ore.red[3], ore.red[4]}

local levels = {
    {
    level = {0,25},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4]},
    items = {ores[1],ores[5], ores[9], ores[13]},
    iselect = 0,
    bstart = 1,
    gstart = 2,
    lbstart = 3,
    rstart = 5,
    chance = 8, -- 30
    qtdmax = 1,
    expgainmin = 20, --15
    expgainmax = 30 --50
    },
    {
    level = {26,55},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4]},
    items = {ores[1],ores[2], ores[5], ores[6], ores[9],ores[10], ores[13], ores[14]},
    iselect = 1,
    bstart = 1,
    gstart = 3,
    lbstart = 5,
    rstart = 8,
    chance = 7,
    qtdmax = 1,
    expgainmin = 30,
    expgainmax = 50
    },
    {
    level = {56,69},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[5], ores[6], ores[7], ores[9],ores[10], ores[11], ores[13], ores[14], ores[15]},
    iselect = 2,
    bstart = 1,
    gstart = 4,
    lbstart = 7,
    rstart = 10,
    chance = 5,
    qtdmax = 1,
    expgainmin = 50,
    expgainmax = 70
    },
    {
    level = {70,89},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4], stones.scrystal[1], stones.scrystal[2], stones.scrystal[3], stones.scrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[4], ores[5], ores[6], ores[7], ores[8], ores[9],ores[10], ores[11], ores[12], ores[13], ores[14], ores[15], ores[16]},
    iselect = 3,
    bstart = 1,
    gstart = 5,
    lbstart = 9,
    rstart = 13,
    chance = 3,
    qtdmax = 1,
    expgainmin = 70,
    expgainmax = 90
    },
    {
    level = {90,125},
    stone = {stones.crystal[1], stones.crystal[2], stones.crystal[3], stones.crystal[4], stones.lcrystal[1], stones.lcrystal[2], stones.lcrystal[3], stones.lcrystal[4], stones.pcrystal[1], stones.pcrystal[2], stones.pcrystal[3], stones.pcrystal[4], stones.scrystal[1], stones.scrystal[2], stones.scrystal[3], stones.scrystal[4]},
    items = {ores[1],ores[2], ores[3], ores[4], ores[5], ores[6], ores[7], ores[8], ores[9],ores[10], ores[11], ores[12], ores[13], ores[14], ores[15], ores[16]},
    iselect = 3,
    bstart = 1,
    gstart = 7,
    lbstart = 12,
    rstart = 18,
    chance = 2,
    qtdmax = 1,
    expgainmin = 90,
    expgainmax = 110
    }
}

function mining.onUse(cid, item, fromPosition, itemEx, target, toPosition, isHotkey)


local getMiningLevel = getPlayerStorageValue(cid, config.storagemining)
local getMiningExp = getPlayerStorageValue(cid, config.experiencemining)
local cooldown = 0

    if getMiningLevel == -1 then
        setPlayerStorageValue(cid, config.storagemining, 0)
    end
    if getMiningExp < 0 then
        setPlayerStorageValue(cid, config.experiencemining, 0)
    end

    if (isInArray(stones.crystal, itemEx.itemid) or isInArray(stones.lcrystal, itemEx.itemid) or isInArray(stones.pcrystal, itemEx.itemid) or isInArray(stones.scrystal, itemEx.itemid))  then
        
        for a = 1, #levels do
            min = levels[a].level[1]; max = levels[a].level[2]

            if (getMiningLevel >= min and getMiningLevel <= max) then
                if isInArray(levels[a].stone, itemEx.itemid) then
                        if (math.random(1, 100) <= levels[a].chance) then
                            quantity = math.random(1, levels[a].qtdmax)
                            experience = math.random(levels[a].expgainmin, levels[a].expgainmax)
                                if isInArray(stone.blue, itemEx.itemid) then
                                    iselection = math.random(levels[a].bstart, levels[a].bstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.green, itemEx.itemid) then
                                    iselection = math.random(levels[a].gstart, levels[a].gstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.lightblue, itemEx.itemid) then
                                    iselection = math.random(levels[a].lbstart, levels[a].lbstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                                if isInArray(stone.red, itemEx.itemid) then
                                    iselection = math.random(levels[a].rstart, levels[a].rstart + levels[a].iselect)
                                    collect = levels[a].items[iselection]
                                end
                            
                            if getMiningLevel == 125 then
                            doSendMagicEffect(toPosition, 9)
                            doPlayerSendTextMessage(cid, 22, text)
                            doPlayerAddItem(cid, collect, quantity)
                            
                            elseif getMiningLevel <= 124 then
                            
                                if getMiningExp >= config.expperlevel then
                                    doSendMagicEffect(getCreaturePosition(cid), 49)
                                    setPlayerStorageValue(cid, config.storagemining, getMiningLevel + 1)
                                    setPlayerStorageValue(cid, config.experiencemining, getMiningExp - config.expperlevel)
                                    text = "You collected " ..quantity.. " mineral" ..(quantity > 1 and "s" or "").. ". \n You have gained " ..experience.. " experience points in Mining. \n You advanced from mining skill level " ..getMiningLevel.. " to mining skill level " ..(getMiningLevel + 1).. "."
                                else
                                    setPlayerStorageValue(cid, config.experiencemining, getMiningExp + experience)
                                    text = "You collected " ..quantity.. " mineral" ..(quantity > 1 and "s" or "").. ". \n You have gained " ..experience.. " experience points in Mining. \n" ..(config.expperlevel - getMiningExp - experience).. " experience points left to next level. \nCurrent Mining Skill: " ..getMiningLevel.. "."
                                end
                                doSendMagicEffect(toPosition, 9)
                                doPlayerSendTextMessage(cid, 22, text)
                                doPlayerAddItem(cid, collect, quantity)
                            end
                            
                        else
                            doPlayerSendTextMessage(cid, 22, "You are Mining on crystal...")
                        end
                else
                    doPlayerSendTextMessage(cid, 22, "You need to get better in Mining to mining this.")
                end
            end

        end

    else
        doSendMagicEffect(getCreaturePosition(cid), 2)
        doPlayerSendTextMessage(cid, 22, "You can't mining this.")
    end

if target:getId() == 27956 then -- clay vein
    target:transform(28059) -- debris id
    target:decay()
end
    
end

mining:id(27809)
mining:register()

I got this error on TFS:

Lua Script Error: [Scripts Interface]
C:\opentibia\data\scripts\newmining.lua:callback
C:\opentibia\data\scripts\newmining.lua:183: attempt to call method 'getId' (a nil value)
stack traceback:
[C]: in function 'getId'
C:\opentibia\data\scripts\newmining.lua:183: in function <C:\opentibia\data\scripts\newmining.lua:106>

The script still works, it just doesn't decay the stone.
 
Last edited:
Back
Top