mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2009
Posts: 10
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Apr 2009
Posts: 10
I'm looking to make a script that would go down all the channels and across all the servers, and if there are less than 3 people in the channel, leave it. I can do it on an individual channel, but for some reason cannot get it to do multiple ones. here is the code I have:

Code:
on 1:text:!run:#: { 
  .scon -a users
}

alias -l users {
  var %users $nick(#,0)
  if (%users < 3) { /part $chan }
  else { HALT }
}


I'm nowhere near an expert on this, but from what I can gather from the help file is that the .scon line will run the alias users on every connection, which should be what I'm looking for. but it's not working, so i was wondering if anyone could give me a nudge in the right direction.

--Brooklyn

Last edited by Brooklyn11218; 06/06/10 03:53 AM.
Joined: Aug 2006
Posts: 183
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
You'd need to use $chan in the users alias...

This code seems to work, but hasn't been tested very well.

Code:
alias -l users {
var %i = 1
while %i <= $chan(0) {
  var %users $nick($chan(%i),0)
  if (%users < 3) { /part $chan(%i) }
inc %i
}
}


That should loop through all the channels, count how many people are there and part if its less than three. I got rid of the halt statement because the while loop needs to continue through to check each channel (and there wasn't a reason it should have been there in the first place as far as I can tell).

Last edited by Thrull; 06/06/10 05:01 AM.

Yar
Joined: Apr 2009
Posts: 10
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Apr 2009
Posts: 10
TY Thrull. That seemed to have fixed it. If you don't mind me asking, i'm a bit confused as to how the $chan worked, could you shed some light for me?

--Brooklyn

Joined: Aug 2006
Posts: 183
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
Ok, first you need to read the help section for $chan in the mirc help file. That should explain it decently. /help $chan (pick the second option in the box that is displayed.)

$chan(0) is the amount of channel you are in.
$chan(1) is the first channel you're in. $chan(2) is he second and so forth.

What I did was to make a while loop that gets the total amount of channels you're in (using $chan(0)) and then loops through each on and checks to see if there are less that three nicks in it.


Yar
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
With the code I saw, the variable that is used to obtain the channel name will be incorrect if the channel is parted.

Here is my recommendation
Code:
alias -l users {
  var %i = 1
  while %i <= $chan(0) {
    var %users = $nick($chan(%i),0)
    if (%users < 3) {
      part $chan(%i)
      dec %i
    }
    inc %i
  }
}


I also recommend using the at1 switches in the scon command.

This will guarantee that you are actually connected to the server before running the alias.

Joined: Aug 2006
Posts: 183
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
@Russel Your code causes me to disconnect. And also causes Mirc to freeze in an infinite loop.

Actually, I tested my code to see if it worked or not. I didn't think it would work for the exact reason you gave, but it does. I believe the script gets done sending all the commands before you actually leave the channels.

If I was writing it over again, I'd probably get a list of channels and then once the while loop is done processing, part all the channels on the list. I think that's the safest way to do it.


Yar
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Sorry about that.. I blame the hour of the day (about 3:30 am)

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Code:
on *:TEXT:!run:*:{
  var %cid = 1
  while ($scon(%x).status) {
    if ($v1 == connected) {
      scon %x
      var %# = 1
      while ($chan(%#)) {
        if ($nick($v1,0) < 3) { part $chan(%#) }
        inc %#
      }
    }
    inc %cid
  }
}



I am SReject
My Stuff
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
a small improvement on all these examples could be looping through $comchan($me,N) instead of $chan(N). the former returns channels that you're actually on whereas the latter deals purely with the windows that are open. you might want to leave a channel window open that you're no longer in, maintain the window buffer for later review perhaps


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
I don't get the text event, this should be purely an alias.

Also, I don't think that will work on all networks, without a scon.

Code:
alias users {
  .scon -at1 u2
}
alias u2 {
  %i = 1
  while %i <= $chan(0) {
    if $nick($chan(%i),0) < 3 %part = %part $+ , $+ $chan(%i)
    inc %i
  }
  part %part
}


This way you just do /users
And it'll work.

I'd recommend changing the first alias`s name.

ziv.

Joined: Feb 2009
Posts: 133
C
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
remember unset %part %i or use /var
and u can use $addtok


WorldDMT
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
Hmm...yes...I sometimes forget about that...add /vars.

The $addtok is also a good idea.

ziv.


Link Copied to Clipboard