Draw Experience as Bar in Prompt/Score

Posted by Jtyler on Tue 10 Aug 2010 01:09 AM — 2 posts, 10,117 views.

#0
Seen a few examples of bars drawn for health, mana, movement points and have figured out how to do so in my mud... can't seem to find the right expression to use for experience.

                  if (( exp_level( ch, ch->level + 1 ) - ch->exp ) > 0)
                     percent =  (100 * ( ch->exp ) ) / ( exp_level( ch, ch->level + 1 ) - ch->exp );
                  else
                     percent = -1;
                  if (percent >= 100)
					  sprintf (pbuf, "&wExp[&Y##########&w]" );
                  else if (percent >= 90)
					  sprintf (pbuf, "&wExp[&Y#########&O:&w]" );
                  else if (percent >= 80)
					  sprintf (pbuf, "&wExp[&Y########&O::&w]" );
                  else if (percent >= 70)
					  sprintf (pbuf, "&wExp[&Y#######&O:::&w]" );
                  else if (percent >= 60)
					  sprintf (pbuf, "&wExp[&Y######&O::::&w]" );
                  else if (percent >= 50)
					  sprintf (pbuf, "&wExp[&Y#####&O:::::&w]" );
                  else if (percent >= 40)
					  sprintf (pbuf, "&wExp[&Y####&O::::::&w]" );
                  else if (percent >= 30)
					  sprintf (pbuf, "&wExp[&Y###&O:::::::&w]" );
                  else if (percent >= 20)
					  sprintf (pbuf, "&wExp[&Y##&O::::::::&w]" );
                  else if (percent >= 10)
					  sprintf (pbuf, "&wExp[&Y#&O:::::::::&w]" );
			      else
					  sprintf (pbuf, "&wExp[&O::::::::::&w]" );
                  break;


does draw a bar, but it fills up about half a level gained expwise rather than when you're about to level up.

Would much appreciate anyone helping me figure this one out, thanks.
Australia Forum Administrator #1
You've basically got:


current_xp 
------------------
next_level - current_xp


So, if you have 100 xp for level 1, and 200 xp for level 2, and you are currently at 150 xp, you will have:

 
percent = 100 * 150 / (200 - 150)

ie.

percent = 100 * (150 / 50)

ie.

percent = 300



You really want something like:


next_level - current_xp        (how far through level we are)
------------------
next_level - current_level     (how much xp from start to end of level)


That is, for 150 xp


percent = 100 * (200 - 150) / (200 - 100)

ie.

percent = 100 * 50 / 100

ie.

percent = 50