Ranking
Original Post
mIRC: Battle Script v1
_________________________________________________
IRC Scripts
How To Make A Fighting Script
_________________________________________________
_________________________________________________
Table of Contents:
1. Introduction
2. What is mIRC? What are Scripts?
3. The Basics
4. Variables
5. If-Else Statements
6. Loading External Txt Files
7. Timers
8. The Battle Script v1 Code
9. Conclusion
_________________________________________________
1. Introduction

Ever been in an IRC chat room and feel you need to fire missiles at a particularly annoying individual? Well, the focus of this tutorial is to lighten your typing load with a simple script. Actually, this tutorial will go through multiple scripting commands, and other concepts including: Aliases, variables, loading external files, if-else statements, simple math functions, and timers. This tutorial will only cover the basics, though, and only what is necessary to code the Battle Script. None the less, it will include a great deal of information to beginners. The Battle Script v1 starts a battle with your target. You then load externally a weapon and dmg points, which is then subtracted from the current enemy health. When they die, if you are an OP, you will de-OP them and then kick them from the chat room! Read on, toribashers!

2. What is mIRC? What are Scripts?

Well, if you don't know what IRC or mIRC is, you shouldn't be reading this. But, since I do have pity on poor uneducated people, I'll tell you. IRC (Internet Relay Chat) is a popular chat method. It is virtually lag free and some IRC clients support "scripts". One IRC client that supports scripts is mIRC. To get mIRC and get into the toribash chat room, read this tutorial.

3. The Basics

After you have set up mIRC, its time to move onto basic scripts. You should know how to use color in chat for this tutorial. First, press ctrl+R or press the Script Editor button (image 1) to open the Script Editor. Click on the Aliases tab.


You should see a lines of code here. Ignore them and skip a few lines under them. Type the following code:
/test /say This is a test!
Press OK and enter "/test" into the window. You should say "This is a test!". This is basically what scripting is. Its a short-cut word. Lets move onto some more scripting commands.

Open the Aliases window (ctrl+R) and try replacing the previous test with this:
/test /say $1 is cool. | /say $2 is ugly!
Enter into the chat box "/test Capt_Zeroth Veb". You may change Capt_Zeroth and Veb to any 2 names. As you see, $1 is replaced with Capt_Zeroth, as $2 is replaced with Veb. Here is a little bit extra: If you edit the code to have two $'s in front of the numbers, it will require two names or else the code will not execute. Also, writing it as "$1-" will make $1 equal to anything typed after "/test" regardless of spaces or punctuation.

4. Variables

Another function of mIRC scripting is the ability to store data as a variable, allowing you to load it anytime into your scripts. First open up the Aliases tab (Ctrl+R) and replace "/test" with the following:
/setvar /set -e %testvar $$1-
/test /say %testvar is my test variable.
/decrease /dec %testvar $1
Press OK and enter "/setvar Twenty Seven". Now, enter "/test". Notice how "/set -e %testvar $$1-" creates a new variable under the Variables tab and sets it to what ever you types as $$1-. When you typed "/test" it replaced %testvar in the code with the variable you set. Also, placing -e in front of the variable makes it so that when you exit mIRC, the variable is deleted. It is not necessary to place the -e. Now, if you enter “/decrease <number>” and then enter “/test”, it decreases the variable by your number. Notice if you do not enter a number, it does not subtract properly.

5. If-Else Statements

"If-Else" statements check to see if a statement is true or not, and if it is (or isn't), it runs a command. Put this into your Aliases:
/test if (# != #toribash) /join #toribash
If you are in the chat room #toribash, exit it. (Make sure you are logged onto the server irc.quakenet.org) Now, enter "/test". This code checks to see if you are in #toribash or not. If you aren't, it brings you into it. The code "(# != #toribash)" takes "#" (the current channel) and sees if it it "!=" (not equal to) "#toribash". If # is not equal to #toribash, it runs the command "/join #toribash" to bring you into the chat room.

Lets try something more advanced. This includes the if-else statement. Put this code in your Aliases:
/test {
if (($1 > 0) && ($1 < 10)) {
  if ($1 < 5) /say Number is less than five
  else /say Number is greater than five
}
else /say Number is out of bounds
}
Now, press OK and enter "/test <any number, letter, or character>". This code determines whether the number you input is greater or less than 10, or it its not a number at all. It then returns one of 3 things. Disecting the code:
/test {
 if (($1 > 0) && ($1 < 10)) {
Notice on the first line is a curly bracket {. The { indicates that there are multiple lines to the code, that it has multiple functions to carry out. The first line is similar. If the number you input is greater than 0 and if it is less than 10 (meaning it must be a number to continue), do the following function:
  if ($1 < 5) /say Number is less than five
  else /say Number is greater than five
}
Now it checks to see if the number inputed is less than 5. If it is, you say so. If it is not leas than five, (meaning greater than 5), you say so. On the next line, is a closing curly bracket }. This means that from the previous { to this } is one function to be carried out at once.
The last part of the script:
else /say Number is out of bounds
}
Now if what you input is not even a number, it would not have gotten past the 2nd line and would have gone straight here: If the input is not greater than or less than 5, it is not a number, and so you say "Number is out of bounds".
Got that? Its okay if you don't, we won’t need to go that complex in the Battle Script.

6. Loading External Txt Files

One of the final concepts you will need to know before pulling it all together is loading an external text file. Lets try a simple code into the aliases:
/test /say $read(quotes.txt)
Press OK. Now, in the same folder that mIRC.exe is in, make a new .txt file called "quotes.txt". Put a few quotes or something on a few lines of the file and save it. Now, enter "/test" into mIRC. It will load a random line from quotes.txt.

7. Timers

Timers can be used to do a function at a specific interval a certain amount of times. Try putting this code in the Aliases and pressing OK:
/test /timer1 3 5 /say Hello!
Upon entering “/test”, the code will repeat 3 times, once every 5 seconds, you say “Hello!” You may use the following syntax to make your own simple timer:
/timer[N/name] [time] <repetitions> <interval> <command>
8. The Battle Script v1 Code

You made it this far, now its time to pull it all together make a Battle Script. First put the following code in your Aliases:
 // Battle Script v1
/sb {
 /set -e %enemy $$1
 /set -e %health $$2
 /me prepares for battle with $1! | /say Health set to $2
}
/attack {
 /set -e %hit $read(hit.txt)
 /dec -e %health %hit
 if (%health <= 0) {
  %health = DEAD!
  /timer1 1 5 /kick # %enemy DEAD!
 }
 /me $read(weapons.txt) %enemy - %hit dmg ~ total HP: %health
}
// End Battle Script
Now press OK. Here’s a quick explanation of each part of the code:
 /sb {
 /set -e %enemy $$1
 /set -e %health $$2
 /me prepares for battle with $1! | /say Health set to $2
}
When you type “/sb <enemy name> <starting health>”, It creates 2 variables: Enemy name and Health. You then say “<Your name> prepares for battle with <enemy>! Health set to <health>”.
 /attack {
 /set -e %hit $read(hit.txt)
 /dec -e %health %hit
This section creates a variable called %hit that will be your damage points. It reads a random hit point from hit.txt (next step) It also subtracts the health by that hit damage.
 if (%health <= 0) {
  %health = DEAD!
  /timer1 1 5 /kick # %enemy DEAD!
 }
Now it tests to see if the health is equal to or lesser than 0. If so, makes health say “DEAD!” This is so there is no negative health. Also, if health is less than or equal to 0, it creates a 1 repetition 5 second timer. After 5 seconds (so he may see his death attack), if you are an OP, kick your enemy from the chat room!

You’re not quite done yet, though. Now make a new .txt file called "weapons.txt" and save it in the mIRC directory. Inside of it put the following:
arms lazer gun and fires at
prepares buckets of butter and launches them at
arms the missiles and fires them at
bakes pie and launches at
primes rocket launchers and fires at
focuses mana and fires magic missiles at
t3h h4x0r l04dz H4X b0mb and launches it at
These will be the weapons that are chosen randomly and loaded externally. You can add more weapons by simply adding a new line of text.

Now, create another .txt file called “hit.txt” and save it also in the mIRC directory. Inside, put the following:
11
10
9
8
7
6
5
4
3
2
1
0
These will be all possible damage amounts. If a .txt file's first line begins with a number, create another line before that with the total number of lines. In this case, 11. Do not edit this txt file. It can severely screw up the code.

9. Conclusion

Congratulations, you should be done and working! Remember, you can only attack one person at once. Perhaps in future versions, multiple enemies will be possible. If you have any problems, just post here.

This is my first real script, I hope you like it. If you want to have fun battling, try creating your own chat room and OP you and your opponent. Take turns battling it out, and the loser is kicked!

Don’t forget, feel free to use, abuse, or mutilate this code. Maybe you could make some advancements on it.

PS. A lot of people find this script annoying, and it can be. If you want to battle, try channel #battletothedeath. Also, be careful you don't get auto-kicked because of "excess flood"!

[EDIT] It seems some computers have trouble coping the color codes. The source is attached below with colors! Read README.txt for quick instructions!