Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Thu Jan 20, 2005 5:14 pm   

Counting Coins
 
I am trying to write some triggers which will count the number of coins I have in each type of pouch.
Here is the same output
<****** / ||||| > count
You begin searching through your belongings, taking a tally of your coin.

<****** / ||||| >
By your count, you have 952 coppers' worth in coin:

1 thin, ridged silver coin (right hand): 50 coppers
2 heavy, oblong silver coins (left hand): 400 coppers
3 large, rounded bronze coins (a simple indigo leather pouch): 15 coppers
12 semicircular copper coins (a simple yellow leather pouch): 12 coppers
25 large, rounded bronze coins (a simple yellow leather pouch): 125 coppers
7 thin, ridged silver coins (a simple yellow leather pouch): 350 coppers


I may or may not have more than one pouch or a coin in my hand. I would like to have it counted by
1) coins held in hands -total amount
2) total coins in each type of bag

Thanks
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jan 20, 2005 5:57 pm   
 
First you need to set up an alias on the count command:
#ALIAS count {#VAR coinsOnHand 0;#VAR coinsInPouches {};~count}

This alias resets the variables that will store the amount of coins you have and sends the count command to the MUD. Next you need a set of triggers for counting the coins. One for counting what's in your hands:
#TRIGGER {%d * ~({right|left} hand~): (%d) coppers} {#ADD coinsOnHand {%1}

And another one for counting coins inside of pouches:
#TRIGGER {%d * ~((*)~): (%d) coppers} {#ADDKEY coinsInPouches {%1} {%eval(%db(@coinsInPouches, "%1") + %2)}}

This trigger keeps the amount of coins in each pouch in a record variable where the keys are the names of the pouches and the values are the coins in the pouch. Every time it sees a line indicating how many coins there are ina pouch, it sets the value for that pouch to the actual value plus whatever the line says.

After the output of the count command is done, you can then use the following alias to display the total amount you have on hand and in each pouch:
#ALIAS displayCount {#SH On hand: @coinsOnHand;#SH %expanddb(@coinsInPouches, %crlf, ": ")}
_________________
Kjata
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Thu Jan 20, 2005 7:30 pm   
 
Kjata,
That works great, but I would like to display it with some color added.
Like below:
Tally
--------------------------------
On hand: 0
a simple indigo leather pouch: 15
a simple yellow leather pouch: 937

--------------------------------

I tried to do this with the %ansi function but you don't get a many colors as I would when I use the MXP tags like <color cornflowerblue>Tally</color>
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Jan 20, 2005 10:11 pm   
 
Could use #color or #cw then use hex values to assign any colour (prefix the hex value with $, so $000000 for black, $ffffff for white, and whatever inbetween)

So alter the alias to

#ALIAS displayCount {#SH On hand: @coinsOnHand;#COLOR $123456;#SH %expanddb(@coinsInPouches, %crlf, ": ");#color $654321}

Could add in the --- lines inbetween and colour it as you wish.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Fri Jan 21, 2005 12:15 am   
 
Yes, and you can also use the mxp tags if you like:
#ALIAS displayCount {#MXP ~<color red~>Tally~</color~>;#MXP ~<color blue~>--------------------------------~</color~>;#MXP ~<color green~>;#SH On hand: @coinsOnHand;#SH %expanddb(@coinsInPouches, %crlf, ": ");#MXP ~</color~>;#MXP ~<color blue~>--------------------------------~</color~>}
_________________
Kjata
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net