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.

Scripting automations on startup and on connect

The introduction of multiple connections within one mIRC client was certainly a revolutionary step in the development of mIRC. Like all big changes, this change brought some new problems. Previously people could have set their mIRC's to automatically connect and to perform certain commands on connect without a single line of script. Introducing multiserver made this a lot more complicated. Even if new dialogs and menus were added to mIRC, the situation still remains a lot more complicated. That's why learning to script your own connection routines would be a long term investment.

People might want to perform many things on startup and on connect. However let's start with a simple scenario. User wants to connect to a three servers and join certain channels for each connection. Scripting this is fast and quick because /server command provides a nice syntax. The syntax is /server [-m] <server> [<port>] [<server password>] [-i <main nick> <alternative nick> <e-mail> <real name>] [-j <channel>,<channel> [<key>,<key>]] It looks horrible and long but that's why it's so powerful. The -m switch opens a new server window while a /server without -m connects the current window to the specified server.

Example script

on *:START: {
  ; Connect to EFnet server as Jack and join #mIRC and #Stars
  server -i Jack Jack2 Jack Smith -j #mIRC,#Stars
  ; Connect to IRCnet server as NullGuy and join #idle and #chat where #idle has key 'yek'
  server -m -i NullGuy NullDude Jack "NullGuy" Smith -j #idle,#chat yek
  ; Connect to a private server port 9438 with password abcd as Jack and join #secret
  server -m irc.private.domain 9438 abcd -i Jack Jack2 Jack Smith -j #secret

Put that into your remotes. You can find it in Alt+R or Tools/Remote. If you don't want to do this every single time you start mIRC, you can do an alias. Just replace the 'on *:START:' with alias name and put it in your aliases.

The previous piece of script is nice but it's probably not enough for many. You might want to identify yourself to a nickname service, you might want to open a DCC chat to your bot, you might want to set certain usermodes, and the list can continue forever. What we need is something equal to the perform section on mIRC options. That's where we start using on CONNECT. on CONNECT is triggered right after mIRC has received the end for the message of the day.

You have a few ways to identify where you have connected. The most reliable is $server which has the hostname of the server, the one you specify with /server. You can also check $server against a wildcard mask, such as * or * The other option is $network. The problem with $network is that it's not always defined. mIRC tries to get the name of the network from connection numerics 001, 005, and the internal server list. Just to be safe, if you decide to use $network, always add the servers into the internal list of servers. Naturally if you are sure that your networks send the proper connection numerics, then you don't have to do this. The real situation just happens to be rather chaotic at the moment. Many big networks don't send this information at all.

Example script

on *:CONNECT: {
  ; When you connect to, set usermode +iw, and join to #foo and #bar
  if ( $server == ) {
    mode $me +iw
    join #foo
    join #bar

  ; When you connect to *, set usermode +i, join #mIRC, and open DCC chat to a bot
  if ( * iswm $server ) {
    mode $me +i
    join #mIRC
    dcc chat mybot

  ; When you connect to DALnet, identify to NickServ, set usermode +R, and put Bob to your silence list
  if ( $network == DALnet ) {
    nickserv identify mypassword
    mode $me +R
    silence +Bob

Naturally the on CONNECT event itself won't connect anywhere. You can apply a small on START event or alias to initiate the connections.

Warning! The protocol gives no guarantee that the server's hostname or network really is what the server is claims them to be. In the other words client trusts that the server doesn't lie. This is why you should never send anything really confidential automatically only according to $server and $network. I have never heard that someone would have actually exploited this but make sure that you're not the first victim.

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