 |
darmir Sorcerer

Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: 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) |
|
|
 |
Kjata GURU

Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: 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 |
|
|
 |
darmir Sorcerer

Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: 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) |
|
|
 |
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: 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. |
|
|
 |
Kjata GURU

Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: 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 |
|
|
 |
|
|