mIRC Home    About    Download    Register    News    Help

Print Thread
#83234 16/05/04 04:54 PM
Joined: Apr 2003
Posts: 25
S
SS217 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 25
Okay, yesterday I spent a few hours making my bot use hash tables instead of text files. One problem it has to write about 20 lines of data to a hash table asap, but it's not finishing its job it doesn't write all of the data.

Code:
 if ($1 isnum 1-127) {
    hdel -w players *
    write IP $+ $asctime(mm-dd-yyyy) $+ .txt $2 $+ : $+ $gettok($gettok($4,3,9),1,59)
    set %ip $+ $2 $gettok($gettok($4,3,9),1,59)
    write playerinfo.txt $1-
    .timeraddhash $+ $2 -m 1 700 hadd players $2 $gettok($4,1,9) $1 $gettok($gettok($4,3,9),1,59)
  


That's the script excerpt the table is made on start via hmake players 12. Is 12 not big enough? The problem is I never know the amount of data that needs to be writted into the hash table, it can be anywhere from 1-127.
That was an example it has to write players playername side playerID IP address
1 tjoyfull1 746 GDI 235 39 000.31.22
2 thickerme 424 NOD 349 30 001.33.02
3 clpgunner 2929 NOD 581 33 000.29.13
4 marine249 2316 NOD 274 42 000.50.21
5 tlcwilldc 539 NOD 309 33 001.42.57
6 alwish 300 NOD 311 39 000.19.45
7 vegitam 1082 GDI 276 39 001.24.07
8 jlb132 2229 GDI 248 44 000.55.45
9 sleepy725 980 NOD 268 40 001.56.43
10 te3sla987 106 GDI 623 47 000.04.05
11 cjasper3 5 GDI 232 42 000.28.28
12 ozuarka 618 NOD 347 45 000.36.56
13 userjohn1 1566 GDI 432 43 000.15.18
14 death5228 185 GDI 492 35 000.14.21
15 HKrebaz 1504 GDI 405 40 001.12.09
16 coach970 135 GDI 515 45 000.03.57
17 unsun 475 NOD 329 37 000.22.30
18 snipeevo 2366 NOD 295 27 000.23.59

[Edit: it might be good to add it adds about 6 lines and stops after player id 6 or so]

Last edited by SS217; 16/05/04 04:57 PM.
#83235 16/05/04 04:59 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

from the help file (/help Hash Tables):

/hmake -s <name> <N>
Creates a new hash table with N slots.

A hash table can store an unlimited number of items regardless of the N you choose, however the bigger N is, the faster it will work, depending on the number of items stored.

eg. if you expect that you'll be storing 1000 items in the table, a table of N set to 100 is quite sufficient.

Greetz


Gone.
#83236 16/05/04 05:05 PM
Joined: Apr 2003
Posts: 25
S
SS217 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 25
Sorry, but that doesn't help me much a hash table with a speed of 12 should store 20 items quite quickly.

#83237 16/05/04 05:10 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
That was my point...it doesn't really matter much in your case what number you chose to make the hash table.

Give some more information about what you are trying to achieve.

1) Why are you writing to .txt files still?

2) In that list that you gave, I don't see valid IP addresses, just some random numbers.

3) Why are you using a timer to add items to your hash table?

4) What is $1 (I know it's a number but what is it for?)

More information plz, I'm sure it's something very easy to script, but tell us more about what kind of input your script gets, why you are writing to .txt file, and what the purpose is for...

Greetz

Edit: the <N> does not mean the speed of 12, it simply allocates space for the amount of items you are planning to add.


Last edited by FiberOPtics; 16/05/04 05:12 PM.

Gone.
#83238 16/05/04 05:23 PM
Joined: Apr 2003
Posts: 25
S
SS217 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 25
I'm writing to text files because it's easier for me to do a while loop and read all the data out of the text files.

The bot takes out the IP address since it's displayed in a message to a public channel

2) id player score side IP ping bandwidth usage time ingame
so 1 test 133 Nod 127.0.0.1 217 16 000:32:16
The hadd reads from that format, the FDS doesn't log all of it using spaces which is why you see some $gettok's in the hadd
3) It was on a timer because it wasn't writing all the data, I assumed it needed some time in between each write
4) As stated eariler $1 is the ID of the player

#83239 16/05/04 05:42 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

I'm sorry someone else will have to help you on your way. Not that I'm incapable of doing so, but because I simply don't understand where the Hash Tables come in.

Quote:
I'm writing to text files because it's easier for me to do a while loop and read all the data out of the text files.


What do you need hash tables for if you are writing everythign to txt file and retrieving it back from txt file. Also, in that snippet that you showed, the hash table players is emptied because of the hdel -w players * each time that you will run that script. In other words, right before adding 1 item with corresponding data, the hash table will be emptied again. Eh maybe I'm not thinking clearly right now, but I don't see what the purpose is...

I don't see what is stopping you from doing:

if ($1 isnum 1-127) { hadd players $2 $gettok($4,1,9) $1 $gettok($gettok($4,3,9),1,59) }

which adds the data to your hash table.

To retrieve all the data from the hash table using a loop, you could simply do:
Code:
 
var %a = $hget(players,0).item
 [color:red]  [/color] 
while (%a) { echo -a $hget(players,%a).item $hget(players,%a).data | dec %a }

You see where I'm going with this. Btw echo is just an example, if you want to msg this data to a channel you would of course use msg # ... however this will surely get you flooded off the server if the amount of items is large. Best way for that would be either to send it with intervals, or to send it through dcc chat.

But like I said, someone else will probably be of more help.

Greetz


Edit
If you want to remove excessive spaces you can simply use the /tokenize command on your string. E.g. if you do /tokenize 32 this____ is__ a_____ test , then the tokenized string $1- will be: this_is_a_test Note that _ represents a space in this example.


Last edited by FiberOPtics; 16/05/04 05:57 PM.

Gone.
#83240 16/05/04 05:59 PM
Joined: Apr 2003
Posts: 25
S
SS217 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 25
The text file is there for the !playerinfo command, let's just ignore that for now.

I need the hash tables to store the player data so if they ever need to be kicked the script takes their information from the hash table, which is faster than a text file and less of a pain. However the script isn't writing all the data. And I need to remove all the data first because it's for a gameserver, and I don't want to keep data in there that I don't have to. In short I want to know *why* it isn't saving all the data there

Last edited by SS217; 16/05/04 06:01 PM.
#83241 16/05/04 06:09 PM
Joined: Apr 2003
Posts: 25
S
SS217 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 25
Found the reason, hdel -w players * was erasing the data as it was being put in. I just need a fix for clearing old players that are still in the hash table.

#83242 17/05/04 04:49 AM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
Code:
alias p.i {
  var %table = PlayerInfo, %item = $+($1,:,$2), %data = $3-
  if ($isid) { return $hget(%table,%item) }
  if (%data) { hadd -m %table %item %data }
  else { hdel %table %item }
}
alias p.save { if ($hget(PlayerInfo).size) { hsave -bo PlayerInfo filename.dat } }
alias p.load { if (!$hget(PlayerInfo).size) { hmake PlayerInfo 1000 } | hload -b PlayerInfo filename.dat }

Usage: p.i playername itemname data data data
--Will save the data to that players item (like "p.i bob999 ip 12.34.56.78" will store that ip address)

Usage: $p.i(playername,itemname)
--Will return the data for that players item (like "$p.i(bob999,ip)" will return 12.34.56.78 using the above example)

Usage: p.i playername itemname (nothing else)
--Will delete that item from the player

You should have your script call on the p.load when mirc is first opened, and p.save when changes are made to keep the data current (in case of mirc crashing, etc, the data is already up to date).

See if that helps any.


Link Copied to Clipboard