• 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+ How can I prevent magic/skill from being lost upon death Tfs 1.2

abdala ragab

Veteran OT User
Joined
Aug 18, 2018
Messages
461
Solutions
11
Reaction score
340
Location
gamelaot.sytes.net
The magic level also decreases a lot, as well as the skill level. I want to prevent them from decreasing upon death
How can i do that
I hope someone can help me, thanks in advance
This is the code I found in player.cpp
C++:
        //Magic level loss
        uint64_t sumMana = 0;
        uint64_t lostMana = 0;

        //sum up all the mana
        for (uint32_t i = 1; i <= magLevel; ++i) {
            sumMana += vocation->getReqMana(i);
        }

        sumMana += manaSpent;

        double deathLossPercent = getLostPercent();

        lostMana = static_cast<uint64_t>(sumMana * deathLossPercent);

        while (lostMana > manaSpent && magLevel > 0) {
            lostMana -= manaSpent;
            manaSpent = vocation->getReqMana(magLevel);
            magLevel--;
        }

        manaSpent -= lostMana;

        uint64_t nextReqMana = vocation->getReqMana(magLevel + 1);
        if (nextReqMana > vocation->getReqMana(magLevel)) {
            magLevelPercent = Player::getPercentLevel(manaSpent, nextReqMana);
        } else {
            magLevelPercent = 0;
        }

        //Skill loss
        for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { //for each skill
            uint64_t sumSkillTries = 0;
            for (uint16_t c = 11; c <= skills[i].level; ++c) { //sum up all required tries for all skill levels
                sumSkillTries += vocation->getReqSkillTries(i, c);
            }

            sumSkillTries += skills[i].tries;

            uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
            while (lostSkillTries > skills[i].tries) {
                lostSkillTries -= skills[i].tries;

                if (skills[i].level <= 10) {
                    skills[i].level = 10;
                    skills[i].tries = 0;
                    lostSkillTries = 0;
                    break;
                }

                skills[i].tries = vocation->getReqSkillTries(i, skills[i].level);
                skills[i].level--;
            }

            skills[i].tries = std::max<int32_t>(0, skills[i].tries - lostSkillTries);
            skills[i].percent = Player::getPercentLevel(skills[i].tries, vocation->getReqSkillTries(i, skills[i].level));
        }
 
Solution
Wrap it in an if so you can use a bool to set it true or false? or delete the code entirely?


C++:
bool preventMagicLoss = true;

if (!preventMagicLoss) {
    //Magic level loss
    uint64_t sumMana = 0;
    uint64_t lostMana = 0;

    //sum up all the mana
    for (uint32_t i = 1; i <= magLevel; ++i) {
        sumMana += vocation->getReqMana(i);
    }

    sumMana += manaSpent;

    double deathLossPercent = getLostPercent();

    lostMana = static_cast<uint64_t>(sumMana * deathLossPercent);

    while (lostMana > manaSpent && magLevel > 0) {
        lostMana -= manaSpent;
        manaSpent = vocation->getReqMana(magLevel);
        magLevel--;
    }

    manaSpent -= lostMana;

    uint64_t nextReqMana = vocation->getReqMana(magLevel +...
Wrap it in an if so you can use a bool to set it true or false? or delete the code entirely?


C++:
bool preventMagicLoss = true;

if (!preventMagicLoss) {
    //Magic level loss
    uint64_t sumMana = 0;
    uint64_t lostMana = 0;

    //sum up all the mana
    for (uint32_t i = 1; i <= magLevel; ++i) {
        sumMana += vocation->getReqMana(i);
    }

    sumMana += manaSpent;

    double deathLossPercent = getLostPercent();

    lostMana = static_cast<uint64_t>(sumMana * deathLossPercent);

    while (lostMana > manaSpent && magLevel > 0) {
        lostMana -= manaSpent;
        manaSpent = vocation->getReqMana(magLevel);
        magLevel--;
    }

    manaSpent -= lostMana;

    uint64_t nextReqMana = vocation->getReqMana(magLevel + 1);
    if (nextReqMana > vocation->getReqMana(magLevel)) {
        magLevelPercent = Player::getPercentLevel(manaSpent, nextReqMana);
    } else {
        magLevelPercent = 0;
    }



        //Skill loss
        for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { //for each skill
            uint64_t sumSkillTries = 0;
            for (uint16_t c = 11; c <= skills[i].level; ++c) { //sum up all required tries for all skill levels
                sumSkillTries += vocation->getReqSkillTries(i, c);
            }

            sumSkillTries += skills[i].tries;

            uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
            while (lostSkillTries > skills[i].tries) {
                lostSkillTries -= skills[i].tries;

                if (skills[i].level <= 10) {
                    skills[i].level = 10;
                    skills[i].tries = 0;
                    lostSkillTries = 0;
                    break;
                }

                skills[i].tries = vocation->getReqSkillTries(i, skills[i].level);
                skills[i].level--;
            }

            skills[i].tries = std::max<int32_t>(0, skills[i].tries - lostSkillTries);
            skills[i].percent = Player::getPercentLevel(skills[i].tries, vocation->getReqSkillTries(i, skills[i].level));
        }
    }
 
Last edited:
Solution
Wrap it in an if so you can use a bool to set it true or false? or delete the code entirely?
Severity Code Description Project File Line Suppression State
Error C2065 'deathLossPercent': undeclared identifier theforgottenserver C:\Users\Abdalahost\Desktop\abdala src\src\player.cpp 2458
I don't understand well what you mean, but I tried the code you sent and I received this error during compilation
 
Severity Code Description Project File Line Suppression State
Error C2065 'deathLossPercent': undeclared identifier theforgottenserver C:\Users\Abdalahost\Desktop\abdala src\src\player.cpp 2458
I don't understand well what you mean, but I tried the code you sent and I received this error during compilation


Try and put the
double deathLossPercent = getLostPercent();
above the new if statement
if (!preventMagicLoss)

The compiler error is stating that the variable 'deathLossPercent' is out of scope because it is wrapped inside the if ()
 
Try and put the
double deathLossPercent = getLostPercent();
above the new if statement
if (!preventMagicLoss)

The compiler error is stating that the variable 'deathLossPercent' is out of scope because it is wrapped inside the if ()
Thank you, it was solved thanks to your experience
Why doesn't this post have the best answer to give you?
 
Back
Top