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

TFS 1.X+ Blessings loss experience

jo31

New Member
Joined
May 24, 2010
Messages
70
Reaction score
1
Location
Sweden
Hello Otland!

Server info: TFS 1.3 CLIENT 10.98

I have an issue with the exp loss when a player dies. I have tried to make own formula in player.cpp but it become fucked up so I ask for help from you guys.
I did even try to make so when people kill another player it will receive only 15% exp but that become fucked up to.
I want to make so people with blessings don't lose any levels/magic/skills. But player without blessing will only lose exp, not levels, Like only 40% of the exp.

I have problem making the right formula in player.cpp
 
Hello Otland!

Server info: TFS 1.3 CLIENT 10.98

I have an issue with the exp loss when a player dies. I have tried to make own formula in player.cpp but it become fucked up so I ask for help from you guys.
I did even try to make so when people kill another player it will receive only 15% exp but that become fucked up to.
I want to make so people with blessings don't lose any levels/magic/skills. But player without blessing will only lose exp, not levels, Like only 40% of the exp.

I have problem making the right formula in player.cpp
You can do something like that,
Disable in config.lua lose exp and
Lua:
function onDeath(player, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
   local prevlev = player:getLevel - 1
if player:hasBlessing() then -- Need to define this.
        return true
    end
    local prevlevelexp = (( 50 * prevlev * prevlev * prevlev) - (150 * prevlev * prevlev) + (400 * prevlev)) / 3
    local getexp = player:getExperience()
   
    if getexp > prevlevelexp then
   
    local lose = ((getexp - prevlevelexp) * 0.40) -- "0.40" in % how many of gained experience to next level will drop
    player:removeExperience(lose)
    return true
    end
    end
 
You can do something like that,
Disable in config.lua lose exp and
Lua:
function onDeath(player, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
   local prevlev = player:getLevel - 1
if player:hasBlessing() then -- Need to define this.
        return true
    end
    local prevlevelexp = (( 50 * prevlev * prevlev * prevlev) - (150 * prevlev * prevlev) + (400 * prevlev)) / 3
    local getexp = player:getExperience()
  
    if getexp > prevlevelexp then
  
    local lose = ((getexp - prevlevelexp) * 0.40) -- "0.40" in % how many of gained experience to next level will drop
    player:removeExperience(lose)
    return true
    end
    end
hey is this creaturescript, would help more information bro?
and how do I disable in config

but thanks for ANSWER
 
You can do something like that,
That makes presumptions about formulas and leaves handling blessing, as especially complicated part in Lua, up to someone asking for help. Lua has traditionally been garbage for handling bitwise operators. Why do you think that's the first thing people usually patch Lua for in customized usage?


I have problem making the right formula in player.cpp

As of current master, that formula starts here:
otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/player.cpp#L3857)

What exactly are you wanting to change about it?

Let us look at it. Standby while I comment the shit out of it ~finished!
C++:
// This function returns how much exp the player is going to lose
double Player::getLostPercent() const
{
    // This gives how many blessing the player has gotten
    //     unless otherwise modified, this will be a number 0-5
    int32_t blessingCount = std::bitset<5>(blessings).count();

    // This get the configured percentage loss as defined in the config lua
    int32_t deathLosePercent = g_config.getNumber(ConfigManager::DEATH_LOSE_PERCENT);
    // If you have defined something in the config lua, the number above won't be -1
    //     so this block of code will execute
    if (deathLosePercent != -1) {
        // is our player a promoted class? If so that cuts 3% off his losses
        if (isPromoted()) {
            deathLosePercent -= 3;
        }

        // Losses cut by 1% per blessing
        deathLosePercent -= blessingCount;

        // By here, the most your losses can be cut by are 8%, 3 for promo, 5 blessings
        return std::max<int32_t>(0, deathLosePercent) / 100.;
    }

    // If you did not define a percentage in config lua, we move on!
    double lossPercent;
    // Players at, or above, level 25 get treated different
    if (level >= 25) {
        // This Players level into a float with the percentage of progress as the decimal
        //    so if you were a level 10, and 90% of the way to next level, this would be 10.9
        double tmpLevel = level + (levelPercent / 100.);
        // This is straight math
        /*
            (
                (level + 50)
                * 50
                * (level * level)
                - (5 * tmpLevel)
                + 8
            )
            / exerience
        */
        lossPercent = static_cast<double>((tmpLevel + 50) * 50 * ((tmpLevel * tmpLevel) - (5 * tmpLevel) + 8)) / experience;
    // Players who are below level 25 have a base loss of 10%
    } else {
        lossPercent = 10;
    }

    double percentReduction = 0;
    // Is our player promotod? We cut their losses by 30%
    if (isPromoted()) {
        percentReduction += 30;
    }
    // Does our player have blessings? We cut their losses by an additional 8% per blessing.
    percentReduction += blessingCount * 8;
    // More math
    return lossPercent * (1 - (percentReduction / 100.)) / 100.;
}
 
Last edited:
That makes presumptions about formulas and leaves handling blessing, as especially complicated part in Lua, up to someone asking for help. Lua has traditionally been garbage for handling bitwise operators. Why do you think that's the first thing people usually patch Lua for in customized usage?




As of current master, that formula starts here:
otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/player.cpp#L3857)

What exactly are you wanting to change about it?

Let us look at it. Standby while I comment the shit out of it ~pending

C++:
// This function returns how much exp the player is going to lose
double Player::getLostPercent() const
{
    // This gives how many blessing the player has gotten
    //     unless otherwise modified, this will be a number 0-5
    int32_t blessingCount = std::bitset<5>(blessings).count();

    // This get the configured percentage loss as defined in the config lua
    int32_t deathLosePercent = g_config.getNumber(ConfigManager::DEATH_LOSE_PERCENT);
    // If you have defined something in the config lua, the number above won't be -1
    //     so this block of code will execute
    if (deathLosePercent != -1) {
        // is our player a promoted class? If so that cuts 3% off his losses
        if (isPromoted()) {
            deathLosePercent -= 3;
        }

        // Losses cut by 1% per blessing
        deathLosePercent -= blessingCount;

        // By here, the most your losses can be cut by are 8%, 3 for promo, 5 blessings
        return std::max<int32_t>(0, deathLosePercent) / 100.;
    }

    // If you did not define a percentage in config lua, we move on!
    double lossPercent;
    // Players at, or above, level 25 get treated different, those who are below have a base loss of 10%
    if (level >= 25) {
        double tmpLevel = level + (levelPercent / 100.);
        lossPercent = static_cast<double>((tmpLevel + 50) * 50 * ((tmpLevel * tmpLevel) - (5 * tmpLevel) + 8)) / experience;
    } else {
        lossPercent = 10;
    }

    double percentReduction = 0;
    if (isPromoted()) {
        percentReduction += 30;
    }
    percentReduction += blessingCount * 8;
    return lossPercent * (1 - (percentReduction / 100.)) / 100.;
}
Im pretty low in c++, thats right :D
Good to get solve in c++, let me understand this a little,
Explain please this line:
Code:
        double tmpLevel = level + (levelPercent / 100.);

        lossPercent = static_cast<double>((tmpLevel + 50) * 50 * ((tmpLevel * tmpLevel) - (5 * tmpLevel) + 8)) / experience;
And this prevent player from lose level?
 
~pending 👈 go back and look again

You want to make it so player can never lose experience past the point of "0 for his current level" ? So like they could be level 250, and die like ~20 times and will still be level 250? That would have to be done in the function that calls this function, somewhere else.
 
Last edited:
~pending 👈 go back and look again


You want to make it so player can never lose experience past the point of "0 for his current level" ? So like they could be level 250, and die like ~20 times and will still be level 250? That would have to be done in the function that calls this function, somewhere else.
Thats right, and my lua is for this :eek:
 
That would be something like this. Though I'd have to go double check on the typings needed.
void Player::death(Creature* lastHitCreature) player.cpp, line ~1888

~~~ scratch that one ~~~

actually... maybe like this...
Diff:
         //Level loss
         uint64_t expLoss = static_cast<uint64_t>(experience * deathLossPercent);
         g_events->eventPlayerOnLoseExperience(this, expLoss);
         if (expLoss != 0) {
             uint32_t oldLevel = level;

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

+            experience = std::max<uint64_t>(experience, Player::getExpForLevel(level))
             while (level > 1 && experience < Player::getExpForLevel(level)) {

So this lets them lose all their progress, but not their levels.

This is pretty much identical to math.max in Lua by the way 🤷‍♂️ Only you have to worry about the static typing in C++. Literally the only difference.
 
Last edited:
As you see :D
I added in
Code:
creaturescripts/playerdeath.lua
After this lines:

Code:
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end

This lines:

Code:
local prevlevelexp = (( 50 * (player:getLevel() - 1) * (player:getLevel() - 1) * (player:getLevel() - 1)) - (150 * (player:getLevel() - 1) * (player:getLevel() - 1)) + (400 * (player:getLevel() - 1))) / 3
    local getexp = player:getExperience()
  
    if getexp >= prevlevelexp + 1 then
  
    local lose = ((getexp - prevlevelexp) * 0.40) -- "0.40" in % how many of gained experience to next level will drop
    player:removeExperience(lose)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
        return
    end
And its works perfect
 
But you are using a different formula than what is in source. And it doesn't solve what OP asked for, now that I see what they actually want, since they want to protect skills too. But it does seem like OP could get what they want pretty close just by setting the loss rate to 8% in config.
 
Hello guys, please could anyone tell me how do I set the minimum server level to 550? Do I do it through creaturescripts or player.cpp?
I'm using Canary 13.21 data

and how can I set it to earn 5k gold when killing a player?
 
Back
Top