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 a good away system

Although nowadays many people don't use /away or even don't know what it is, the /away command still is an integral part of IRC standard. When protocol supports a way to tell if you are away or not, why not use it? Setting correct away also has advantages in scripting. For example I have made my client to make noise when someone sends me private messages when the client is inactive. However I don't want this to happen when I am away. These are reasons why a good away system is a very good thing to have. You can set away with /away <message> and back with /away with no parameters.

Unfortunately many scripts feature icky bloated away systems. They may announce the away in all channels as an action! Even worse is that they may stick the name of the script at the end of action in rainbow colors. We don't want that, right? Of course you can use /ame but I highly recommend not to use it. /ame <message> sends action to all channels you are on. /ame usually causes trouble if you are on many channels. See what IRCnet #mIRC FAQ say about the issue.

One of the most simple away scripts just sets away for all your connections. It doesn't need any processing of messages since the server does that automatically for you.

It may sound little contradictory but I think that it is best for compatibility to write your own away alias that replaces mIRC's default command. That alias should call the real /away command with ! prefix which tells mIRC to send the actual away command to the server instead of calling the alias again.

Example script

alias away scon -at1 !away $1-

That's it! Very easy and efficient. :-) The scon switch -a tells to execute the command for all connections and -t1 specifies that the commands are to be executed only for connections that are actually alive. The away command needs to be prefixed with ! so that mIRC doesn't try recursive calling of the alias.

I assume that if you are reading this, you probably want something a bit more advanced. Such things could be automatic away after a certain time of idle, more informative messages, and restoring away status after disconnection.

The away message should usually tell why you are away. However I assume that nobody wants to write every reason why they are away from the keyboard at that very moment. I think it is best that if you don't bother to type an away message manually, it will at least be set automatically. The most often used way to determine absence is to have a certain time of inactivity after which the away is automatically set. I also use $appstate identifier on my own away script. It tells whether mIRC is running maximized, minimized, normal, hidden, or tray.

Many people use the time of the moment when the away was set in their away messages but I think it's a bad idea as long as you are on international IRC network with users from many timezones. If you are going to use a timestamp in your away message, at least include timezone information. Generally people are very clueless about timezones and converting them to their local time, at least it has taken me a couple of years to get used to timezone conversions on international networks.

In order for us to set the away after a certain amount of time, we will have to use timers. The easiest way is to set a timer on certain events that tell you are active. on INPUT tells when you type something so naturally that is the most common method. As long as we are using one timer with a defined name, we can always postpone the away by writing new text to mIRC windows. We can also use on APPACTIVE event which triggers every time when mIRC's active status changes. If $appstate is tray, mIRC has just been been minimized to tray. This is another chance of setting automatic away.

Example script

; Clear the variables when mIRC starts
on *:START: {
  unset %away.*
  set %away.global $false
}

; Set global away: /away <reason>
; Set global back: /away
alias away {
  if ( $0 > 0 ) {
    ; Don't allow new aways when you already are away
    if ( %away.global == $true ) return
    set %away.global $true
    set %away.globalmsg $1-
  }
  else {
    ; Don't allow setting back if you already are back
    if ( %away.global == $false ) return
    set %away.global $false
    unset %away.globalmsg
  }
  
  ; If the autoaway timer is running, stop it so that it doesn't cause weird errors
  if ( $timer(autoaway) ) .timerautoaway off
  
  scon -at1 !away $1-
}

; Set automatic away after 60 minutes of idle
on *:INPUT:*: .timerautoaway -i 1 3600 away Automatic away after 60 minutes of idling

; Restore away if you were away before disconnection
on *:CONNECT: if ( %away.global == $true ) !away %away.globalmsg

; Set away when mIRC is hidden as tray icon
on *:APPACTIVE: if ( $appstate == tray ) away Gone

; Display information when the server says you are away
raw 306:*: {
  echo $color(info2 text) -set * You are now away: $awaymsg
  set $+(%,away.msg,$cid) $awaymsg
  set $+(%,away.time,$cid) $ctime
  halt
}

; Display information when the server says you are back
raw 305:*: {
  echo $color(info2 text) -st * You are now back ( $+ $eval($+(%,away.msg,$cid),2) $+ )
  echo $color(info2 text) -st * Away duration: $duration($calc($ctime - $eval($+(%,away.time,$cid),2)))
  linesep -s
  halt
}

Note that the numeric events 306 and 305 use their own variables instead of the global ones. This makes it possible for you to take just the just those two events instead of taking the entire away script. Note the use of $eval and $+ instead of complicated evaluation bracket magic. You can also remove the on INPUT, on CONNECT, and on APPACTIVE events without worrying about the rest of the script: it works fine without them.

Finally some extras you can use to enhance your away script.

Example script

; Bind some function keys to set away and back
alias f3 away Gone, private messages will be read later
alias f4 away

; Notice that you are away if someone sends you a message which opens a new window
on *:OPEN:?: if ( $away ) notice $nick I am currently away ( $+ $awaymsg $+ ). Messages are logged.

Last updated 2003-04-05, Janne 'Geetee' Nikula, jn-mirc@zkelvin.net