Need help with databases

by Unknown

Back to Mechanic's Corner.

Unknown2004-12-01 07:03:51
What i would really like to be able to do is match a pattern like the following:

You have slain (*)

and add that to some sort of a database

i want it to look something like

Name:--------------Kills:
A rockeater..........1
Bob.....................2
(the periods and dashes are to keep the forums from messing around with the spaces)

I looked into using Data Record Variables to do this, and was able to work it out so that the name of the Mobile was correctly identified and entered.. But then i got stuck when i couldnt figure out how to "add" the number of kills.. if that doesnt make any sense what i mean is that normally:

#var kill_counter
#addkey kill_counter bob 1

would enter bob|1 into the Data Record.. however, say i kill bob again, how do i then ADD 1 to the number already inside the Record?

I would like it if i didnt have to mess around with a real Database because this sounds like something that Data Record Variables were designed to do.. but i just cant seem to find the right commands to work with them.

Any help is much appreciated.
Unknown2004-12-01 10:28:59
After a few hours i was finally able to figure it out.. it looks pretty sweet too.. check it out.

It looks like this:


You have killed:
----------------------------------------
a moose 6 times
a cat 3 times
----------------------------------------

except i cant get the spaces to show up correctly on the forums...

and heres the code:
CODE
#ALIAS kills {#MXP ~You have killed:;#MXP ~----------------------------------------~;#LOOPDB @killcounter {#MXP ~ %key %repeat( " ", 25-%len( %key))%val times ~};#MXP ~----------------------------------------~} "Killcounter"
#VAR killcounter {} {_nodef} "Killcounter"
#VAR stack {} {_nodef} "Killcounter"
#VAR mobname {a cat} {_nodef} "Killcounter"
#TRIGGER {you have slain (*).} {mobname=%1;stack = %db( @killcounter, @mobname);#ADDKEY killcounter @mobname ;stack=""} "Killcounter"


Enjoy!
Unknown2004-12-02 11:06:53
Now to figure out how to convert that so that it will summarize a powerlog... ninja.gif
Daganev2004-12-02 11:36:04
that rhetorical? cause it seems pretty easy and your the one who has been helping me learn this zmud stuff.
Unknown2004-12-02 17:35:39
Anonymous has been helping you learn zmud?
Unknown2004-12-03 21:18:14
Easy the code may be, be difficult to figure out it can orc.gif

Suggestion: If you want to do the same in less lines of code and without use of temporary variables (mobname, stack), try this:

CODE
#TRIGGER {you have slain (*).} {#ADDKEY killcounter {%1} %eval(%db(@killcounter,{%1})+1)} "Killcounter"


The reason why you might want to do it that way is mainly execution speed, the less lines of code zmud needs to parse and the less variables it needs to manipulate the faster it'll execute your code (and especially variable manipulation is quite a factor in terms of speed)
I know that doesn't really matter much for your trigger, just wanted to say it in general.

Also:
If you only had a single word as your variable keys, like if you had a PK-only killcounter where you only record the names of people slain, you can also do
#ADD killcounter.%1 1

-david