Author Topic: GetRealHD  (Read 339 times)

Legacy_ultima03

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
GetRealHD
« on: January 08, 2012, 07:45:31 pm »


               Just want some thought or suggestions on how to get the the HD corresponding to the current available XP of creatures/pc's. (ie : returning 40 for a level 1 holding 780.000 xp)

I have my own, wich process level by level, so I'm kind of concerned about its efficiency, and I would appreciate any lighter way to achieve it. I do not want that version wich is a switch-case stating each lvl, nor the version with a lot of if else statments.

Just to let you know my current version


<code>
int GetRealHD(object oPC)
    {
      int i,x,f;
      int nXP = GetXP(oPC);
      if(nXP < 780000)
      {
        for (x = 0; x <= 40; x ++)
        {
          i = ((x * (x - 1)) / 2) * 1000;
          if(nXP < i)
            {
            f = x-1; break;
            }
        }
       }
       else{f = 40;}

    return f;
    }

</code>
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
GetRealHD
« Reply #1 on: January 08, 2012, 07:50:50 pm »


               This is from pwfxp script:

int GetRealHD(object oPC)
{
   return FloatToInt(0.5 + sqrt(0.25 + ( IntToFloat(GetXP(oPC)) / 500 )));
}
               
               

               
            

Legacy_ultima03

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
GetRealHD
« Reply #2 on: January 08, 2012, 07:54:14 pm »


               Thanks. I see that it's from Knat, that guy rocks, I'll let him know once more.
               
               

               


                     Modifié par ultima03, 08 janvier 2012 - 07:55 .
                     
                  


            

Legacy_ultima03

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
GetRealHD
« Reply #3 on: January 08, 2012, 08:14:50 pm »


               

Alex Warren wrote...

This is from pwfxp script:

int GetRealHD(object oPC)
{
   return FloatToInt(0.5 + sqrt(0.25 + ( IntToFloat(GetXP(oPC)) / 500 )));
}



Just tested and it worked perfectly. Just one addition because it goes beyond 40. (I got level 103)

int GetRealHD(object oPC)
    {
    int nXP = GetXP(oPC);
    if(nXP >= 780000){return 40;}
    return FloatToInt(0.5 + sqrt(0.25 + ( IntToFloat(nXP) / 500 )));
    }