mIRC Scripting

mIRC: Aliases

Aliases, more commonly known in other languages as functions, are small independent code which performs a specific task and can be relatively independent of the remaining code. Most aliases are created to be used multiple times by different scripts.

Aliases can also be made to create custom Function Keys and shortcuts.

Aliases can be written in two places: Aliases Tab Alias_Window, and the Remote Tab

Aliases Window

The basic syntax will look like this:

<name> <commands>
;or
<name> {
  <commands>
}

An example would looks something like this:

/Ctime msg $chan The current time where I live is: $time(hh:nn:ss TT) || TimeZone: $time(zzz)

By simply typing /ctime in any of your channel you will trigger this custom alias. Which will show something like this:

<@David> The current time where I live is: 12:33:01 PM || TimeZone: -0500 GMT

Remote Window

The remote section its almost the same thing except you will need to start the alias with the word “alias”.

alias <name> <commands>
;or
alias <name> {
  <commands>
}

Custom Properties

Just like mIRC’s identifiers have properties for things like $file and $chan. You can have custom properties for your alias. The $prop identifier can be used to return the property that was called.

Try the following identifier with and without the property test:

Alias Average {
  ;First check if its an identifier or not
  if ($isid) {
    ;calculate the average, (sum of $1 + $2 + etc...) / (total numbers ($0))
    return $calc( ( $replace($1-,$chr(32),+) ) / $0 )
  }
  ;Its a command
  else {
    ;echo the results
    echo $color(info) -a * Average Of $&
      $chr(123) $+ $replace($1-,$chr(32),$chr(44)) $+ $chr(125) $&
      == $calc( ( $replace($1-,$chr(32),+) ) / $0 )
  }
}

; $0 – returns the number of $n s
; $chr(123) and $chr(125) - { and }
; $chr(32) - space

Usage:
//echo -a $Average(2,99,34,65)
returns 50

or

//Average 2 99 34 65
will echo: * Average Of {2,99,34,65} == 50

Identifier or a command

Aliases can be used as an identifier or as a command. A command will usually not return anything but simply process some information. An identifier will require the alias to return an output.

The /return command allows the calling routine to continue on. Let’s say we have a dialog that requires an alias to calculate an average of a few numbers. We can call the average alias to calculate it and return the output back to the dialog so it will continue on.

The $isid can be used to check whether or not the alias was called as an identifier or as a command by return $true for identifier and $false for a command.

Alias Example {
  if ($prop == test) {
    return Test Worked! (Input: $1)
  }
  else {
    return Example! (Input: $1)
  }
}

; //echo -a $Example(cool).test
; returns Test Worked! (Input: cool) , while:
; //echo -a $Example(cool)
; returns Example! (Input: cool)

Passing Arguments

Data can be passed to an alias. You can refer to the data using the $Nth Identifier to refer to the data that was passed.

When an alias is called in a form of a /command, mIRC tokenize the value by spaces ($chr(32)). For example:

/Example This is a test

Alias Example {
  echo -a Total Words: $0
  echo -a First Word: $1
  echo -a Second Word: $2
}

When it’s called in a form of a value-returning alias ($ident()), you can pass individual arguments separated by commas.

//noop $Example(This is the first argument.,This is the second.)

Alias Example {
  echo -a First Parameter: $1
  echo -a Second Parameter: $2
}

Function Keys

Aliases can be used to redefine function keys and shortcuts by simply renaming them the actual key or key combinations. For the F-keys all you need is to name the actual alias F1 to F12. C and S can be used for the Shift and Ctrl Key.

The following example will trigger when you press the F2 button:

Alias F2 {
  echo -a * F2 Was Pressed!
}

F-Keys can be combined with the shift or control button as well. This will trigger when you press Control+F2:

Alias cF2 {
  echo -a Ctrl + F2 Were Pressed
}