Ilrahil made a request to me to see if I could code a kill counter in CMUD. I came up with a primitive one that's fairly easy to use, and I wanted to share it here for all to use (or study). Since it's been a while since I've used ZMUD, I'm not sure if the following will work, but my guess is that the script won't work on probably the most latest versions of ZMUD, if they work at all.
First, you need a place to store kills. In CMUD, there is a nice data type called a database record. I use this data type quite a bit, because the database record hold a list of key and value pairs. In other words, within one variable, I can store a list of other variables which I refer to by name. For my example, I will use a variable called @KillCount.
@KillCount will store data like this with the number indicating how many kills of that particular race:
- troll = 5
hobbit = 4
human = 2
orc = 4
dwarf = 1
goblin = 3
Code: Select all
#TRIG {You killed * (%w).} {#if (%db(@KillCount, %1) == "") {#ADDKEY KillCount %1 1} {#ADDKEY KillCount %1 (%db(@KillCount, %1) + 1)}}
The %db(@KillCount, %1) part checks the variable @KillCount to see if there is a key with the name %1 and returns the value. If CMUD can't find a variable it returns "", so basically, if you haven't killed something of %1 type, it executes {#ADDKEY KillCount %1 1}, which creates a brand new key and sets it to 1.
If the key exists already, then {#ADDKEY KillCount %1 (%db(@KillCount, %1) + 1)}} happens which basically adds 1 to the existing number it returns and puts it back inside the variable.
That's it. Nice and simple.
Now let's add a few aliases that you can use to clear and show the values in @KillCount.
Code: Select all
#alias resetkills {#var KillCount "";#echo "Kill Count Reset!"}
#alias showkills {#echo @KillCount}
I won't concern myself with formatting at this point as it may confuse things, I'll let you figure out now to make the results pretty if you so desire.
I just wanted to keep this simple so you have something you can try and use right away. Just copy and paste the 3 code lines into your command box and you should be good to go.
The above script is one of the reasons I use CMUD, it's quite amazing how you can do something so powerful with only 3 lines of script.
Feel free to post and questions or comments here.
Happy coding!
Edited to fix typo