Starting Out With Scripting

Contributed by blue-elf
Introduction
So you have decided to script mIRC or you've just began to do it. But what if you don't have any programming knowledge, or you're simply confused? This tutorial will attempt to guide you in learning how to script.
After hanging out in help channels for so long, it occurred to me that the biggest problem that a new scripter encounters is confusion. There are those who might already know a lot of commands, or identifiers and yet are unable to connect those separate elements together. Let's find out how we can avoid that confusion.
Knowledge of simple commands
There are no shortcuts in learning. People learn to crawl first before they can walk. We learn the A-B-C's and then attempt to write words, and after we can write words, only then we create sentences. The same is true with scripting (or programming or anything at all). From what I have observed, there are bad scripters because they immediately jump in to if-else statements without even understanding why the if-else are needed, or they would try and use variables without knowing the purpose of variables, or how to unset them.
What I'm trying to point out is, before you can actually script something, you have to know the simple commands. And one of the most useful tool in mIRC is the Help File - or what is called mirc.hlp and that comes in every copy of mIRC. There are things in there that are quite confusing, and that's what help channels are for (you can go to UnderNet or EFNet #mIRC - just don't ask stupid questions). But referring back to the mirc.hlp again and again won't hurt you (I confess, I printed out the whole mirc.hlp back in mIRC 4.72 just so I could refer to it easier).
Putting the pieces together
So you know that there is a /whois command and you know that there is an /ignore command. But how do you put them to good use? You're itching to write an alias and you only know two commands!

Have a plan. Think ahead what you want to achieve. For instance, you want an alias that will ignore a user for a certain period of time, and while you're ignoring, you want to know who the person you are ignoring. So, put them together, and make an alias like the one below:
ign {
  ignore $$1
  whois $$1
}
From two simple things, you have written a short alias that does exactly what you wanted it to do.
Improve, upgrade, complicate
Now you have a /ign alias. You're happy with it, and you're using it, doing ignores and whoises in a single command, having it in the popups.. suddenly you realize that you are now faced with a few problems.
1. That command ignores the nicknames only, and not addresses.
2. It does not remove the ignore, you have ignored your friend accidentally, when you actually meant to ignore them for 5 seconds only.
3. The annoying *** Not connected to server error comes up twice after you accidentally typed /ign and you were not connected to a server.
So far, we have the following alias:
ign {
  ignore $$1
  whois $$1
}
We typed /help /ignore and the help file gives us this:
/ignore [-lrpcntikxu#] [type]
Where p = private, c = channel, n = notice, t = ctcp, i = invite, k = control codes.

The -u# switch specifies a delay in seconds after which the ignore is automatically removed.
The -r switch indicates that the address is to be removed.
The -x switch indicates that this address should be excluded from ignores.
The -l switch displays the list of ignored addresses which match the specified switches.

(Note: In writing this article, I stumbled upon /ignore -l which renders one of my aliases semi-useless.)
Okay, so there's a [type] there allowing us to ignore users by address even if the nick is specified (let's assume you've read the mirc.hlp about $mask and asked in #mirc or posted a question in pairc.com's webboard that's why you understand mask types already).
ign {
  ignore $$1
  whois $$1
}
That fixes problem number 1. Now to solve problem number 2. Let's look again at the help.. and there we find the -u switch. Let's insert that in our alias...
ign {
  ignore -u5 $$1 3
  whois $$1
}
And now for the third problem, we don't want it to give out that error message.. this is where we start doing if-else statements...
ign {
  if ($server != $null) {
    ignore -u5 $$1 3
    whois $$1
  }
}
So two identifiers are introduced. The $server and the $null. How would you discover it? By asking.

Here's an explanation of that alias, line by line.
ign {
 ; the alias name

  if ($server != $null) {
    ; in plain English, it would mean "If there is a server"
    ; it's like saying that if the $server identifier has a value which does not equate to
    ; $null - which means nothing - then we are connected to a server and we can proceed
    ; with our little alias.

    ignore -u5 $$1 3
    ; ignore the loser for 5 seconds, using mask type 3 - that would be *!*ident@*.domain.com

    whois $$1
    ; then do a whois on him

  }
}
Exercise
Find out how well you can improve this alias. Modify it so that it will:
1. Hide the default ignore display and make it display the way you want it.
2. Make the 5 second ignore optional, and rewrite it so that you can specify the number of seconds at will.
Hints and Tips
Think ahead.

Know what you want to do before you attempt to do anything. Some people actually just write. While it may work sometimes, it may not work for everyone - especially for somebody new to scripting.

Think simple.

When you script, do not be intimidated with the complicated scripts that you have seen. It is good to learn from those scripts but it is not good to try to complicate yourself for no reason.

And also, when you think in a simple way, you script in a simple way. Even mIRC will not be confused and burdened in trying to parse your commands.

Do not go into areas that you do not understand completely. I've met people who don't even know how to do if-else statements and yet attempt to socket scripting. Try a simple ON JOIN, or a simple /kick alias, before you go and script a huge global nick completion ON INPUT event. Because if you cannot achieve the simplest things, I doubt you will be able to script the more complicated aspects of mIRC.

This does not mean that you have to avoid hundred-line aliases. It only means that you can script complicated stuff only when you are comfortable scripting with simple commands and when you have a good knowledge of mIRC commands, identifiers, etc.

And even when you have reached a higher level of scripting (or even when you have decided to learn how to write hello.c), remain logical. The idea behind the example above still applies even when you are already scripting your flood protection.

Seek help.

No. Not just because you're demented, but because you don't know. Be careful though. Before asking any questions in any help channels or webboards, make sure you have read the mIRC.hlp a few times, and you have attempted to understand it. If you don't, you'll either be ridiculed or ignored.

Experiment.

Try the things you have read before anything else. Don't be scared to test things - even if it might crash mIRC sometimes. Just have your backups intact.

Conclusion
What I have written so far may or may not be of use to you. The important thing is, it takes time to learn how to script. And it takes longer time to be good at it. Just learn at your own pace and be patient.

All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.