All pastes #122306 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-08-08 16:14 UTC
rendered paste body
                      RussellReal's Introduction to scripting guide!


Index:
I    introduction
II   aliases
III  read|write from|to text files
IV   Variables
V    conclusion



I Introduction

Hey, and welcome to RussellReal's first ever tutorial, or better yet, step by step help with scripting, with this guide I'll do my best to make sure you understand everything you're about to see, this tutorial will consist of a little bit of aliases, introduction to variables, and how to write and read from a text file.




II Aliases

Aliases are very important for a number of reasons, and one of those ways, is that it allows you to trigger your own scripts, basic knowledge indicates that someone on mIRC can't and will not be able to activate their own on TEXT events. in this case, an alias would come in handy, its the same as an on TEXT event (in a way) but only you can activate it :).

OKAY so lets get started with aliases:

K so here is where you have to think, similar to the /join command or /quit command, after you finish this alias it will be a command like that, so for this tutorials sake, lets make this event say a random number :) Hows that sound? Good? OKAY!

First you want to make the command to start the alias.

[code]/random {[/code]
 ;there is your first line of your alias, that make the command to activate whatever is after the { (bracket) and do what you like, to activate this you'd type /random into a channel window :)

K so now lets make the random number, then make it message the channel :)

[code]/msg $chan random number is: $rand(1,99)[/code]
 ;The "/msg" means "Message" and "$chan" means the channel that you activated the script on, and You might not be too familiar with the $rand Identifier, so let me briefly explain it, it gets a random letter number etc from the range you specify within the () if you did $rand(1,2) it will return (at random) 1 or 2. All together, it should be read like this if you were reading the line "Message Channel Random number is: 1-99" and that doesn't seem so hard does it?

Lastly, You'd like to close off the script for every { there is there should be a } to close it off.

[code]}[/code]
 ;congratulations if you have followed the guide, you have just created your first alias!

Code should look like this if it was done right:

[code]
/random {
  /msg $chan random number is: $rand(1,99)
}
[/code]



III Read|Write From|To a text file.

Okay, this is a very basic, but another very powerful technique to storing information for later use. (Note: If what I tell you here is too basic for what You need, then in the mIRC window, type /help write or /help $read for more detailed information).

 ;/write:
Okay lets get this outta the way, This to me seems pretty hard for a beginner, to learn now, but Lets give you a shot :) It was one of the first things I learned, and I still use it often.
Basics: Say we want to write everybody's name that says "lol", to a text file to a text file named lol.txt
Okay lets start off, most of anybody knows about on TEXT events, but if you don't lets start you off on a good foot.
 on TEXT events follow this syntax: on <User Level>:TEXT:<Match Text>:<Channel>:{
 on TEXT events trigger when someone says what is in the <match text>
Okay so lets get started, We arn't getting into user levels in this tutorial, so lets not worry about the <user level> area for now, just use * as the user level.  
 now so far this is what we have: [code]on *:TEXT[/code]
now to fill in the match text field, lets for this script, make it *lol* the reason "lol" is encased in * (asterisks) is that it means "lol" is before or after anything, or inside anything even. :) so you can be sure you'll catch every lol :) lol
 now so far we have this: [code] on *:TEXT:*lol*: [/code]
now to fill in the channel field, for this tutorial, you will use just # that means any channel.
 now what we have is this: [code] on *:TEXT:*lol*:#:{ [/code]
______________________________________________________________________
Back to the write command.
 the proper way to use write is (in basic terms) /write <text file> <what to write to the file>
 so here we have your first like:

[code] on *text:*lol*:#:{ [/code]
;this part just states that when someone says lol in any spot in the line, the script will trigger.

 now to add the /write command.

[code]/write lol.txt $nick[/code]
;this "writes to text file lol.txt the nickname of the person who triggered the script"

 now to close it off, like I said in the alias tutorial above, for every { "opening bracket" there should be a } "Closing Bracket"

[code]}[/code]
;that closes off the script, congratulations you have just made a write script! :)

This part of the complete script should look like this so far:
[code]
on *text:*lol*:#:{
  /write lol.txt $nick
}
[/code]
________________________________________________________________________
 ;Read:
Now the cool part, This will be another basic "Just for your knowledge" script.
To read from the text file you just wrote, You might want another event to take place. (although thats not nesessary)
but to start us off, lets revert back to the write section where you learned how to make an event or "check" so lets make it [code]on *:TEXT:!read:#:{[/code]
so here you go, lets start this off.

[code]on *:TEXT:!read:#:{[/code]
;thats just what triggers it, Read like: "When Someone on # (means any channel You are on) says !read, trigger the following commands:"

now you wanna fill in the commands you want, so for this, you want to $read from lol.txt for this script we'll read it at random.

[code]/msg $chan Someone Who said "lol": $read(lol.txt)[/code]
;that is the read part, its read like: "Message Channel Someone who said "lol": Read random line from lol.txt"

now you just gotta close it off

[code]}[/code]
;that closes the script, congratulations you have just read the text file you wrote to :).


This part of the script should look like this if done right:

[code]
on *:TEXT:!read:#:{
  /msg $chan Someone Who said "lol": $read(lol.txt)
}
[/code]

Whole Code should look like this if done right: 

[code]
on *text:*lol*:#:{
  /write lol.txt $nick
}
on *:TEXT:!read:#:{
  /msg $chan Someone Who said "lol": $read(lol.txt)
}
[/code]


IV Variables

These are tricky, (not really trying to scare you lol) They are so easy! You'll be like "OH GOSH! THAT WAS SO EASY!" they just look tricky lol, well here lets start you off. % is the prefix for most variables, most variables will start with that.
we arn't going to get into temporary variables, or dynamic variables, just regular, easy to use, basic variables. Be sure to type /help variables if this doesn't give you a general enough idea.
 here you will learn to set, and unset, and read whats inside of the variable. and learn ways to use them. this is yet another powerfull tool.
 to set a variable you will have to use /set %<variable name> <whatever to put inside of it>
 k so lets start off, We're gonna add onto the alias we made in chapter II Aliases, We are going to set the random number to the variable, and then return the variable to the channel.

[code]/random {[/code]
;first line of this script, just like in chapter II Aliases.

K so now lets make the random number set to a variable instead of just messaging the channel :)

[code]/set %rand $rand(1,99)[/code]
 ;that will set the variable %rand to the random number between 1 and 99 read like: "Set %rand 1-99"

now you want it to be sent to the channel.

[code]/msg $chan The Random number is: %rand[/code]
;that messages to the channel the random number that is inside of %rand read like: "Message Channel The random number is: Whatever is inside the variable" 

Now, you don't want your variable set and taking space in your variable tab, it gets hectic in there, you'll use variables alot. so now lets unset the variable.

[code]/unset %rand[/code]
;that unsets %rand Read like "Unset %rand" <-- lol :)

Lastly, You'd like to close off the script for every { there is there should be a } to close it off.

[code]}[/code]
 ;congratulations if you have followed the guide, you have just enhanced your first alias, and just learned to set read and unset your variables!!

 Script should look like this if done correctly:

[code]
/random {
  /set %rand $rand(1,99)
  /msg $chan The Random number is: %rand
  /unset %rand
}
[/code]


V Conclusion

In this part of the tutorial, we will colaborate all that we learned into one script. so for this part, lets make an alias, that reads and writes, and I'll also teach you a lil trick, which makes writing scripts so much easier :)
K so the point of this conclusion is to put your mind to the test, First I'd like to thank you for using my tutorial :) And I hope you've learned something, Scripting has been real good to me, and its been what I do to pass time
for the past month :) Enjoy scripting, Its really fun.

so lets get started!! lets get started with the lil alias trick, We'll make the alias be able to be in the remotes section, but still be used like an alias. :)

the only thing you have to do is change the "/<alias name> {" To "alias /<alias name> {" and it becomes a variable that can be put into your remotes section :) Btw, Aliases can be triggered inside of a script, to do whats inside of the command. when you want it to.

so now lets make an alias thats going to write whats inside of a variable (That we will set at a later time) :)

[code]alias /copy {[/code]
;thats the remote version of /copy {

the next line should be:

[code]/write copy.txt %variable[/code]
;that writes what is in the variable %variable to the text file copy.txt

The next line should be:

[code]}[/code]
;That closes off the alias, and you are ready to start writing the next part of this script.

Now we will make the script, which will give us the variable %variable and which will trigger our alias.

[code]on *:TEXT:*omg*:#:{[/code]
;that will trigger anytime someone says.. omg 

Now we will set the variable

[code]/set %variable $nick[/code]
;that will set the nickname of the person who said "omg" to the variable

Now we will trigger our alias inside this script.

[code]/copy[/code]
;that triggers your alias that you just made

now we will close this script off.

[code]}[/code]
;that closes the script off.

now we will set an event to read from the text file copy.txt

[code]on *:TEXT:!copy:#:{[/code]
;that is the event. Read like "When someone says !copy trigger the events that follow the { (starting bracket)

next line will simply message to the channel at random, a line from copy.txt

[code]/msg $chan $read(copy.txt)[/code]
;that message the channel with a random line from the text file copy.txt Read Like: "Message Channel : Read random line from copy.txt"

next line will simply close off your script

[code]}[/code]
;that closes off your script.

The script should look like this if you did it right:

[code]
alias /copy {
  /write copy.txt %variable
}
on *:TEXT:*omg*:#:{
  /set %variable $nick
  /copy
}
on *:TEXT:!copy:#:{
  /msg $chan $read(copy.txt)
}
[/code]
If you did it right You're awesome!!! YAY! :) enjoy scripting, I might write other guides later on, Sincerely Russell J. Crevatas (RussellReal)