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

Compiling Why sometimes server freeze after i added it

maikons

Member
Joined
Aug 1, 2015
Messages
227
Reaction score
16
Why sometimes when a guy die in my server freeze after i added it on my sources to increase skills losses ondeath?

I'm using 0.4 sources

I just added a * 5 in player.cpp

Code:
    lostMana = (uint64_t)std::ceil(sumMana * ((double)(percent * 5 * lossPercent[LOSS_MANA]) / 100.));
     lostSkillTries = (uint32_t)std::ceil(sumSkillTries * ((double)(percent * 5 * lossPercent[LOSS_SKILLS]) / 100.));


Code:
  if(skillLoss)
   {
     uint64_t lossExperience = getLostExperience();
     removeExperience(lossExperience, false);
     double percent = 1. - ((double)(experience - lossExperience) / experience);

     //Magic level loss
     uint32_t sumMana = 0;
     uint64_t lostMana = 0;
     for(uint32_t i = 1; i <= magLevel; ++i)
       sumMana += vocation->getReqMana(i);

     sumMana += manaSpent;
     lostMana = (uint64_t)std::ceil(sumMana * ((double)(percent * 5 * lossPercent[LOSS_MANA]) / 100.));
     while(lostMana > manaSpent && magLevel > 0)
     {
       lostMana -= manaSpent;
       manaSpent = vocation->getReqMana(magLevel);
       magLevel--;
     }

     manaSpent -= std::max((int32_t)0, (int32_t)lostMana);
     uint64_t nextReqMana = vocation->getReqMana(magLevel + 1);
     if(nextReqMana > vocation->getReqMana(magLevel))
       magLevelPercent = Player::getPercentLevel(manaSpent, nextReqMana);
     else
       magLevelPercent = 0;

     //Skill loss
     uint32_t lostSkillTries, sumSkillTries;
     for(int16_t i = 0; i < 7; ++i) //for each skill
     {
       lostSkillTries = sumSkillTries = 0;
       for(uint32_t c = 11; c <= skills[i][SKILL_LEVEL]; ++c) //sum up all required tries for all skill levels
         sumSkillTries += vocation->getReqSkillTries(i, c);

       sumSkillTries += skills[i][SKILL_TRIES];
       lostSkillTries = (uint32_t)std::ceil(sumSkillTries * ((double)(percent * 5 * lossPercent[LOSS_SKILLS]) / 100.));
       while(lostSkillTries > skills[i][SKILL_TRIES])
       {
         lostSkillTries -= skills[i][SKILL_TRIES];
         skills[i][SKILL_TRIES] = vocation->getReqSkillTries(i, skills[i][SKILL_LEVEL]);
         if(skills[i][SKILL_LEVEL] < 11)
         {
           skills[i][SKILL_LEVEL] = 10;
           skills[i][SKILL_TRIES] = lostSkillTries = 0;
           break;
         }
         else
           skills[i][SKILL_LEVEL]--;
       }

       skills[i][SKILL_TRIES] = std::max((int32_t)0, (int32_t)(skills[i][SKILL_TRIES] - lostSkillTries));
     }

     blessings = 0;
     loginPosition = masterPosition;
     if(!inventory[SLOT_BACKPACK])
       __internalAddThing(SLOT_BACKPACK, Item::CreateItem(g_config.getNumber(ConfigManager::DEATH_CONTAINER)));

     sendIcons();
     sendStats();
     sendSkills();

     g_creatureEvents->playerLogout(this, true);
     g_game.removeCreature(this, false);
     sendReLoginWindow();
   }
   else
   {
     setLossSkill(true);
     if(preventLoss)
     {
       loginPosition = masterPosition;
       g_creatureEvents->playerLogout(this, true);
       g_game.removeCreature(this, false);
       sendReLoginWindow();
     }
   }
 
Well if you we look at this line.
Code:
double percent = 1. - ((double)(experience - lossExperience) / experience);
We see that percent is a number which is less then 1.

While here you are amongst other places.
Code:
lostSkillTries = (uint32_t)std::ceil(sumSkillTries * ((double)(percent * 5 * lossPercent[LOSS_SKILLS]) / 100.));
Multiplying a less then 1 number by 5, hypothetically if percent was 0.5 / some value and then divided by 100 gave a correct formula and you came along and altered that formula to increase the percent by 5, this would make that formula possibly an invalid number for an uint32_t data-type to handle.

If you don't know how the code works, its best not to mess with it, that is why I don't mess with the sources. ;)
 
Well if you we look at this line.
Code:
double percent = 1. - ((double)(experience - lossExperience) / experience);
We see that percent is a number which is less then 1.

While here you are amongst other places.
Code:
lostSkillTries = (uint32_t)std::ceil(sumSkillTries * ((double)(percent * 5 * lossPercent[LOSS_SKILLS]) / 100.));
Multiplying a less then 1 number by 5, hypothetically if percent was 0.5 / some value and then divided by 100 gave a correct formula and you came along and altered that formula to increase the percent by 5, this would make that formula possibly an invalid number for an uint32_t data-type to handle.

If you don't know how the code works, its best not to mess with it, that is why I don't mess with the sources. ;)

I trough it was simple...
Because i just want add more skills penalty with no change exp penalty...

Now im scare to make some errors
Did you know whats the right way to make it?
 
Back
Top