 |
remus Wanderer
Joined: 06 Jul 2002 Posts: 53 Location: Australia
|
Posted: Sat Apr 03, 2004 8:32 am
Numbers to percentage |
Greetings Fellow Zmudians,
What I am looking for is a way to capture to a variable the percentage of xp I have gained. I have the Amount needed to get to next level and the amount left before I get there figures.
I have used these as such to get the amount gained figure.
#math gain (@next-@left)
Now what I seek to do is convert it all from numbers to percentages so in the end I have a percentage gained amount.
So instead of my XP button gauge displaying
"You have attained 1234455XP" it will just show
"You are 59% of the way to your next level"
I have not the learned knowledge of Zmuds scripting to do the fomula that will use the available info. The amount of xp left is displayed numerically in my prompt and I have a trigger set to catch this number. The amount in the @next variable I capture at each levelup by manaully typing it using an alias.
Any help would be greatly appreciated.
Oh and here is my first attempt at it, (failed dismally)
#TRIGGER {~$(%d)~>} {#math gain @next-@left;#math xxp @gain/100;#math xxxp @next/100;#math xxxxp @xxxp-@xxp;#math xxxxxp 100-@xxxxp} "" (prompt) |
|
|
 |
Vodoc Apprentice
Joined: 11 Apr 2003 Posts: 119 Location: Sweden
|
Posted: Sat Apr 03, 2004 10:28 am |
What you want to do is something like:
#math gain @next-@left;
#var procent %left(%eval(%float(@gain)/@next*100),5)
or just
#var procent %left(%eval(%float(@next-@left)/@next*100),5) |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Apr 03, 2004 4:50 pm |
Percentages are easy.
If A is X percent of B then
X = (100*A)/B
or
X = A/(B/100)
The second formula is for large numbers, which is what you have.
From your formula it appears that
@next = amount between current level and next level
@left = amount remaining to next level
@gain = amount gained since current level
In that case, the percentage would be @gain compared to @next:
X = @gain/(@next/100)
#TR {~$(%d)~>} {#MATH gain (@next - @left);#MATH xpercent (@gain/(@next/100))} "" (prompt) |
|
|
 |
Ryntrax Wanderer
Joined: 15 Mar 2004 Posts: 55 Location: USA
|
Posted: Sat Apr 03, 2004 5:13 pm |
I have used similar math problems in the past and found that if you are using all integers it will return an integer value. Be sure that if this is true you change one of your numbers to a floating integer when you process the string, this will allow the result to be floating point as well. ); #MATH xpercent (%float(@gain)/(@next/100))} "" (prompt)
|
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Apr 03, 2004 5:36 pm |
%float isn't needed. I intend the formula to return an integer.
|
|
|
 |
|
|