• 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 Level lock

AdventureOts

Member
Joined
Sep 26, 2016
Messages
74
Reaction score
17
I am trying to put a lock on my server that only allows players to level x amount of times when killing a monster.

This code seems like it should work but doesn't. Any help?

Code:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onAdvance(cid, skill, oldLevel, newLevel)
    if newLevel <= oldLevel then
        return true
    end
    player = Player(cid)
    if not player then return true end
   
    if skill == SKILL_LEVEL then
        count = 0
        level_lock = oldLevel + 20
       
        if newLevel > level_lock then
            while player:getLevel() > level_lock do
                player:removeExperience(getExpForLevel(player:getLevel()))
            end
        end
    end
    return true
end
 
Edit: Going to be annoying adding names in. Would rather 1 script can handle it all without the need of adding in any new values.
maybe im not understanding what you're trying to say
what i interpreted was you wanted specific monsters to give a set amount of levels
 
Yes, but I want the code to handle every monster without the need to put in specific monsters. All monster will have the level lock. Even ones that don't need it.

It seems the onAdvance doesnt work because it registers each level as a new advance rather than all at once.
 
Yes, but I want the code to handle every monster without the need to put in specific monsters. All monster will have the level lock. Even ones that don't need it.
that doesnt really make sense though
how would you make all monsters give different levels without having to edit any values
 
Okay, the monster gives 10000 exp.... When the player kills it, it gives him those levels. What I want to do is put in a code that makes sure he isn't going over 20 levels when he gets that exp. If he does then stop him at 20 levels.

So lets say we have 3 monsters.....

1 has 10k exp
2 has 1kk exp
3 has 10kk exp

If a player is level 1 and kills any of those monsters he will only get 20 levels at max from them.
 
Code:
local cap = 20

function onAdvance(cid, skill, oldLevel, newLevel)
    if skill == SKILL__LEVEL then
        local value = newLevel - oldLevel
        if value > cap then
            doPlayerAddLevel(cid, -(value-cap))
        end
    end
    return true
end

like this?
 
print troubleshoot
Code:
local cap = 20

function onAdvance(cid, skill, oldLevel, newLevel)
    print('execute')
    if skill == SKILL__LEVEL then
        local value = newLevel - oldLevel
        print(value)
        if value > cap then
            value = -(value-cap)
            print(value)
            doPlayerAddLevel(cid, value)
        end
    end
    return true
end
 
Alright, I decided to just do onKill.

What is wrong with this code? It seems like it doesn't add to the COUNT

It gives my guy all the exp.

Code:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

local monsters = {
["Test Monster"] = {exp = 99999999999999}
}

function onKill(creature, target)
player = Player(creature)
    if not player then return true end
    MONS = monsters[target:getName()]
        if not MONS then return true end
        EXP = MONS.exp
        COUNT = 0
   
    while getExpForLevel(player:getLevel() + 1) <= EXP and COUNT < 20 do
        COUNT = COUNT + 1
        EXP = EXP - getExpForLevel(player:getLevel() + 1)
        player:addExperience(getExpForLevel(player:getLevel() + 1), false)
    end
   
    return true
end

Edit: I have the same type of code for leveling up pets on my server and it works just fine....So i am not getting why it doesn't work.
 
Last edited:
You can just block gain exp when you reached level lock. You can find it in events folder.
 
Worked like a charm, ty printer. I always forget to check the events.

Here is code to put in onGainExperience event

Code:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

if exp > getExpForLevel(self:getLevel() + 20) - self:getExperience() then
        exp = getExpForLevel(self:getLevel() + 20) - self:getExperience()
end
 
Back
Top