• 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] Automatic generating exp stages

xiduzo

New Member
Joined
Sep 8, 2015
Messages
2
Reaction score
2
Looking for a way to have balanced experience stages and can't find an easy way to do so? Try out this little piece of code I made:

Code:
-- MADE BY: Xiduzo
-- If you want to enable exp_stages, make sure that you have experience_stages = true at your config.lua
local MAX_LEVEL = 350
local MAX_EXP_RATE = 125
local LEVEL_STEPS = 10

local LEVEL_STAGES_SIZE = math.floor(MAX_LEVEL / LEVEL_STEPS)

stages = {}

function getStageMultiplier(level)
    local stage = math.floor(level / LEVEL_STAGES_SIZE)
    local exp_rate = MAX_EXP_RATE * math.pow(math.pow(1/MAX_EXP_RATE, 1/15), stage)
    return  math.ceil(exp_rate)
end

for level = 0, MAX_LEVEL do
    if (math.fmod(level, LEVEL_STAGES_SIZE) == 0) then
        if(level + LEVEL_STAGES_SIZE - 1 >= MAX_LEVEL) then
            table.insert(stages, {
             minLevel = level,
                multiplier = getStageMultiplier(level)
            })
        else
            table.insert(stages, {
             minLevel = level,
             maxLevel = level + LEVEL_STAGES_SIZE - 1,
                multiplier = getStageMultiplier(level)
            })
        end
    end
end

This will generate an exponential decreasing experience rate:

Code:
stage    min    max    multiplier
1        0      34     125
2        35     69     91
3        70     104    66
4        105    139    49
5        140    174    35
6        175    209    25
7        210    244    19
8        245    279    14
9        280    314    10
10       315    349    7
11       350    -      5

Change the MAX_LEVEL, MAX_EXP_RATE, LEVEL_STEPS to customize the rates for your server!
 
can't seem to find the edit buttons anywhere so... EDIT:

You'll need to have a max level at any stage, use this code below to get working stages


Code:
local MAX_LEVEL = 350
local MAX_EXP_RATE = 125
local LEVEL_STEPS = 10

local LEVEL_STAGES_SIZE = math.floor(MAX_LEVEL / LEVEL_STEPS)

stages = {}

function getStageMultiplier(level)
    local stage = math.floor(level / LEVEL_STAGES_SIZE)
    local exp_rate = MAX_EXP_RATE * math.pow(math.pow(1/MAX_EXP_RATE, 1/15), stage)
    return math.ceil(exp_rate)
end

for level = 0, MAX_LEVEL do
    if (math.fmod(level, LEVEL_STAGES_SIZE) == 0) then
        table.insert(stages, {
         minLevel = level,
         maxLevel = level + LEVEL_STAGES_SIZE - 1,
            multiplier = getStageMultiplier(level)
        })
    end
end
 
Back
Top