mIRC Homepage
Posted By: UNOwen Auto /part when channel is empty - 23/07/07 01:23 AM
I'm trying to write a script that'll part me from a channel when I'm the only user left in that channel.

I've got this far, but it's not working. Could someone please explain what else is needed.

Code:
on !*:part:#:{
  if ($nick(#,0) <= 1) {
      part $chan
  }
}
on !*:quit:#:{
  if ($nick(#,0) <= 1) {
      part $chan
  }
}


Thank you for your assistance!! smile
Posted By: RusselB Re: Auto /part when channel is empty - 23/07/07 01:50 AM
The on quit event doesn't have a location for a channel parameter, so you need to loop through your channels

Code:
on !*:quit:{
  var %a = 1, %b = $chan(0)
  while %a <= %b {
    if $nick($chan(%a),0) = 1 {
      part $chan(%a)
    }
    inc %a
  }
}

Posted By: SladeKraven Re: Auto /part when channel is empty - 23/07/07 02:11 AM
Code:
On me:*:Join:#: {
  $+(.timerchkusers,.,$cid,.,$chan) 0 10 chkusers $chan
}

On me:*:Part:#: {
  if ($timer($+(chkusers,.,$cid,.,$chan))) $+(.timerchkusers,.,$cid,.,$chan) off
}

alias chkusers {
  if ($nick($1,0) == 1) {
    $+(.timerchkusers,.,$cid,.,$1) off
    part $1
  }
}


I'm not sure if there's a better way of doing this, and I've never really used $cid before.

When you join a channel a timer is started and checks every 10 seconds to see how many users are on the channel. If there's only 1 user (you) it parts the channel.
Posted By: RusselB Re: Auto /part when channel is empty - 23/07/07 06:26 AM
No offense to your code, Slade, however, in my opinion, running a timer every 10 seconds would be a waste of resources.

Checking the number of users upon joining, is a good idea, but once that's done, then one only needs to check after people part, quit or are kicked.

In regards to the usage of $cid, for a code like this, it's not necessary, as the checking doesn't have to be done over multiple networks.
Here's my current recommendation for a full code
Code:
on me:*:join:#:{
  chkusers $chan
}
on !*:part:#:{
  chkusers $chan
}
on !*:quit:{
  chkusers $chan
}
on *:kick:#:{
  if $knick != $me {
    chkusers $chan
  }
}
alias chkusers {
  if $nick($1,0) == 1 {
    part $1
  }
}
Posted By: SladeKraven Re: Auto /part when channel is empty - 23/07/07 11:18 AM
Using your code I joined a room with 20 users in it, it parted me straight away.
Posted By: LostShadow Re: Auto /part when channel is empty - 23/07/07 11:52 AM
There's no point in checking if ($nick(#,0)) <= 1 because it could never go below 1 for as long as you're in the channel..

Here's some basic ones.

on *:QUIT:{ if ($nick != $me) { var %x = 1 | while ($comchan($nick,%x)) { var %v1 = $v1 | if ($nick($v1,0) == 1) { hop -c %v1 } | inc %x } }
on *:PART:#:{ if ($nick != $me) && ($nick($chan,0) == 1) { hop -c $chan } }

However, I extended some, and I don't think the next on quit works.

1.No point cycling a channel that's +i.
2.No point in cycling a channel when you're op.
3.If the channel is +r, ChanServ will -oh you you so you still get the +v, so no point in hopping it if you are +v.

Code:
on !*:part:#: { 
  if ($nick($chan,0) > 2) { /halt }
  else {
    if ($me isreg $chan) { 
      if (i !isin $chan($active).mode) {
        /hop $chan | /mode $chan +vh $me $me | echo $chan on part event
      } 
    }
  } 
}
on !*:quit: { 
  var %i = 1 
  while ($comchan($nick,%i)) { 
    if ($nick($comchan($nick,%i),0) > 2) { /halt }
    else {
      if (r !isincs $chan($chan).mode) && (i !isin $chan($chan).mode) {
        if ($me isreg $comchan($nick,%i)) {
          /hop -c $comchan($nick,1) | /mode $comchan($nick,%i) +vh $me $me 
        }
      } 
      if (r isincs $chan($chan).mode) {
        if ($me isreg $comchan($nick,%i)) {
          /hop -c $comchan($nick,%i)) | /mode $comchan($nick,%i) +vh $me $me
        }
      }
      inc %i 
    } 
    unset %i 
  } 
}


Posted By: SladeKraven Re: Auto /part when channel is empty - 23/07/07 01:45 PM
Not all IRCds support the +h mode.

So maybe something like:

Code:
/mode $comchan($nick,%i) $+(+v,$iif(% isin $prefix,h $me)) $me


Without testing your code, I don't know how well it works but looking at this line:

Code:
if (r isincs $chan($chan).mode) {


$chan wouldn't have a value in the On Quit event.
Posted By: LostShadow Re: Auto /part when channel is empty - 23/07/07 07:56 PM
Ah yes, I shall fix that. Thanks.
Posted By: UNOwen Re: Auto /part when channel is empty - 24/07/07 09:27 PM
I appreciate all your help.

Russel this one works in most instances:
Code:
on !*:quit:{
  var %a = 1, %b = $chan(0)
  while %a <= %b {
    if $nick($chan(%a),0) = 1 {
      part $chan(%a)
    }
    inc %a
  }
}


I've tried all the others except the last one by LostShadow and did't have much luck with them. Before I try yours LostShadow, I'm confused why you're using /hop instead of /part? Is that for debugging purposes? Could you please explain.
Posted By: RusselB Re: Auto /part when channel is empty - 24/07/07 10:26 PM
That would work fine when someone quits, but if they part the channel, leaving the OP alone on the channel, then the OP also wanted to depart the channel, which that code does not incorporate
© mIRC Discussion Forums