|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Wed Jan 21, 2004 11:16 pm
Help with #MATH |
In my MUD there is a command that shows an output that looks like this.
quote: Clan Mortality Statistics:
* NPCs slain by members: [286247 ] Members slain by NPCs: [5353 ]
* LPKs by clan members: [2251 ] Members LPKed: [1955 ]
* NPKs by clan members: [4192 ] Members NPKed: [2857 ]
* CPKs by clan members: [233 ] Members CPKed: [105 ]
* PKs out of normal PK: [1015 ] Members PKed out of normal PK: [1671 ]
I am trying to turn these figures into percents with decimal points but have been thus far unsuccessful. i am working with CPK in this example but i would like to have the output for all of the statistics. this is what i have thus far.
quote:
#VAR CPKPER 0
#VAR number1 0
#VAR number2 0
#TR {~* CPKs by clan members~: ~[%1 ~] Members CPKed~: ~[%2 ~]} {#VAR number1 %1;#VAR number2 %2
#VAR CPKPER #MATH @number1*100/@number2}
|
|
|
|
Guede Wanderer
Joined: 30 Nov 2003 Posts: 65 Location: United Kingdom
|
Posted: Thu Jan 22, 2004 12:16 am |
You need to turn the numbers into floating point numbers first as I think zMUD treats numbers as integers by default to do the % calculation:
#MATH %float((%float(@number1)*100)/%float(@number2))
should do the trick if I've got it correct. I had a similar thing that I use to check the progress of something on the mapper (colouring a large group of rooms of the same name) and the variable I have has this as it's value:
%concat( %int( %eval( %float( @progress)/%float( %numrooms( )))*100), "%")
Replace %int with %float I think to give a floating point answer, but accurate to nearest whole number was good enough for me.
-G- |
|
|
|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Thu Jan 22, 2004 6:22 am |
ive at least gotten SOMEWHERE trying it this way.
#TR {^* CPKs by clan members: ~[%1 ~] Members CPKed: ~[%2 ~]} {#MATH CPKPER %2/%1;~say @CPKPER}
but for some dam reason its not working. however, this is what it IS doing. its creating a class folder named 233 (which is the value of %2) and inside it there is a variable named CPKPER with a value of 105 (which is the value of %1) im completely confused now... thank you for any assistance. |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Thu Jan 22, 2004 6:51 am |
It is good practice to avoid using %* wildcards (%1,%2 etc) in the trigger pattern. Since you're matching numbers, %d wildcard will do the trick.
Also, * is a wildcard that matches any number of alphanumeric and whitespace characters. So you need a ~ in front so zmud doesn't parse it as a wildcard:
#trigger {^~* CPKs by clan members: ~[%d ~] Members CPKed: ~[%d ~]} {#Var CPKPER {%float(%float(%2)/%float(%1))}}
Edit: Removed an extra { |
|
|
|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Thu Jan 22, 2004 7:16 am |
nope. a popup window presents itself saying error triggering (the name of the trigger) and makes me click it repeatedly until it line by line catches up with the current mud output.. not only that. it just doesnt work. it doesnt redefine the value of CPKPER at all.
thank you though :) |
|
|
|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Thu Jan 22, 2004 6:57 pm |
i confess to my ignorance at scripting... i would appreciate it if whoever replies expands my pitiful research to contain all of the statistics :( If more information is needed, please let me know and i will provide it. ive spent hours and hours searching the help files to no avail.
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Jan 22, 2004 8:58 pm |
#TR {NPCs slain by members:%s~[(%d)} {#VAR NPC1 %1}
#TR {Members slain by NPCs:%s~[(%d)} {#VAR NPC2 %1;#MATH NPCper (%float( @NPC1) *100)/@NPC2}
#TR {LPKs by clan members:%s~[(%d)} {#VAR LPK1 %1}
#TR {Members LPKed:%s~[(%d)} {#VAR LPK2 %1;#MATH LPKper (%float( @LPK1) *100)/@LPK2}
#TR {PKs out of normal PK:%s~[(%d)} {#VAR PK1 %1}
#TR {Members PKed out of normal PK:%s~[(%d)} {#VAR PK2 %1;#MATH PKper (%float( @PK1) *100)/@PK2}
I could easily have done the rest of the triggers but so could you. It's just a matter of replacing the L with N or C in the middle two triggers. |
|
|
|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Thu Jan 22, 2004 10:23 pm |
does zMUD use PEDMAS to solve problems? to get the % of wins out of the number of total LPKs i am trying to do
#TR {LPKs by clan members:%s~[(%d)} {#VAR LPK1 %1}
#TR {Members LPKed:%s~[(%d)} {#VAR LPK2 %1;#MATH LPKper @LPK1/(@LPK1+@LPK2)} |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Jan 23, 2004 5:04 am |
I don't have the slightest idea what PEDMAS is.
zMUD uses integer math. Your formula is guaranteed to give a result of 0 in almost all cases, since the numerator (@LPK 1) will almost always be smaller than the denominator (@LPK1 + @LPK2). |
|
|
|
Brujah Wanderer
Joined: 13 Nov 2002 Posts: 88 Location: USA
|
Posted: Fri Jan 23, 2004 5:29 am |
PEDMAS is the order in which to correctly solve math functions. parenthesis, exponents, divide/multiply, add/subtract.
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Jan 23, 2004 8:07 am |
Thanks. zMUD does evaluate parentheses first, and does mulitiplication and division ahead of addition and subtraction. It doesn't have exponent operators.
To get a percentage, you'll want to multiply the numerator by 100 before dividing. To get a fractional value, you should use the %float function somewhere within the formula. It only needs to be used once, if floating point is used at all it will apply to the whole formula. |
|
|
|
|
|