• 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 Adding Levels on This system

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
225
Reaction score
64
Hello,

Im using this script made by @Xikini on a thread with many pages , i don't remember where is it now...
And is working perfect.

I Would like to add a Level System from 0 to 255 for example with levels, increasing the Experience needed on each level ( for example +500 experience / each level ).

I paste a second script with a system level, where i start trying but i dont get any error while use the item.

Lua:
local AdentisPick = Action()

local config = {
    [8637] = {text = {"The crystal is regenerating"}}, -- Blue Crystal
    [8633] = {break_chance = 50, loot_chance = 35, lower_tier = 8637,  -- Large Blue Crystal
        normal_loot_table = { -- 80%
            [1] = {item_id = 7705, count = 1}, -- Magma Stone
            [2] = {item_id = 5089, count = 1}, -- Crystal Stone
            [3] = {item_id = 7736, count = 1}, -- Solar Stone
            [4] = {item_id = 7844, count = 1}, -- Amethyst Stone
            [5] = {item_id = 4854, count = 1}, -- Amber Stone
            [6] = {item_id = 7846, count = 1}, -- Lava Stone
            [7] = {item_id = 4851, count = 1}, -- Light Solar Stone
            [8] = {item_id = 4853, count = 1}, -- Malachite Stone
            [9] = {item_id = 4872, count = 1}, -- Sapphir Stone
            [10] = {item_id = 4858, count = 1} -- Gold Stone
        },
       ---- A LOOT OF TABLES ( same as before ) DELETED Because we cannot exceed 25000 characters
        }
    },
}

function AdentisPick.onUse(cid, item, fromPosition, itemEx, toPosition)
 
    local object = config[itemEx.itemid]
 
    if object then
 
        if object.text then
            local rand_text = math.random(#object.text)
            doCreatureSay(cid, object.text[rand_text], TALKTYPE_ORANGE_1, nil, nil, toPosition)
            doSendMagicEffect(toPosition, CONST_ME_POFF)
            return true
        end
 
    
        local rand_event = math.random(200)
        if rand_event == 200 then
            doSendMagicEffect(toPosition, 33)
            return true
        end
    
        local rand_break = math.random(100)
        if rand_break <= object.break_chance then
            doTransformItem(itemEx.uid, object.lower_tier)
            doSendMagicEffect(toPosition, CONST_ME_POFF)
        end
 
        local rand_reward = math.random(100)
        if rand_reward > (object.loot_chance + 10) then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            return true
        end
        doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
      
        local multiple = 1
        local rand_multiple = math.random(15)
        if rand_multiple == 15 then
            multiple = math.random(2, 3)
        end
        for i = 1, multiple do
            local loot_table = object.normal_loot_table
            local rand_loot = math.random(100)
            if rand_loot < 6 then
                loot_table = object.rare_loot_table
            elseif rand_loot < 21 then
                loot_table = object.semi_rare_loot_table
            end
            local rand_item = math.random(#loot_table)
            rand_item = loot_table[rand_item]
            if rand_item.count == 1 then
                doPlayerAddItem(cid, rand_item.item_id, 1, true)
            else
                local new_count = math.random(rand_item.count)
                doPlayerAddItem(cid, rand_item.item_id, new_count, true)
            end
        end
 
    end
 
    return true
end

AdentisPick:id(8980)
AdentisPick:register()

Using parts of this script created by a guy here ( i dont remember ):

Code:
local mining = Action()

local config = {
maxmininglevel = 100,
storagemining = 100000,
expperlevel = 1500,
experiencemining = 125
}

local stone = {
    blue = {8637, 8633, 9798, 1354},
    green = {8640, 8636, 9791, 1353},
    lightblue = {8638, 8634, 9790, 12344},
    red = {8639, 8635, 9788, 1355},
}

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 = {2146, 7759, 5905, 2158},
    green = {2149, 7761, 12396 ,2155},
    lightblue = {2150, 7762, 12575, 2155},
    red = {2147, 7760, 5906, 2156},
}

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,19},
    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 = 4,
    chance = 10, -- 30
    qtdmax = 1,
    expgainmin = 15, --15
    expgainmax = 50 --50
    },
    {
    level = {20,49},
    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 = 7,
    chance = 10,
    qtdmax = 1,
    expgainmin = 25,
    expgainmax = 75
    },
    {
    level = {50,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 = 10,
    qtdmax = 1,
    expgainmin = 35,
    expgainmax = 95
    },
    {
    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 = 10,
    qtdmax = 1,
    expgainmin = 55,
    expgainmax = 125
    },
    {
    level = {90,100},
    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 = 10,
    qtdmax = 1,
    expgainmin = 125,
    expgainmax = 180
    }
}

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


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

    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 == 100 then
                            doSendMagicEffect(toPosition, 9)
                            doPlayerSendTextMessage(cid, 22, text)
                            doPlayerAddItem(cid, collect, quantity)
                          
                            elseif getMiningLevel <= 99 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.. " matter" ..(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.. " matter" ..(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, "Working.")
                        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(2553)
mining:register()
 
Solution
Here you go.

Lua:
giveMiningExperience(playerId, amount) -- use this function whenever you want to give mining experience.
Lua:
if giveMiningExperience(player:getId(), 1) then
    print("Experience given successfully")
else
    print("Something went wrong.")
end
Lua:
local function giveMiningExperience(playerId, amount)
    local player = Player(playerId)
    if not player then
        print("Error in function giveMiningExperience -> player does not exist (check to ensure playerId being passed to function is correct)")
        return false
    end
 
    -- config table
    local mining = {
        maxLevel = 255,
        experiencePerLevel = 500, -- 0, 500, 1000, 1500, 2000.. et cetera
        storage = {
            level = 45001...
Here you go.

Lua:
giveMiningExperience(playerId, amount) -- use this function whenever you want to give mining experience.
Lua:
if giveMiningExperience(player:getId(), 1) then
    print("Experience given successfully")
else
    print("Something went wrong.")
end
Lua:
local function giveMiningExperience(playerId, amount)
    local player = Player(playerId)
    if not player then
        print("Error in function giveMiningExperience -> player does not exist (check to ensure playerId being passed to function is correct)")
        return false
    end
 
    -- config table
    local mining = {
        maxLevel = 255,
        experiencePerLevel = 500, -- 0, 500, 1000, 1500, 2000.. et cetera
        storage = {
            level = 45001,
            experience = 45002
        }
    }
 
    local miningLevel = player:getStorageValue(mining.storage.level)
    miningLevel = miningLevel >= 0 and miningLevel or 0
 
    local miningExperience = player:getStorageValue(mining.storage.experience)
    miningExperience = miningExperience >= 0 and miningExperience or 0
 
    -- local TotalMiningExperience = (miningLevel * ((mining.experience * (miningLevel - 1))/2)) + miningExperience
 
    miningExperience = miningExperience + amount
 
    if miningLevel < mining.maxLevel then
        repeat    
            local ExperienceRequiredForNextLevel = miningLevel * mining.experiencePerLevel
            if miningExperience >= ExperienceRequiredForNextLevel then
                miningExperience = miningExperience - ExperienceRequiredForNextLevel
                miningLevel = miningLevel + 1
                local text = "You have advanced to mining level " .. miningLevel .. "."
                if miningLevel == mining.maxLevel then
                    text = "You have reached the maximum mining level."
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)
            else
                break
            end
        until (miningLevel == mining.maxLevel)
    end
 
    player:setStorageValue(mining.storage.level, miningLevel)
    player:setStorageValue(mining.storage.experience, miningExperience)
    return true
end
 
Last edited:
Solution
Here you go.

Lua:
giveMiningExperience(playerId, amount) -- use this function whenever you want to give mining experience.
Lua:
if giveMiningExperience(player:getId(), 1) then
    print("Experience given successfully")
else
    print("Something went wrong.")
end
Lua:
local function giveMiningExperience(playerId, amount)
    local player = Player(playerId)
    if not player then
        print("Error in function giveMiningExperience -> player does not exist (check to ensure playerId being passed to function is correct)")
        return false
    end
 
    -- config table
    local mining = {
        maxLevel = 255,
        experiencePerLevel = 500, -- 0, 500, 1000, 1500, 2000.. et cetera
        storage = {
            level = 45001,
            experience = 45002
        }
    }
 
    local miningLevel = player:getStorageValue(mining.storage.level)
    miningLevel = miningLevel >= 0 and miningLevel or 0
 
    local miningExperience = player:getStorageValue(mining.storage.experience)
    miningExperience = miningExperience >= 0 and miningExperience or 0
 
    -- local TotalMiningExperience = (miningLevel * ((mining.experience * (miningLevel - 1))/2)) + miningExperience
 
    miningExperience = miningExperience + amount
 
    if miningLevel < mining.maxLevel then
        repeat   
            local ExperienceRequiredForNextLevel = miningLevel * mining.experiencePerLevel
            if miningExperience >= ExperienceRequiredForNextLevel then
                miningExperience = miningExperience - ExperienceRequiredForNextLevel
                miningLevel = miningLevel + 1
                local text = "You have advanced to mining level " .. miningLevel .. "."
                if miningLevel == mining.maxLevel then
                    text = "You have reached the maximum mining level."
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)
            else
                break
            end
        until (miningLevel == mining.maxLevel)
    end
 
    player:setStorageValue(mining.storage.level, miningLevel)
    player:setStorageValue(mining.storage.experience, miningExperience)
    return true
end

I'll get directly
"Error in function giveMiningExperience -> player does not exist (check to ensure playerId being passed to function is correct)
Working and giving reward, but not Exp
 
I'll get directly
"Error in function giveMiningExperience -> player does not exist (check to ensure playerId being passed to function is correct)
Working and giving reward, but not Exp
So you're not sending a playerId to the function.

If you're unsure what to do, post your current script.
 
Back
Top