Note: The mainteinance of the scripting examples is discontinued since I no longer have an interest to continue doing so. The pages will remain here, for now, but that might not be the case in the future. You are free to download all the material on these pages and set a up mirror, or even continue the maintenance of the material by enhancing the examples yourself.

All the material in these examples are for the mIRC version 6.03. It is very likely that some or most of these examples won't work in future versions.

My on JOIN events don't work. Why?

Beginning scripters often makes mistakes with on JOIN event. The issue that confuses them is that joining a channel isn't just one event. In reality it is composed of many events. Let's take a look what the server actually sends when you join a channel. The output is not directly from any existing IRC server software. The replies that are marked as optional have been added after RFC1459 was made. They are not found on all servers. Some implement the optional replies and some don't. The best way to find out is to just to try it out in your home network.

Sample output

; The server reply that triggers on JOIN
:Geetee! JOIN :#Chat

; Topic 332 Geetee #Chat :Happy birthday Fred!

; Topic information (non-RFC1459) 333 Geetee #Chat Foo! 1004635543

; Names and channelmodes for users
; Note that there are multiple 353's in case all nicks don't fit in one reply 353 Geetee = #Chat :Geetee @Fred @Foo @Bar

; End of names 366 Geetee #Chat :End of NAMES list.

; Modes for the channel 324 Geetee #Chat +tn

; The moment the channel was created (non-RFC1459) 329 Geetee #Chat 1008511228

The replies 324 and optional 329 are not sent automatically. After every join, mIRC does 'MODE #channel'. This, however, is done automatically and you can't stop it from being sent. That's why you can trust that when doing mIRC scripting, the numerics 324 and optional 329 are sent with every join. The only exception are the modeless +channels that cannot have any modes.

What this means is that you don't know your channelmode in on JOIN event. mIRC doesn't know anything that hasn't been sent and processed yet. In the other words you don't know topic, user count and nicks or the channelmode in on JOIN event.

There are many things you can do with the numeric replies. You can change the default output and also send commands based on the information you get from the replies.

If you're running a small channel, you often want to check if you have joined to an empty channel. You know that you have joined an empty channel when you are the only user and you are operator restricted connections being an exception to the latter. When you want to check this, you need to use the raw event 353 instead of on JOIN event. If you want to set or unset default modes for the channel when you get op, you should do this in two events: raw 353 (you get op when you join) and on OP (someone else ops you). The on OP event doesn't trigger if you get op when you join a channel. Note that although 353 can be used, most of the time it's more convinient to use 366 with mIRC's built-in variables. The numeric 366 will be sent right after 353 so there is no significant delay or other negative effects.

Example script

raw 366:& #chat *: if ( ($me isop $2) && ($nick($2,0) == 1) ) mode $2 +nst
on *:OP:#chat: if ( $opnick == $me ) mode $chan +nst

This example sets channelmode +nst whenever you get operator status on #chat.

Another common script feature is to display statistics of channel's users. If you want to do this, it's best to display the statistics when you get numeric 366. By then the client has received information of all users and their channelmodes (operator, half-op, voice). Note that you can use /names and get 353 and 366 from outside the channel. In this case, you probably don't want to echo any statistics since the statistics would be incomplete. If you want to see the statistics on other situations apart from join, you can just do /names #channel which uses the same numerics.

Example script

raw 366:*: {
  if ( $me ison $2 ) {
    var %string
    if ( $nick($2,0,o) > 0 ) %string = $nick($2,0,o) op(s),
    if ( $nick($2,0,h,o) > 0 ) %string = %string $nick($2,0,h,o) half-op(s),
    if ( $nick($2,0,v,oh) > 0 ) %string = %string $nick($2,0,v,oh) voiced,
    %string = %string $nick($2,0,r) normal
    echo $color(mode text) -t $2 *** There are $nick($2,0) users ( $+ %string $+ )  on $2

Last updated 2003-04-05, Janne 'Geetee' Nikula,