mIRC Homepage
Posted By: truguce Help with loop in dialog - 15/04/06 08:48 AM
What im trying to do here is when i click the check button it will scan all nicks in all open chans for a word in a tx file. Im not so sure the best way to do this but the way i have it now i am getting an error "* /while: invalid format (line 38, namecheck.mrc)" and that line is /nickscanfile. Any help would be great. Thanks
Code:
menu channel,menubar,status,@Check {
  &Name Check: { dialog -rm namecheck namecheck }
}

dialog namecheck {
  title "Nick Check"
  size -1 -1 207 131
  option dbu
  combo 1, 5 7 58 103, size edit
  button "Check", 2, 66 20 28 9
  list 3, 99 19 99 89, sort extsel hsbar
  button "Kick/Ban", 4, 66 33 28 9
  button "Kick", 5, 66 45 29 9
  button "Ban", 6, 66 57 29 9
  button "OK", 7, 161 114 37 12, ok
}
on *:dialog:namecheck:*:*: {
  if ($did == 2) {
    if ($devent == sclick) {
      var %i = 1
      while (%i <= $chan(0)) {
        scannick $chan(%i)
        //echo -a $chan(%i)
        inc %i
      }
    }
  }
}
alias scannick {
  var %s = 1
  while (%s <= $nick($1,0)) {
    /nickscanfile $nick($1,%s)
    inc %s
  }
}
alias nickscanfile {
  var %f = 1
  while (%f <= $lines(nickcheck.txt) {
    if ($read(nickcheck.txt, %f) iswn $1) //echo -a $1
    inc %f
  }
}
  
Posted By: schaefer31 Re: Help with loop in dialog - 15/04/06 09:17 AM
Code:
alias nickscanfile {
  var %i = 1, %chan = $chan(0)
  while (%i <= %chan) {
    var %j = 1, %nicks = $nick($chan(%i),0)
    while (%j <= %nicks) {
      if (something* iswm $nick($chan(%i),%j)) {
         ;do stuff
      }
      inc %j
    }
    inc %i
  }
}
Posted By: RusselB Re: Help with loop in dialog - 15/04/06 10:01 AM
You're missing a closed bracket in the while line.
Code:
 while (%f <= $lines(nickcheck.txt) [color:red])  [/color]  { 


Schaefer did more of a re-write on the code, making a few things better (ie: using a variable to store the number of lines in the text file, then referencing that variable rather than having to access the hard drive every time the while condition is checked), but the basic problem you were having is simply the missing bracket (as shown above)
Posted By: jaytea Re: Help with loop in dialog - 15/04/06 02:45 PM
you can also check $fline($chan(%i),something*,1,1) - if it returns something then theres at least one match laugh
Posted By: truguce Re: Help with loop in dialog - 15/04/06 07:35 PM
ok i chaned it to this
Code:
 on *:dialog:namecheck:*:*: {
  if ($did == 2) {
    if ($devent == sclick) { nickscanfile }
  }
}

alias nickscanfile {
  var %i = 1, %chan = $chan(0)
  while (%i <= %chan) {
    var %j = 1, %nicks = $nick($chan(%i),0)
    while (%j <= %nicks) {
      var %k = 1, %file = $lines(nickcheck.txt)
      var %nick = $nick($chan(%i),%j)
[color:red]      var %chan.n = $chan(%i) [/color] 
      while (%k <= %file) {
        var %word = $read(nickcheck.txt, %k)
[color:red]        nickchecktxt %word %nick %chan.n [/color]         
        inc %k
      }
      inc %j
    }
    inc %i
  }
}
[color:red]alias nickchecktxt {
  if ($1 iswm $2) { //echo -a $2 $1 $3 }
}
  [/color] 
 

After some time I got it to work. I had to add the code in red later after it was not working for me.
Thanks for showing me the proper way to shorten the code. I tried it with no success because I was putting all the variables on the first line. As always I appreciate all your help.
Posted By: DaveC Re: Help with loop in dialog - 15/04/06 10:33 PM
Try this code out, you well find its likely alot faster.

Code:
alias nickscanfile {
  ;
  ; * get all nicks into a list *
  var %hidwin1 = $+(@hidwin.,$cid,.,$ticks,.,$mid($rand(1000000,1999999),2)) | window -c %hidwin1 | window -hn %hidwin1

  var %i = $chan(0)
  while (%i) {
    var %chan = $chan(%i)
    var %j = $nick(%chan,0)
    while (%j) {
      aline -n %hidwin1 $nick(%chan,%j)
      dec %j
    }
    dec %i
  }
  ;
  ; * filter a result set using file *
  var %hidwin2 = $+(@hidwin.,$cid,.,$ticks,.,$mid($rand(1000000,1999999),2)) | window -c %hidwin2 | window -hn %hidwin2
  var %tmphsh1 = $+(tmphsh.,$cid,.,$ticks,.,$mid($rand(1000000,1999999),2)) | hfree -w %tmphsh1 | hmake %tmphsh1 1024
  hload -n %tmphsh1 nickcheck.txt
  var %i = $hget(%tmphsh1,0).item
  while (%i) {
    filter -ww %hidwin1 %hidwin2 $hget(%tmphsh1,%i)
    if ($filtered) { 
      filter -wwcx %hidwin1 %hidwin1 $hget(%tmphsh1,%i)
    }
    dec %i
  }
  ;
  ; * sort result set (this can be removed if not needed) *
  filter -wwct 1 32 %hidwin2 %hidwin2 *
  ;
  ; * call alias "action2take" passing each result set nick *
  filter -wk %hidwin2 action2take
  ;
  ; * clean up *
  hfree -w %tmphsh1
  window -c %hidwin2
  window -c %hidwin1
}
;$1 = nick
alias action2take { //echo -a $1 }


Whats it do...
It loads all nicks to a hidden window, removing duplicates as it goes (nick in 2+ channels etc)
loads the textfile into a hashtable for faster access
filters the nicklist using the textfile (from the hashtable) into a second hidden window, removing any nicks from the first window
sorts the second window
calls an alias that displays each nick (make this what ya want obviously)
cleans up
Posted By: truguce Re: Help with loop in dialog - 16/04/06 01:34 AM
Wasn't expecting that. Thanks for rewriting the script. It indeed works alot faster now. Now I need to take some time to understand how it all works together. Thanks again!!
© mIRC Discussion Forums