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
wasiu
Newbie


Joined: 22 Feb 2002
Posts: 2
Location: Poland

PostPosted: Fri Feb 22, 2002 8:22 am   

how to write kills counter ? a challenge?
 
Hello, I have a problem...

I would like to have some kind of script/trigger witch do something like that:
whenever I kill somebody and a text "you have killed ork" apear
i want that this script/trigger open file kills.txt, checked the word after "you have killed" and write that word to the file.

that's the basic version
and advence is that when it open file kills.txt, then checks for "ork" (or anything what I had just killed) and if it is then it places a number after it so i would know how many orks i killed without counting a word "ork"...

it's something like kills counter, with helps :)

thanks for reply...
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Fri Feb 22, 2002 11:35 am   
 
Probably easier to handle with the database

See help ADDKEY and SHOWDB
quote:

ADDKEY

Syntax: #ADDK database-rec key value
Related: #DELKEY

Adds a key-value pair to a database record. Database records are a list of key properties, each with a value. Key must be unique. Any existing value for the given key is replaced with the new value.
You can also use the syntax: #ADDKEY dbrec {field=key|field=key...} to assign more than one key at a time. To set multiple fields to the same value, you can also use: #ADDKEY dbrec {field1|field2|...} Value

ADDKEY Example

#ADDKEY db Name Zugg

Adds the key "Name" to the record variable @db, with the value of "Zugg"


#ADDKEY db {Name=Zugg|Level=20}
#SHOWDB @db

will display:

Name: Zugg
Level: 20

#ADDKEY db {Name|Level} ""

will clear out the values of the Name and Level keys in the @db variable.


quote:

SHOWDB

Syntax: #SHOWDB database-rec

Displays the key-value pairs of the given database record on the screen.

SHOWDB Example

#ADDKEY db Name Zugg
#ADDKEY db Race Dwarf
#SHOWDB db

Displays the database record on the screen



TonDiening
Beta Upgrading to 6.26
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Feb 23, 2002 1:30 am   
 
I like this challenge, yes a database would be easier. This is kinda fun though.

First you must add some things to the atconnect alias, if you don't know it is in the System class as an inheritted setting.
#FILE 1 "kills.txt"
KillNames=""
#WHILE (%filesize(1)!=%numitems(@KillNames)) {#ADDITEM KillNames %item(%read(1),1)}
#CLOSE 1

Next we have to make a trigger to update the counter.
#TR {you have killed (*)} {#FILE 1 "kills.txt";#IF (%ismember("%1",@KillNames) {KillData="";#WHILE (%filesize(1)!=%numitems(@KillData) {#ADDITEM KillData %replace(%read(1),"|",":")};#ERASE 1;#FILE 1 "kills.txt";#FORALL @KillData {#IF (%item(%replace(%i,":","|"))="%i") {#WRITE 1 {%concat(%item(%replace(%i,":","|"),1),"|",%eval(%number(%item(%replace(%i,":","|"),2))+1))}} {#WRITE 1 {%i}}};#CLOSE 1} {#WRITE 1 {%concat("%1","|1")}}}

I think that would about do it, be slow as molasses though, when the file gets large. Use a database or rearrange the concept just a bit to get all the speed you need. Just a few small hints...update killdata with the new kill number then do the writing, that way killdata would always be up to date, also keep killnames up to date and then you don't have to read it every connect.

Of course you really should use a wonderful database.
Reply with quote
wasiu
Newbie


Joined: 22 Feb 2002
Posts: 2
Location: Poland

PostPosted: Sat Feb 23, 2002 12:36 pm   
 
ok i did what you said, but it don't work anyway, it says that there's some syntax error in the trigger.
I'm not a programist and what my best thing what i did by my self is setting a colors trigger :P
so would you say what to do, like you would say it to the small child ? :)

then i think it would be much simpler for me :)
thx again...
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sat Feb 23, 2002 7:54 pm   
 
If this is a permanent record, then this is a job for the database. (Not a database variable -- that would suck up too much memory.)

Click on DB and create a new database named Killcount. Create two fields: Monster as type Text; Kills as type Number.

Then click on Settings and create a new trigger. In the pattern box put

you have killed (*)

In the Value box put the following:
#DBLOAD ki
#FIND "%1" All Monster 1
#IF %null(%rec) {#NEW All {Monster=%1|Kills=1}} {&Kills=%eval(&Kills+1)}
#DBRESET

This trigger will check the Killcount database for the name of the monster you've just killed and increment its kills if it's found. If it's not found, it creates a new record.

Make sure you've got the right trigger pattern though -- "you have killed ork" doesn't strike me as quite right.

Troubadour
Reply with quote
Kru
Beginner


Joined: 14 Nov 2001
Posts: 28

PostPosted: Sun Feb 24, 2002 8:30 am   
 
Hmm.. I don't want to jump a thread, but what is the difference in memory between a database and several record variables?

My mud has a somewhat intricate skill system, whereby doing actions related to skills is what raises those skills. I have almost 20 dbvariables, each with a record for each skill.. One of the variables is just a pointer to other record variables, heh. All these records are accessed in various ways, err, well quite often. I don't doubt that my performance would be better with a full database, but a full database seemed like extra complexity (I have to set the record pointer, then use that for access? wot?).

Is there some way of measuring how much performance I am losing with all these record variables? could the multitude of data records be why zMud is causing disk writes every 2 seconds?
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