Hash tables are very much like INI files, but because they are fully loaded into memory (unless/until you save them and free them), they work faster than having to read through a file.
The first thing you have to decide is how you want to store the data. In a hash table, you have an item name and a data value. Personally, I would use the address as the item name for what you are doing. Just make sure you use standard address masks for the addresses so you can easily find the data. For example, using an address of *!ident@* isn't a standard mask and would make searching for it more difficult (it can be done easily enough, but it requires extra coding for it to work). Also, such a mask is REALLY bad for choosing to op someone. Anyone can change their ident to anything else and suddenly be opped. To see a list of the masks, type /help $mask and scroll down one page.
Here is a short example:
[color:green]; Create your table and load the saved copy and set up automatic saving of the table.[/color]
on *:connect: {
if ($hget(UserData) == $null) {
hmake UserData 30
hload UserData UserData.hash
}
if ($timer(UserData) == $null) {
.timerUserData 0 30 hsave UserData UserData.hash
}
}
Now, when you're adding data, I would consider doing it something like this (in a script, or on command line):
//hadd UserData $address(nick1,2) OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
//hadd UserData $address(nick2,2) VOICE ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
//hadd UserData $address(nick3,2) REGULAR ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
Ok, so we just set 3 nicks that were in the channel up in the table. One for op, one for voice, and one for regular. We did them using the mask of *!*@host.com (mask 2).
Now, when someone joins...
on @:join:#yourchannel: {
[color:green]; Get the data for the address using mask 2. If that fails, you can try other masks as shown... you only need to use the ones that you used when adding the data.[/color]
var %data = $hget(UserData,$address($nick,2))
if (%data == $null) {
var %data = $hget(UserData,$address($nick,4))
}
[color:green]; After checking for all masks that you want to check for, see if there is any data. If not, then you don't have data on that nick and can halt the script. Otherwise, check the first token of the data to find out what status the nick has.[/color]
if (%data != $null) {
if ($gettok(%data,1,32) == OP) { mode $chan +o $nick }
elseif ($gettok(%data,1,32) == VOICE) { mode $chan +v $nick }
}
}
Just as a note... If you don't like using just the masks, you can also set the address manually:
Example:
//hadd UserData nick!ident@* OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
Then, since you know that's one way you're using, you can use:
if (%data == $null) {
var %data = $hget(UserData,$gettok($address($nick,5),1,64) $+ @*)
}
That would take everything before the @ in the address and then put @* at the end...
So, nick!ident@host.com would become nick!ident@* ... that would give you the ability to use any mask you like, even if it's not standard. But, you really need to be careful of using masks that do not include a host name.
One last note... if you want to include both DNS and IP, you'll probably need to manually add at least one of those:
//hadd UserData nick!ident@123.456.789.012 OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
Whether it's IP or DNS, you still use the same masks...
var %data = $hget(UserData,$address($nick,2)) will still work regardless if you used IP or DNS as long as they are both in there.
Anyhow, that may get confusing... If you have questions, just ask.