mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2005
Posts: 5
R
rOglrah Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Mar 2005
Posts: 5
How can I get the number of users in a channel? Is there any identifier that can give me that value?
thank you.

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
$nick($chan,0)

Joined: Mar 2005
Posts: 5
R
rOglrah Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Mar 2005
Posts: 5
Thanks smile

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You could also use this to calculate the number of users on all channels you're on.

/users #mIRC returns all users on #mIRC providing you are in there.
/users on it's own calculates the number of users on all the channels you're on.

//say $users(#mIRC) - returns all users on #mIRC providing you are in there.
//say $users calculates the number of users on all the channels you're on.

Not necessary but you migh need it. smile
Code:
alias users {
  if ($1) && ($me ison $1) {
    echo -a Working out: $nick($1,0) users on $1.
    return $nick($1,0)
  }
  elseif (!$1) {
    var %x = $chan(0), %count
    while (%x) { 
      var %count = $addtok(%count,$nick($chan(%x),0),32)
      dec %x
    }
    echo -a Working out: $replace(%count,$chr(32),$chr(32) $+ + $+ $chr(32)) = $calc($replace(%count,$chr(32),$chr(32) $+ + $+ $chr(32))) 
    return $calc($replace(%count,$chr(32),$chr(32) $+ + $+ $chr(32)))
  }
}

Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Here's an alternative:

Code:
alias users {
  var %users
  tokenize 32 $iif($1,$1,$dde(mirc,channels))
  scon -r inc % $+ users $!nick( $* ,0)
  return %users
}


//echo -a $users
-> 170

//echo -a $users(#mIRC)
-> 29

//echo -a $users(#mIRC #scripting)
-> 73


New username: hixxy
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
If you issue //echo -a $users from a channel window, the channel name will be prefixed with a * in the $dde reply, thus not returning any amount of nicks for that channel.

Might also be a good idea to use $ddename, since the name of the ddeserver can be changed, although it defaults to mIRC at each startup.

Finally, using $dde is ok, but if another mIRC is running, the results are corrupted, since $dde will return the channels from the client which was last opened.


Gone.
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Code:
alias users {
  var %users
  tokenize 32 $iif($1,$1,$remove($dde($ddename,channels),*))
  scon -r inc % $+ users $!nick( $* ,0)
  return %users
}


New username: hixxy
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I forgot to mention the most important one of all in my last post, being that this snippet does not work in a multi-server environment. It only gives the nicks from the server window where you issued, and even this result is incorrect.

Let's say you have 2 server windows open, 2 different networks.

Network 1: dalnet
Channels:
#a = 2
#b = 2
#c = 2

Network 2: undernet
Channels:
#d = 5

Issuing $users on server 1, will result in %users being: 7 instead of 11, because $dde returns all channels, including #d, but you're not on #d in network 1, so the code does an inc with $nick(#d,0) being $null, which increments with 1 (default if no amount is specified)

Issuing $users on server 2, will result in %users being 8 instead of 11, for the same reason.

One other thing, channel names can contain a * in their name, so using a global $remove on a channel name would also remove those and corrupt the results.

I'd perhaps go for something like:

Code:
alias users {
  var %users
  scon -at var $(%a = 1 |,) while $!chan(%a) $({ inc %users $nick($v1,0) |,) inc $(%a },) 
  return %users
}

Greets


Gone.

Link Copied to Clipboard