• 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 HELP WITH SCRIPT

paulvzla

New Member
Joined
Jun 20, 2015
Messages
23
Reaction score
4
Hi i put this line on login.lua
if player:getLevel() < 45
then
player:addExperience(120000)
end
to reset the lvl from character after die and get lvl 44 but it only works when you die and cancel the box with the message saying youre dead and you need to re log to get the exp , help me please :)
 
I really did not understand very well but what if you try with addevent
Lua:
addEvent(function()
if player:getLevel() < 45 then
    player:addExperience(120000)
end
  end, 1000)
 
I really did not understand very well but what if you try with addevent
Lua:
addEvent(function()
if player:getLevel() < 45 then
    player:addExperience(120000)
end
  end, 1000)
where should i put this ?
im looking for a script for a war server so when you get downgraded to lvl 44 you reset the lvl 45 that is the start level from characters
 
where should i put this ?
im looking for a script for a war server so when you get downgraded to lvl 44 you reset the lvl 45 that is the start level from characters
add in globalevents

function onThink(interval)
for _, name in ipairs(getOnlinePlayers()) do
local cid = getPlayerByName(name)

if getPlayerLevel(cid) < 45 then
doPlayerAddExperience(cid,120000)
end
return true
end
end
 
try :
\data\events\scripts\player.lua
Lua:
function Player:onLoseExperience(exp)
    if self:getLevel() < 45 then
        exp = math.floor(exp * 0)
    end
    
return hasEventCallback(EVENT_CALLBACK_ONLOSEEXPERIENCE) and EventCallback(EVENT_CALLBACK_ONLOSEEXPERIENCE, self, exp) or exp
end
 
Hi i put this line on login.lua
if player:getLevel() < 45
then
player:addExperience(120000)
end
to reset the lvl from character after die and get lvl 44 but it only works when you die and cancel the box with the message saying youre dead and you need to re log to get the exp , help me please :)

Not in lua but this seems a lot easier by editing the source.

In player.cpp under the Player::death function look for

C++:
if (expLoss != 0) {

change that whole part to

C++:
if (expLoss != 0) {
    uint32_t oldLevel = level;

    if (vocation->getId() == VOCATION_NONE || level > 7) {
            experience -= expLoss;
    }

    while (level > 45 && experience < Player::getExpForLevel(level)) {
            --level;
            healthMax = std::max<int32_t>(0, healthMax - vocation->getHPGain());
            manaMax = std::max<int32_t>(0, manaMax - vocation->getManaGain());
            capacity = std::max<int32_t>(0, capacity - vocation->getCapGain());
    }

    if (level < 45) {
            level = 45;
    }

    if (oldLevel != level) {
            sendTextMessage(MESSAGE_EVENT_ADVANCE,
                fmt::format("You were downgraded from Level {:d} to Level {:d}.", oldLevel, level));
    }

    uint64_t currLevelExp = Player::getExpForLevel(level);
    uint64_t nextLevelExp = Player::getExpForLevel(level + 1);
    if (nextLevelExp > currLevelExp) {
            levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);
    } else {
        levelPercent = 0;
}
 
Lua:
local ec = EventCallback
function ec.onLoseExperience(player, exp)
    return player:getExperience() - math.max(Game.getExperienceForLevel(45), player:getExperience() - exp)
end
ec:register(-1)
 
Back
Top