|
aliensurfer Beginner
Joined: 11 Apr 2005 Posts: 17
|
Posted: Mon Mar 26, 2007 3:05 pm
Using #MATH |
Can someone sanity check this for me please?
This script should be able to do two things.
show_contracts will give me a list of everyone I have killed as a Champion. Pretty sure this works as I've got this elsewhere for a different script.
totals should give me a percentage number for each #VAR based on the "contracts" VAR, but I've no idea if I have used #MATH right in the alias, or even if I have the whole syntax correct. (Or even if it is the best way to do it! :) )
#DELCLASS Contract
#CLASS {Contract}
#VAR contracts
#VAR ccompleted
#VAR cfailed
#VAR cexpired
#VAR ccancelled
#VAR cslain
#TRIGGER {You have agreed to the Championing. Good luck!} {#ADD contracts 1}
#TRIGGER {You have succeeded in fullfilling your duties as Champion by slaying} {#ADD ccompleted 1}
#TRIGGER {You have failed in your duties as Champion} {#ADD cfailed 1}
#TRIGGER {Your contract with * has expired} {#ADD cexpired 1}
#TRIGGER {You cancel contract} {#ADD ccancelled 1}
#TRIGGER {You have succeeded in fullfilling your duties as Champion by slaying (*)} {#ADDKEY ccslain {%1} %eval( %db( @cslain, "%1")+1)}
#ALIAS show_contracts {#SAY {%crlf};#SAY %ansi( green)Contract Targets Slain:;#LOOPDB @cslain {#SAYP %ansi( blue, high)~[%ansi( white)%repeat( " ", 4-%len( %val))%val%ansi( blue, high)~] %ansi( grey)%key %repeat( " ", 35-%len( %key))%if( %eval( %len( %key)>35) & %eval( %iskey( @cslain, {%key})\2)=1, %crlf)%if( %eval( %iskey( @cslain, {%key})\2)=0, %crlf)};#IF (%numkeys( @cslain)=0) {#SAY %ansi( white)Nobody slain... get busy!!!}}
#ALIAS totals {#SAY {%crlf};#SAY %ansi( green)Total Contract Statistics:;#SAY {%crlf};#MATH tcompleted (@ccompleted/@contracts)*100;#MATH tfailed (@cfailed/@contracts)*100;#MATH texpired (@cexpired/@contracts)*100;#MATH tcancelled (@ccancelled/@contracts)*100;#SAYP %ansi( blue, high)Contracts Completed: @tcompleted; #IF (%numkeys( @tcompleted)=0) {#SAY %ansi( white)No Contracts Completed!} {%crlf};#SAYP %ansi( blue, high)Contracts Failed: @tfailed; #IF (%numkeys( @tfailed)=0) {#SAY %ansi( white)None Failed, Excelllent!!} {%crlf};#SAYP %ansi( blue, high)Contracts Expired: @texpired {%crlf};#SAYP %ansi( blue, high)Contracts Cancelled: @tcancelled}
#CLASS 0
Thanks! |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Mar 26, 2007 4:33 pm |
zMud uses integer based math. So while this is mathetically accurate "#MATH tcompleted (@ccompleted/@contracts)*100", the integer basis causes the division to result in a 0. Just a small change by commutation of the operators and it will work. #MATH tcompleted {@ccompleted*100/@contracts}
For the most it looks correct. You could probably shorten it some by using %format. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Mar 26, 2007 10:40 pm |
Did you forget about %float()? ZMud defaults to integer math, but with %float() you can force it into floating-point math if at least one member is floated.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|