Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Draw Experience as Bar in Prompt/Score

Draw Experience as Bar in Prompt/Score

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jtyler   (1 post)  Bio
Date Tue 10 Aug 2010 01:09 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 10 Aug 2010 01:44 AM (UTC)
Message
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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,815 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.