mIRC Home    About    Download    Register    News    Help

Print Thread
#146243 02/04/06 02:06 AM
Joined: Mar 2005
Posts: 74
K
KidSol Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2005
Posts: 74
how to i make a hash table so it'll go like this in a notepad when it made

Nick ## RealName Phonenumber
testing 5165 Test 123456

and if i want to update, i just say !update nick ## RealName Phonenumber


Is it possible to copy and paste into the hashtable notepad if i don't wont to use the mirc to update?

#146244 02/04/06 04:20 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
One of us must be confused about what you want. Do you want the data to be stored in a hash table (in RAM) or do you want it in a text file? A hash table can be saved to an ini file (with sections and items).

-genius_at_work

#146245 02/04/06 04:28 AM
Joined: Mar 2005
Posts: 74
K
KidSol Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2005
Posts: 74
data store in hashtable
i wish it could be arrage in order.
I saw one of my friend data is just 1 whole line long even it have 100 data

i wish it could make like

Nick Data RealName Phonenumber
1) Testing ### Test ######
2) '' '' '' ''

and when i update i'll just say !update Testing(Nick) ###(Data) ####(PhoneNumber)

#146246 02/04/06 06:15 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
A hash table is inherently unsorted. Rather than using a hash table, you could store the data in an ini file. Ini files store the data in this sort of format:
Code:
[section1]
item1=data1
item2=data2
item3=data3

You could store your "address book" information in an ini file in several ways. Here is one example:
Code:
[My_Nick]
Name=Joe Smith
Phone=1234567890
Address=123 cityname


or like this:
Code:
[AddressBook]
My_Nick=Joe Smith,1234567890,123 cityname


I would suggest the first example. It has individual sections for each nick, and within each section there is a separate item for each bit of address/phone/name data.

Technically the data *could* be stored in a plain txt file, but that would require more coding and would be ultimately more difficult to edit in notepad.

Decide which way you would like, and we can move on from there.

-genius_at_work

#146247 02/04/06 07:58 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias -l hash.table {
  var %hash.table = HASHTABLENAME
  if (!$hget(%hash.table)) {
    hmake %hash.table
    if ($isfile(%hash.table)) {
      hload -n %hash.table %hash.table
    }
  }
  return %hash.table
}
;
on *:TEXT:!update & & & *:{
  if ($hfind($hash.table,$+($1,$chr(9),*),1,w).data) { var %item = $v1 }
  else { var %item = $+($ctime,$ticks,$rand(1000000,1999999)) }
  hadd $hash.table %item $+($2,$chr(9),$3,$chr(9),$4,$chr(9),$5)
  hsave -no $hash.table $hash.table
}

* code untested, if it dont work check back with me *

usage by clients to bot, !update nick data realname phonenumber
Nick well be updated, or added.
file well be updated to match table.

*** note the window NOTEPAD does not always open the file correctly, it cant detect LineFeeds as new lines, try opening the file in wordpad.

#146248 03/04/06 02:33 PM
Joined: Mar 2005
Posts: 74
K
KidSol Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2005
Posts: 74
Code:
on *:text:@info &:*: { 
   msg $chan $nick : $+ hget(HASHTABLENAME, $2)
}




So i just need to add that code to get the info when i say @info ###(nick)

the bot will tell me the data right?

#146249 03/04/06 08:08 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I just noticed a mistake in my original code (i used $1 in the $hfind instead of $2)

and no your code wont work here is what should do the job.

Code:
alias -l hash.table {
  var %hash.table = HASHTABLENAME
  if (!$hget(%hash.table)) {
    hmake %hash.table
    if ($isfile(%hash.table)) {
      hload -n %hash.table %hash.table
    }
  }
  return %hash.table
}
;
on *:TEXT:!update & & & *:{
  if ($hfind($hash.table,$+($2,$chr(9),*),1,w).data) { var %item = $v1 }
  else { var %item = $+($ctime,$ticks,$rand(1000000,1999999)) }
  hadd $hash.table %item $+($2,$chr(9),$3,$chr(9),$4,$chr(9),$5)
  hsave -no $hash.table $hash.table
}
on *:text:@info &:*: {
  if ($hfind($hash.table,$+($2,$chr(9),*),1,w).data) { var %item = $v1 | msg $chan $nick : $+ $hget($hash.table,%item) }
  else { msg $chan $nick : $2 Not present }
}

* code untested *

Note when using this never refrence HASHTABLENAME directly always use $hash.table, as this creates if needed the table and also loads it from the save file if needed.

#146250 04/04/06 04:38 AM
Joined: Mar 2005
Posts: 74
K
KidSol Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2005
Posts: 74
I just test it.
it wont work.
i check under my program file, it doesn't create any hashtable script.

Or did i do anything wrong?

#146251 04/04/06 06:58 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
The hashtable script should appear in the remotes section of MIRC not under program files!!!!
The HASHTABLENAME is of course ment to be changed to what ever you want to call it, If u want to call it say BOBOtheMONKEY.TXT call it that, thats a filename, but can double as the hashtable name just fine.

There was a fault in it that was stoping it from working, something small and hard to see, which is a bit tipicale for scripts i write in here, I forgot to put a *: on the !update event so it works for where ever (you might eventually want to reduce that to a smaller lot but thats up to u)
I also added a filter to sort the save file, so its a nice order.

Code:
alias -l hash.table {
  var %hash.table = HASHTABLENAME
  if (!$hget(%hash.table)) {
    hmake %hash.table
    if ($isfile(%hash.table)) {
      hload -n %hash.table %hash.table
    }
  }
  return %hash.table
}
on *:TEXT:!update & & & *:#:{
  if ($hfind($hash.table,$+($2,$chr(9),*),1,w).data) { var %item = $v1 }
  else { var %item = $+($ctime,$ticks,$rand(1000000,1999999)) }
  hadd $hash.table %item $+($2,$chr(9),$3,$chr(9),$4,$chr(9),$5)
  hsave -no $hash.table $hash.table
  filter -ffct 1 9 $hash.table $hash.table
}
on *:text:@info &:*:{
  if ($hfind($hash.table,$+($2,$chr(9),*),1,w).data) { var %item = $v1 | msg $chan $nick : $+ $hget($hash.table,%item) }
  else { msg $chan $nick : $2 Not present }
}

* code has been tested and works, remember on text events only trigger from remote clients NOT from the BOT itself. *

* remeber also that NOTEPAD doesnt show saved hashtables corerectly (no newlines) using WORDPAD should display it correctly

[i]--edit--

Something i just thought of, the "Nick TAB Data TAB RealName TAB Phonenumber" info from !update is saved as the hashtable DATA, not the hashtable ITEMname which is randomely generated (just a big number thats pretty unlikly to ever exist already in the table, its like 26 digits long).
If your mirc is restarted then all existing hashtable entries get reloaded from the savefile, these get issued numbers from 1 onwards as there ITEMname, but since the ITEMname isnt important just the data thats fine.

Last edited by DaveC; 04/04/06 07:05 AM.

Link Copied to Clipboard