General info how mIRC scripts work
mIRC scripts like all programs are a serie of commands. The difference between them and general programming languages are, that usually normal languages start running the program when you run it, and they run the whole program.
With mIRC scripts there must be an activator, that launches a part of a script, before anything happens. So naturally commands need an activator that activates them in front of them.
In addition to the commands that makes something to happen, theres identifiers in mIRC scripts. Identifiers are something that look for some information, and use it in the script.
Also Variables that you can use to store information, and userlevels have big part in making efficient scripts.
I have also included some general tips in this thread And the purpose of this thread is to introduce a basic scripting, due to the fact, that I do not any advanced scripting myself
Now I am sure you are anxious to start scripting, so just launch your mIRC, connect to the server IRC.chat4all.org, add the B-line, and join to channell #OGbottest. Now press alt+r and you'll see the script editor in front of you
Script editor
When you press alt+r in your mIRC client, the script editor opens.
You see aliases, popups, remote, users and variables tags.
remote section
That window should be open now. In this screen, you write the actual code. The code will be saved in ini file, called script.ini in your mIRC folder. Its not suggested to edit inifiles that mIRC uses manually, while mIRC is running. And when you use the editor, changes you make are automatically saved when you close the editor (by clicking ok), and the edited script is loaded for mIRC to use.
If you edit script.ini manually, you need to use /reload command with appropriate switch to load it. But I am not going to explain that now ^_^
aliases section You put your aliases there, and probably there already is some aliases already.
popups section You can make popup windows to appear, but I have never used them myself, so I am not going to try to explain them
users section you can give userlevels for users, and they appear here. You can do this either by typing them in here, or using some commands like /auser /guser etc. You can also remove users/levels from here, either just delete them from here (users or levels) or use some command like /deluser
Variables section Variables you define in your scripts will appear to here, first the name, and then the value. Also variables can be added or removed manually. note, removing variable from here, will not destroy the part of a script that put it here. so if you launch the script, the variable will appear again.
activators
Now, like I told, nothing happens untill something activates a script. The most usuall events are joinings to the channell and "seeing" some text on the channell or in private message.
REMEMBER that one event can only launch one activator in scripts! So theres no point in making for example two different on text activator with same word triggering it.
Now. Activator always begins with text on. then comes the userlevel and type of the activator. The rest of it depends on activator used. Heres two examples:
ON *:TEXT:hello*:#oldgames:{
/msg #oldgames Hello there!
/msg #oldgames how have you been?
}
This looks quite clear right? Well, it is. But I'll explain some things tho.
Like I said, all activators start with on. Then the * . Well, it means userlevel. And when one uses * or 1 as a userlevel, it means that everyone that (in this case) types hello, will launch the commands. You can give different levels to users, so that if you specify some other userlevel in activator, only user that is on that level can launch the commands.
Next theres the word TEXT. That tells that a text that is specified next activates the script. hello* is the text that launches script, and #oldgames after it tells, that the word hello must come from the channell #oldgames. Now. notice the * after hello. That means that there can be something after word hello, and script will still work. If you use only word hello, without *, then only plain word hello launches the scrit, not "Hello there" for example.
But since theres no star in front of word hello, the activator wont work if someone puts something in front of word hello, like "hey you, hello there".
Alternative ways to put * in text activator are:
Hello : only plain word hello launches the script
Hello* : hello you works, plain hello works, but also hellowfellow would work.
*Hello* : hello works, Blaablaa hello works, blaablaahelloblaanlaa works, helloblaablaa works hello blaa works etc... I assume you got it
*Hello : Well, I assume you know
Now. You can also leave a space between star and hello:
* Hello : Now blaahello wouldnt work, but blaa hello would. However, if you use space between the word hello and star, then there must be a word either before, or after or both before and after the word hello, depending on wich side the star is, or if its on both sides.
Hello * : (word must follw after hello)
* Hello * : (there must be a word both before and after hello)
looks confusing? well, it isnt. try it out
The actual commands there is (those commands that re inside brackets) does not belong to actual activator, but are commands that execute after activator is triggered. IE. when someone types hello on #oldgames, the bot (your client) would send texts "Hello there!" and "how have you been?" on channell, and then execute command 3 ... untill the closing bracket, or command /halt
[B]Remember, you cant activate on text activator yourself from your bot account. So for testing this, you need another account. Thats one reason why peoples that do bots usually use other account to chat normally
Well, I'll show the joining activator:
on *:JOIN:#oldgames:/msg #oldgames welcome ^_^
This would trigger when someone joins on channell #oldgames, and then execute command /msg #oldgames welcome ^_^, wich works just like commands abowe. Like you see, if theres only one command after activator, brackets are not needed, but command can be put right after the activator.
if you use brackets, REMEMBER THE CLOSING BRACKET. If you forgot it, your script might work oddily, or not at all...
If you want to use your bot on multible channells, you can use:
on *:join:#:{...} or
on *:TEXT:blaablaa:#:{...}
Now using # means that activating event can occur in any channell.
If you want that activator triggers only if command is given in private chat window, you can use ? instead of #
and if you want that command can be given either in any channell, or in private window, you can use *
masks, or more like addressess O_o
Adress, or mask or whatever is a thing that tells where the connection comes from. And since in IRC nicks often change, its a quite good way to recognize person.
Unfortunately with some connectiontypes, like dialups, address is often changing, or at least some part of it. Therefor when we use adress based commands, we can usually decide if we want to use whole address, or just a part of it.
Usually I use mask number 3, wich means I cut something out of the address... Heres an example:
My "address" using masknumbers from 1 to 10
*!*sluiba_99@No-IP-C01D3429.suomi.net
*!*@No-IP-C01D3429.suomi.net
*!*sluiba_99@*.suomi.net
*!*@*.suomi.net
Maz|Lurking!sluiba_99@No-IP-C01D3429.suomi.net
Maz|Lurking!*sluiba_99@No-IP-C01D3429.suomi.net
Maz|Lurking!*@No-IP-C01D3429.suomi.net
Maz|Lurking!*sluiba_99@*.suomi.net
Maz|Lurking!*@*.suomi.net
*!sluiba_99@No-IP-C??D????.suomi.net
Now, when you look the address given with number 3, you see that hassle with numbers cutted out. Thats often the changing part, although other parts can change too...
Anyways, if you want your bot to recognize some member, I suggest you to use the address instead of nick ( prevents cheating with nick changing more efficiently ) and to use mask number 3.
Examples how to do the recognizing, first when a member you want bot to remember is online, write his address somewhere so that you can remember it. You can see it for example by using //echo <channellname> $address(<nick>,3) command.
Then if you want some command to be executed only for him, use if then structure like this: after activator put this: if ( $address($nick,3) ) == <address you just wrote> ) { /command you want to be executed for this member } else { commands for other members }
commands
I show some basic commands here. You can use these from commandline too, but when making a bot, scripting is more interesting for us
Remember, to execute any command from script, you need an activator to be triggered first!
/msg <channell or nick> <message> : this sends a message to a channel, or to a person in private chat. Example /msg #oldgames Hi All or /msg Maz Hi Ho you dirty old fellow
/describe <channell or nick> <message> : Works like /me command in commandline. Remember that /me command cant be used in scripts. example: /describe #oldgames needs a beer would send a purple message " *MazBot|V2 needs a beer" to channell #oldgames. (if the nick of the bot would be MazBot|V2)
/timer <how many times command will be executed> <delay between executions (in secs)> : Will execute command after certain time. Example: /timer1 10 20 /msg #oldgames MazBot nods This command would first wait 20 secs, then send message MazBot nods to the channell, wait another 20 secs and send it again... It would do it 10 times, and then stop.
/set <name of the variable> <value of the variable> : this would set a value to variable. Example: /set %age 25 | /msg #oldgames %age would first set value 25 to variable %age, and next command would send it to channell #oldgames. Remember, commands must be on separate lines, or then there must be | mark between the commands. I suggest using separate lines, since usage of | mark can do scripts messy to read.
/var <name of the variable> <value of the variable> : this would set a value to local variable.
/enable <name of the part to enable> (see the separating parts of the scripts )
/disable <name of the part to disable> (see the separating parts of the scripts )
/write <filename to write> <line to write> : Writes a line to file. notice, reading is not done by command, but by identifier
/guser <level> <nick> <mask number> : adds user to specific level, so that recognizing of him is based on his address (mask) see userlevels and masks
/ruser <level> <nick> <masknumber> : removes the specified level from certain user, based on address.
/inc <name of a variable> <amount (optional)> : increases the value of a variable with the amount specified. If amount is not specified, it will be assumed to be 1
/dec <name of a variable> <amount (optional)> : decreases the value of a variable with the amount specified
mIRC also supports so called raw commands, that are commands to be sent straight to the server. I know nothing(much) about them, so I cant teach anything about them. I have also heard, that you should avoid using them, unless you know what you are doing
If - Then structures
if then structures allow you to make conditions, when something happens. Basically, just like name tells, If something is true, then something happens.
Example:
if ( 1 == 1 ) { /msg #oldgames I can count!!! }
Well, that example is quite useless, since the sentence inside () is always true, so command inside brackets (then command) will always be executed.
NOTICE that equal is not = but ==. If you use =, mIRC thinks you are trying to set a value to a variable!
You can use also variables, identifiers etc. inside (). A bit more usefull example:
on *:join:#oldgames:{ if ( $nick == Maz ) { /msg #oldgames YAY, hes here again!! }
else { /msg #oldgames Hi $nick } }
Now. like you see, when someone joins to the channell, it triggers the activator. Next there is if sentence, wich compares $nick [URL=] identifier to text Maz. If they match, it executes command inside brackets, else the command(s) inside else brackets.
What if I dont put else command there, but just the command for other joiners? Then when I join, it would execute BOTH welcomemessages. That could be prevented by using halt command inside the brackets, like this:
on *:join:#oldgames:{ if ( $nick == Maz ) {
/msg #oldgames Hi Ho Mazzy
/halt }
/msg #oldgames Hi $nick }
Now if joiner is me, program goes into then brackets, and first sends the message, and then bumps into halt command and stops. If someone else joins, it does not go inside then brackets, but goes to the next command after it.
aliases
Aliases section in script editor is reserved for your own commands. So if you need some thing to happen in multiple parts of your script, you can define an alias to do it.
Just invent a good name for your command, and add / in front of it, to really make it a command. then leave a space, and add brackets. Inside these brackets you can put multiple commands, if then structures etc.
I have an example here:
/quizansw {
inc %missattujaQ
/msg #oldgames answer was %vastaus ...tea drinkers...
dec %QUIZCOUNTER 1
if ( %QUIZCOUNTER != 0 ) { /read_quiz }
else { set %onoffquiz 0 | /pstatQ | /msg #oldgames statistics: total amount of questions: %totalQ | /msg #oldgames known answers %tiedettyjaQ | /msg #oldgames unknown %missattujaQ questions this far | /msg #oldgames and cancelled/skipped questions %skipped | halt }
This is my own command from MazBot. It can be used just like normal command, and when I use it ( just put /quizansw somewhere as a command) it executes all those commands that are inside the brackets. This particular alias handles with giving the right answer in triviagame, if no one knows it untill the time is up. It also prints points statistiks and does some other things.
Aliases are wery powerfull tool, but I suggest you to name them wisely. Using lots of badly named aliases will definitely make your script hard to follow...
Variables
Variables are "storages" where you can put information. It can be either numbers or text. And you can use them in calculations, and message them on the channells etc.
The name of a variable starts always with %
You can give value for variable by using /set command example: /set %age 25 , or straight defining %age = 25
variables appear to variables.inf file, and you can see them in your script editor at variables tag.
You can also define the value of a variable, by doing a calculation (example: %total = %part1 + %part2 , %howmuch = 1 + 6 , %blaa = %sigh + 5 ). Still if you need to calculate more than one operation, you need to use $calc() identifier. %bahbuh = $calc( ( 1 + 3 + 6 + %fksnd - 7 ) / 4 ).
Remember that sentence at left side, will be calculated first, and after that the result will be stored in variable.
You can also use the previous value of the same variable in operation, like: %age = %age + 1
Increasing or decreasing of the value of a variable can be done with commands /inc and /dec too
/inc %age 4 increases value of %age with 4
/dec %age 5 decreases the %age with 5.
If you do not sepcify the amount that will be decreased/increased, it will decrease/increase 1 as a default.
you can also storage text in the variables. /set %blaa blaablaa, would set blaablaa as a value for variable %blaa. With text variables you cant of course do any calculations, but they can be sent to channell just as normal variables.
Some examples:
on *:TEXT:count*:#oldgames:{ /set %round $2
while ( %round > 1 ) { /dec %round
/msg #oldgames %round }
}
in some cases you need to force mIRC to evaluate the value of variable before doing something. That can be done by putting variable inside [] .
Script sections
You can divide your script in to sections, and either disable or enable sections with /disable <name of the section> and /enable <name of the section> commands.
Section name is always form:
[B/]#name_of_the_section on/off[/B] (on or off, depending if the section is enabled or disabled) at the beginning
#name_of_the_section end at the end of section
I for example have this in MazBot:
#comments on
on *:TEXT:*beer*:#oldgames:{ ... }
on *:TEXT:*guinness*:...
.
.
.
#comments end
on 75:text:talkbot:#oldgames:{ /enable #comments }
on 75:text:stfubot:#oldgames:{ /disable #comments }
Got the idea?
I suggest all of you to have this in your bots, since sometimes bots that keep babbling always when one says something he is talking with other member gets kicked and banned
and of course you can use that to disable/enable other features of your bot too.
userlevels
Userlevels are handy tool. You can use them to allow only some users to access some commands, without writing excessive amounts of if-then sentences.
You can either use numerical userlevels, or with newer versions of mIRC also userlevel that consist of letters.
If you use numerical userlevels, remember that all users that have the required leve or higher, can launch the command. Therefor you might want to reserve the highest level for yourself so you can use all commands, and specify some commands only for your own usage
How to actually use levels:
Now remember the activators, wich I have usually typed as follow:
on *:text:...
or
on *:join:...
We can specify a level that is required to launch the script, by putting it instead of * there. like:
ON 75:TEXT:... Now, only user that has level 75 or higher can launch the script.
or then we can use
ON noquery:join:#oldgames:{ /halt } Now if user that joins has level noquery, he launches this script (that does nothing), but since he launches this, he doesnt launch the following on *:join:... statement I have.
How to give levels for user?
Theres two ways. Either type the levels manually in your script editor, in users section, as follows <level>,<level>,...:mask you want to use, or nickname. Example:
200,=noquery:*!*Maz@*.suomi.net
Now if you wonder whats the = mark before the level noquery. That means the level is so called specific level. If you add levels with command (not manually), all levels that consist of letters will be marked as special levels. If you specify a numeric level with = mark, it means the level only launches the scripts that have exactly same level, not the lower levels.
The second way is to use command
/guser <switch> <level> <nick> <masknumber>
switch is optional, but using switch -a adds the level to user, if user does not already have it.
Like you see, this command adds the level to user, and recognizing user will be based on his address, not his nick.
There is also way to add levels for users so, that user will be recognized by his nick, but like I have already told, nicks can change often in IRC, so I suggest using addresses. More info about userlevels can be obtained from mIRC helpfile
General tips
If your script does not work as it should, check the statuswindow for errormessages. And at least for me, 90% of all errors were beacuse of typos, missing brackets or missing : .
Also using /echo command is a good way to see what parts of your scripts are working, and wich arent. For example /echo #oldgames Variable increased successfully prints to your screen, at #oldgames channell window that message. Remember, /echo command does not send anything to the channell, it just shows the text for you.
Remember, the best way to learn is to do, so feel free to join us to server irc.chat4all.org, at channell #OGbottest
Remember to add comments in your scripts. You can add a comment that does not affect on script by placing a ; in front of the line
And more commands, identifiers etc. with their explanations, you can find from the mIRC help file. (launch mIRC, press alt+r and select help) It is quite good, almost all I know I learnt myself from it