mIRC Homepage
Posted By: Simo how to check each nick in $1- is in channel - 14/03/24 01:58 PM
greetingz , im strugling to find each nick in $1- and see if they are all actually in channel before proceeding adding them to be voiced with $modespl
here is what i work with so far (got it from here from a post and edited it somewhat)

Code


kjjsdklsddk {
  var %chan = #  , %a = 1,  %nicks = $1-,%b = $numtok(%nicks,32) 
  while (%a = %b) {
    if ($gettok(%nicks,%a,32) ison %chan) { set %nicks $addtok(%nicks,$gettok(%nicks,%a,32),32) }
    if $numtok(%nicks,32) == $modespl {
      .mode %chan + $+ $str(v,$numtok(%nicks,32)) %nicks
      unset %mode.nicks
    }
    inc %a
  }
  if %nicks {
    .mode %chan + $+ $str(v,$numtok(%nicks,32)) %nicks
    unset %nicks
  }
}



thanks in advance.
Don't use '=' for comparison, always use '=='. (In this case you don't need to, because you're doing a loop)

I think the problem is the loop on the third line, while (%a = %b) {
Change it to while (%a <= %b) { and that I think would solve the problem.
Posted By: Simo Re: how to check each nick in $1- is in channel - 15/03/24 08:09 PM
thanks for your reply Masoud i tried your suggestion

but only this gets executed :


Quote
if $numtok(%nicks,32) == $modespl {



if any remaining nicks in %nicks dont get voiced

the remaining in :


Quote
if (%nicks) {

dont trigger
Posted By: Simo Re: how to check each nick in $1- is in channel - 23/03/24 02:21 PM
someone on IRC provided this alias with 2 while loops would it be possible to use 1 loop ?

Code



alias mvoice {
  var %xTemp $1-  , %nicks = %xTemp,   %newnicks,  %x = 0,  %numnicks = $numtok(%xTemp,32),   %inc = $modespl,  %max = %numnicks,  %nickstring  
  while (%x < $numtok(%xTemp,32)) {
    inc %x
    var %nick = $gettok(%xTemp,%x,32)
    if (%nick ison #) {
      if (%x != 1) %nickstring = %nickstring $+ $
      %nickstring = %nickstring $+ %nick
    }
  }
  %nickstring = $replace(%nickstring,$,$chr(32))
  %x = 1
  while (%x < %max) {
    %end = $calc(%x + %inc)
    if (%end > %max) %end = %max
    %currentnicks = $gettok(%nickstring, %x - %end, 32)
    %vs = + $+ $str(v,$numtok(%currentnicks,32))
    mode # %vs %currentnicks
    inc %x %inc
    inc %x
  }
}

Posted By: Wims Re: how to check each nick in $1- is in channel - 23/03/24 06:19 PM
1) Why do you care if it uses 1 or 2 while loops?
2) The code will not prevent any voice to occur if a single nickname is not on the channel, which is how you asked about it originallly
3) Even if the logic you want is to simply filter nickname not being on the channel first and only then do mass voices this code is not correct.
4) It's not correct but in a way that makes it works 100% of the time still, you got lucky, %max should be set to $numtok(%nickstring,32) after reseting %x to 1

It's possible to filter the nickname using $* which will do the while loop for you.
Posted By: Simo Re: how to check each nick in $1- is in channel - 23/03/24 07:36 PM
perhaps i wasnt clear in the initial request, the idea is to voice a list of users provided in $1- or similar (not entire channel no massvoice of entire channel)

like /mvoice nick nick nick nick nick nick nick nick

and if any of the nicks isnt in the channel to send an echo (with all the nicks that arent in the channel) and send the rest of the nicks to be voiced with $modespl

thanks.
Posted By: Wims Re: how to check each nick in $1- is in channel - 23/03/24 09:07 PM
The code you have does that already though.
Posted By: Simo Re: how to check each nick in $1- is in channel - 25/04/24 10:24 PM
Found a way to use 1 loop and it seems to work as expected makes the code smaller too 👍
© mIRC Discussion Forums