Making Your Own Nick Completer

Contributed by fubar
Nick completion has been around for a long time and is usually very handy for most people, especially in help channels. A nick completer is basically a script that will 'complete' a person's nick when you type the first few letters of that nick. We all know that mIRC has its own built in nick completer (using TAB key) but you can't add your own design or effects to it. This tutorial requires a little knowledge of mirc scripting.
on INPUT
Before you start making your nick completer a knowledge of the 'ON INPUT' event is required. ON INPUT event triggers when you enter text in an editbox and press enter. The format, on <level>:INPUT:<*#?=!@>:<commands>. For a nick completer the format for the on INPUT would be:
on *:INPUT:#: 
note: If you noticed I put a * for the level, this basically means any level can trigger this event, but obviously only you can trigger the 'ON INPUT'. So no need for a level.
Triggering Your Nick Completer
Now seeing how the on INPUT event triggers when we hit enter, we don't need it to trigger when we are using commands. So a basic if statement can fix that. There are 2 ways to go about this:
if (/* !iswm $1)
or
if ($left($1,1) != /)
The first way uses the 'is wild match' operator which is negated with a ! which makes it 'is not wild match' meaning anything that doesn't match /* in the first word. The second uses the $left() identifier (which returns the 1st left character in $1) to check if the first letter is not the command prefix / .

Next we're going to need to check if its a nick completer or not with the assumption that you're using a : to trigger the nick completer.
if (*: iswm $1)
or
if ($right($1,1) == :)
Again we can do this 2 different ways, both the same idea as the first two.
note: You can use any character like : that you want.

Now we need to put the last 2 statements together:
on *:INPUT:#: {
  if ((/* !iswm $1) && (*: iswm $1))
Here I combined the 2 statements with the && (AND) comparison. Now, if you don't type a command and you do have the : at the end of the first word (which should be the start of someone's nick) you can continue with the rest of the nick completer. Also, these statements will enclose the rest of our code.
Looping though the nick names
To find the first matching nick we're going to need to loop through the nicks on the channel. First we need to set a variable and use it to increase and repeat our loop.
var %i = 1
Next we use the /while command to work the loop.
while ($nick($chan,%i) != $null)
This while statement will check to see if $nick($chan,%i) actually exists and if isn't $null the loop will continue. ( using just 'while ($nick($chan,%i)) {' works the same)

Now that we have the base of our loop we can check for the first nick that matches our prefix.
on *:INPUT:#: {
  if ((/* !iswm $1) && (*: iswm $1)) {
    var %i = 1
    while ($nick($chan,%i) != $null) {
      if ($replace($1,:,*) iswm $nick($chan,%i))
    }
  }
}  
Here we're being a little tricky with $replace(). If we're going to be typing, e.g. fu: for fubar we need to find a wildmatch of fu* in the real nickname so we just basically $replace : with * (used for wildcards) . So the if statement really looks like if (fu* iswm fubar).

Now that we have found a nick name that matches we need to msg the channel with the full nickname and message
msg $chan $nick($chan,%i) $+ : $2-
This message goes to the active $chan and puts the full nickname with the rest of what you type in the editbox which is $2- ($1 contains the nick prefix).
This is a basic look for your nick completer.

Now that we've message the channel we should /halt the event from continuing any further
if ($replace($1,:,*) iswm $nick($chan,%i)) {
  msg $chan $nick($chan,%i) $+ : $2-
  halt
}
Dressing it up
This is the fun part of making the nick completer. Creating your own design or designs. We have the basic msg command that goes to the channel. Now we can add maybe some color or boldness. For our example I will use '&k' for control+k (color) and &b for control+b (bold ) and &u for control+u (underline)
msg $chan &b&k5 $+ $nick($chan,%i) $+ &k&b&u:&u $2-
In mIRC this will look like:

Nickname: Hey how are you!

Some people like to go overboard and add tons of colour and/or extra ascii characters, this can be annoying to other people of the channel so you might want to think about keeping it somewhat tame.

That's it, our nick completer is done! Here's the code how you would have it in a mIRC's script file:
on *:INPUT:#: {
  if ((/* !iswm $1) && (*: iswm $1)) {
    var %i = 1
    while ($nick($chan,%i)) {
      if ($replace($1,:,*) iswm $nick($chan,%i)) {
        msg $chan 5 $+ $nick($chan,%i) $+ : $2-
        halt
      }
      inc %i
    }
  }
}
Using random designs
Most people like to have more than one style of nick completer. Here's an easy way to do it.
First, you need to make an alias that will write to a text file.

alias ncomp {
  write ncomp.txt $1-
}
Why have this? Now we can make a simple list of nick complete styles by typing /ncomp &u&k3 $+ $1 $+ &k&u: (Nickname:)

Now that you have made a few styles we need a way to retrieve each style. Instead of using a second alias we can use our /ncomp and make it an identifier ($ncomp).
alias ncomp {
  if ($isid) return $read ncomp.txt
  else write ncomp.txt $1-
}
Using the $isid identifier (returns $true if an alias was called as an identifier) we check to see if you used /ncomp as a command or a identifier. If $isid returns true we used $ncomp else we used /ncomp. By simply using 'return $read ncomp.txt' we can return a random line for ncomp.txt. How we would use this in our nick completer:
msg $chan $ncomp($nick($chan,%i)) $2-
If you didn't want to make it random you would need to add a parameter in your $ncomp identifier telling it which line to return:
if ($2 isnum) return $read -l $2 ncomp.txt
else return $read ncomp.txt
In this if statement it first checks if the second parameter exists and is a number then reads that line of ncomp.txt, if you didn't provide the second parameter or its not a number it just reads a random line from ncomp.txt.

In order to trigger the second parameter you would use $ncomp($nick($chan,%i),4) which returns the 4th line in ncomp.txt

Now we should have the complete /ncomp
alias ncomp {
  if ($isid) {
    if ($2 isnum) return $read -l $2 ncomp.txt
    else return $read ncomp.txt
  }
  else write ncomp.txt $1-
}
All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.