• 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+ [tfs 1.3] How can i make player dont lose skill Fishing dying

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
How can I make the player not lose skill fishing dying?
just skill fishing
 
Solution
In file player.cpp You have structure like this

C++:
//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...
In file player.cpp You have structure like this

C++:
//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));
        }

Replace this fragment of code
Code:
uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
with
Code:
if (i == SKILL_FISHING) {
    uint32_t lostSkillTries = 0;
} else {
    uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
}

When skill loss counting loop "targets" fishing skill, instead of calculating lost tries, it will set it to 0, what means that no skill tries will be lost,
No skill tries loss equals no skill loss.
 
In file player.cpp You have structure like this

C++:
//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));
        }

Replace this fragment of code
Code:
uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
with
Code:
if (i == SKILL_FISHING) {
    uint32_t lostSkillTries = 0;
} else {
    uint32_t lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
}

When skill loss counting loop "targets" fishing skill, instead of calculating lost tries, it will set it to 0, what means that no skill tries will be lost,
No skill tries loss equals no skill loss.
Those variables are inaccessible because of the scope you're declaring them in, you're not reassigning.
Either way you should just be replacing the loop condition's limit:
C++:
for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST - 1; ++i) { //for each skill
OR
C++:
for (uint8_t i = SKILL_FIRST; i < SKILL_LAST; ++i) { //for each skill
 
Solution
@Stigma I see my mistake, and of course answer which You provided is correct.
However my intention in making code such like this was to ensure that no matter which skill is last (SKILL_LAST) code will run correctly,
of course my previous code wasn't working but i just wonder if using something like this will be safer and non-dependent from number of skills and their index

Inside for loop at beginning
C++:
if (i == SKILL_FISHING)
    continue;
 
@Stigma I see my mistake, and of course answer which You provided is correct.
However my intention in making code such like this was to ensure that no matter which skill is last (SKILL_LAST) code will run correctly,
of course my previous code wasn't working but i just wonder if using something like this will be safer and non-dependent from number of skills and their index

Inside for loop at beginning
C++:
if (i == SKILL_FISHING)
    continue;
Originally I was going to go with a continue statement like that, but then I realized fishing was SKILL_LAST, so the better solution is removing that iteration completely rather than just skipping it 100% of the time.
 
Back
Top