mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Hi all,

I have this hashtable called 'chans'

The hashtable contains channelnames and ops
example:
item = channel1 data = nick1 nick2 nick3 nick4
item = channel2 data = nick1 nick2

Now i wanna find the info that a channel holds when someone types a command in the channel. I tried with the following:
Code:
on *:text:!tellme *:#: {
    var %i = 1
    var %chan = $2
    while ($hfind(chans, * $+ %chan $+ *, %i, w).item) {
      msg $chan => item= $hget(chans,%i).item data= $hget(chans,%i).data
      inc %i
    }
}


But it doesn't work... Whats wrong? And how do I get the proper info?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If that's all it has (and the channel name is the item name), you can just do:

Code:
on *:text:!tellme *:#: {
  if ($hget(chans,$2) != $null) {
    msg $chan item= $+ $2 data= $+ $hget(chans,$2)
  }
  else msg $chan No data on $2 $+ .
}


No need to even use $hfind since you can pull the item name directly because you are typing the full channel name.

Again, this assumes you have it set like you said... item=#channel, data=nicks. To have added it this way, you'd have used something like /hadd chans $chan nick

If, on the other hand, your channel ISN'T the item and you used a number for your items and the channel is just the first part of the data, we'd need to do something else. If that's the case, just let us know.

Last edited by Riamus2; 29/09/05 02:14 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Yes i've used the format '/hadd chans $chan nick nick2 nick3 etc...'

It works too smile awesome!

And how would i approche this if i would type a part of the channel name? and not the full part?
Example: channel #mIRC
type: !tellme IRC
And still have it reply the info for #mIRC.

Tnx in advance!

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
For that, you would need $hfind...

Code:
on *:text:!tellme *:#: {
  if ($hfind(chans,* $+ $2 $+ *,0,w) > 0) {
    var %c = 1
    var %i = $hfind(chans,* $+ $2 $+ *,0,w)
    while (%c <= %i) {
      msg $chan item= $+ $hfind(chans,* $+ $2 $+ *,%c,w) data= $+ $hget(chans,$hfind(chans,* $+ $2 $+ *,%c,w))
      inc %c
    }
  }
  else msg $chan No data on $2 $+ .
}


See if that will work for you.

As you can see, that's almost the same as what you had previously. The main difference is in the msg line.


*EDIT* Fixed error.

Last edited by Riamus2; 29/09/05 02:15 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
* Invalid parameters: $hget

for this line:
Code:
if ($hget(chans,* $+ $2 $+ *,0,w) > 0) {


Of course this must be $hfind smile

Last edited by Div; 29/09/05 01:41 PM.
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
No, that didn't do the trick... still complaining about other $hget

should all be changed to $hfind?


Ok all, exept the last one ;-)
$hget(chans,$hfind(chans,* $+ $2 $+ *,%c,w))

Last edited by Div; 29/09/05 01:52 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry... typos after doing the previous script. I fixed it in the previous post for you.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Yup smile that's how I had it too! Tnx!

Another thing I was wondering...

Is there any way to show the full channelname too when someone searched for 'mI'?
Example, user searches for 'mI' and the reply isn't just $2 but 'mIRC'? And perhaps also 'iminthemood'?

Tnx smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
It should...

In table:
#mirc nick1 nick2
#minion nick3 nick4
#ominous nick5

!tellme mi
item=#mirc data=nick1 nick2
item=#minion data=nick3 nick4
item=#ominous data=nick5


Just as a note, there isn't any form of flood protection in this... if you do a search that results in a lot of matches, you're going to be flooded off... here's a fix for that:

Code:
on *:text:!tellme *:#: {
  if ($hfind(chans,* $+ $2 $+ *,0,w) > 0) {
    var %c = 1
    var %i = $hfind(chans,* $+ $2 $+ *,0,w)
    while (%c <= %i) {
      write temp.txt item= $+ $hfind(chans,* $+ $2 $+ *,%c,w) data= $+ $hget(chans,$hfind(chans,* $+ $2 $+ *,%c,w))
      inc %c
    }
    play temp.txt $chan 1500
    .remove temp.txt
  }
  else msg $chan No data on $2 $+ .
}


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Tnx smile

When there are more results to display, I've noticed it does not show the results in the same order they were added, is there a way i can give ppl the results in the order i added them? Like from the last added channel on?

Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Afaik, hash tables are ordered (reordered?) alphanumerically, not in the order that you added them. This is likely to increase the speed of accessing and searching them. The only solution is to assign each item and ID and include the channel name in the data fex 0001=#chan nick nick2 nick3 instead of #chan=nick nick2 nick3. But that would requires different search code and would slow it down.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You could probably do something with filder and perhaps adding $ctime into the data so that you can filter it by that. You could then output it without $ctime using $gettok. That would be very easy if play would allow you to play a file using $gettok params. Without it, I'm not sure how to do it very easily and still use play. Maybe it can only really be done using a timer and an alias to "play" it slow enough to avoid possible flooding.

Maybe one of the others here has a better idea.


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Hash tables aren't ordered, but the location an item is stored depends on the hash of the key. The hash function is a function that makes a semi-random number from a key value. If all keys are mapped to a different number then the hash table performance is optimal. If all keys are mapped to the same number, then you've basically got an unordered array and performance is just bad...

But back to the topic:
To put in order just make entries like
1 = #channelfirst
2 = #channeltwo
3 = #mIRC

so you have both order and still a fast lookup if you aleady know the full channel name...

Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Your right, it was late, i have infact run into ordering problems myself in the past so should have known better.

For original poster, using numbers wont order your items either, but it will allow you to use hget in a while loop where %x is used as the hash table item you want to retrieve


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby

Link Copied to Clipboard