Jump to content

Welcome to Pure Warfare - The #1 Community for Pures

Welcome to Pure Warfare - The #1 Community for Pures, like most online communities you must register to view or post in our community, but don't worry this is a simple free process that requires minimal information for you to signup. Be apart of Pure Warfare - The #1 Community for Pures by signing in or creating an account.
  • Start new topics and reply to others
  • Subscribe to topics and forums to get email updates
  • Get your own profile page and make new friends
  • Send personal messages to other members.

[Tutorial] An Introduction to mSL.


Recommended Posts

An Introduction to mSL.



Index

• Introduction
• Bracketing
• Tokens
• If-Then-Else
• Variables
• Remotes
• Aliases
• Conclusion




Introduction



mSL (mIRC Scripting Language) is definded as "a powerful scripting language that can be used both to automate mIRC and to create applications that perform a wide range of functions from network communications to playing games."

Bracketing



The mSL, like other languages, uses brackets to organize scripts. An opening bracket is "{" and a closing bracket is "}". The key to the bracket system is that your brackets must balance. If you open a bracket, you must close it by the end of the script. The best way to think about bracketing is as a roadway. Take a look at the script below:

alias checkme {  if ($me == Jay) {	echo I am Jay!  }  elseif ($me == Karl) {	echo I am Karl:(  }  else {	echo Who am I?!  }}



The first bracket is opened on the first line, "alias checkme {". This bracket opens the entire script, all components of the script must fit inside of this bracket and the final bracket, which will be at the very end.

Next is another bracket opened on the "if ($me == Jay) {" line. If the condition in this "if" statement is true, all commands within this opening bracket and the next closing bracket which will close the statement are executed. If not, the script will skip ahead to the beyond the closing bracket which would have closed this opening bracket. So if $me does equal "Jay", all commands until the closing bracket which will end this statement are executed, which would be "echo I am Jay!". If $me does not equal "Jay", it will skip to the closing bracket which ends the statement, which would be the "elseif" line.

Below is a script which does not have balanced brackets. I've colored the opening and closing brackets of the same statement so you can see how they match up.

alias example {
if ($1 == 1) {
echo It's one.
}
else {
echo It's not one.
}

As you can see, the original opening bracket (the red one) is never closed, which will cause problems with this script as well as any scripts after it in the file.

Tokens



Tokens are what mSL uses to identify certain text within a line.

You can use the $1 $2 ... $N identifiers to refer to individual parameters in a line. You can also use $N- to refer to parameters N and onwards, and $N-M to refer to parameters $N through to $M. So to refer to a whole line, you would use $1-.


Here are some examples to help you understand how tokens work.

"Hello there my name is Jay!"

  • $1 equals Hello
  • $4 equals name
  • $1-2 equals Hello there
  • $3- equals my name is Jay
  • $0 equals 6 (the number of tokens in the line)
  • $1- equals the entire line, Hello there my name is Jay!



Let's apply this to a simple script.

ON *:TEXT:!calc*:#: {  notice $nick $2- equals $calc($2-)}



The above script would trigger when a user enters a line which begins with "!calc". That would mean $1 is always !calc, or anything that begins with calc. Therefor $2 is where the calculation to be performed begins. In order to get the entire calculation, we use $2-.

If-Then-Else



All scripting is based on an "If-Then-Else" format. The principal idea of this is if a condition is true, then an action is carried out, else it is not. It looks like this:

if {  then}else {  then}



Using this format, you can create a script to perform a certain action if a condition is true, and do something else if it is not. For example:

if (1) {  then}else {  then}



Notice that there is only a condition for the "if" statement. This is because the "if" statement is used to execute a command if a certain condition is true, and carry on if not. If you would like to check for multiple conditions, you would use elseif.

if (1) {  then}elseif (2) {  then}else {  then}



An "elseif" statement can only be used after an "if" statement, and will only be checked if the "if" statement before it is false. Here, let's try putting it to use.

alias checkme {  if ($me == Jay) {	echo I am Jay!  }  elseif ($me == Karl) {	echo I am Karl:(  }  else {	echo Who am I?!  }}



Above is an alias called "checkme". When you enter "/checkme", your script will first check if "$me" (an identifier which returns the nickname on which the script was activated) is equal to "Jay". If so, it will echo "I am Jay!". If not, it will go to the next "elseif" statement, and check if "$me" is equal to "Karl." If so, it will echo "I am Karl:(", if not it will carry on to the next "else" statement, which will then echo "Who am I?!".

Variables



Variables are temporary storage areas to which you can assign values which you can use later in your scripts.


There are two types of variables: global(dynamic) and local. The difference between them is that a global variable is saved until it is unset, and a local variable is only saved for the duration of the script.

To set a global variable:
/set %var value


To set a local variable:

/var %var value



Once you save a value to a variable, you can call back that variable by using the %var name you assigned to it.

alias myage {  set %age $1}alias sayage {  echo I am %age years old!}



You can also use evaluation brackets ([ ]) when setting a variable. This can be used to assign static variables. For example:

ON *:TEXT:!setage*:#: {  set %age. [ $+ [ $nick ] ] $2}ON *:TEXT:!myage:#: {  msg $nick You are %age. [ $+ [ $nick ] ] years old.}



For more help with variables, type "/help variables" in mIRC.

Remotes



A remote is something that is triggered by an action in IRC. Some examples are "ON TEXT", "ON NICK", and "ON INVITE", all of which I will be showing examples of in this section.

The format for an ON TEXT remote is as follows.
ON <level>:TEXT:<matchtext>:<*><?><#[,#]>:<commands>


  • ON - Signals to mIRC that this line is a trigger. Tip: If you would like to disable a trigger, an easy way to do so is by changing this to "OFF".
  • <level> - This refers to the userlevel (/help /auser) of the person triggering the script. 99% of the time this will be a wildcard, *, indicating any user level.
  • :TEXT: - This tells mIRC what type of trigger it is.
  • <matchtext> - This is where you put the actual trigger of the script (such as !stats* or !commands). A wildcard may be used here. Wildcards (*) can be used to match any amount of characters.
  • :<*><?><#>: - This is where you indicate the location of the trigger. ? refers to in a private message, # means in a channel (you can specify with #Channel, or #Chan1,#Chan2 etc), and * means either.
  • <commands> - this is where you use an opening bracket and then continue on with your script.



An example trigger, which will will trigger on the text "!help" only, and only in a channel.

ON *:TEXT:!help:#: {



Another example, which will trigger on any text which begins with "!stats", and is said in #PureWarfare.

 ON *:TEXT:!stats*:#PureWarfare: {



The format for an ON NICK trigger is as follows.

on <level>:NICK:<commands>


Nothing new is introduced with this trigger, though you should notice there is no location (#?*) parameter, and there is no <textmatch> parameter. This is because a nickname change does not occur in any one specific location, and because there is no text to match.

A typical ON NICK trigger looks like this:
ON *:NICK: {




The format for an ON INVITE trigger looks like this:

on <level>:INVITE:<#[,#]>:<commands>


Notice that this trigger also does not have a textmatch parameter, though it does have a channel paramater. For all channels, use "#", for a specific channel use "#Chan", and for multiple channels use "#Chan1,#Chan2,etc".

An ON INVITE script may look like this:
ON *:INVITE:#PureWarfare: { join $chan }



Aliases



mIRC allows you to create aliases and scripts to speed up your IRC session or to perform repetitive functions more easily. Aliases can be called from the command line, from other aliases, and from popup and remote scripts. An alias cannot call itself recursively mainly because this seems to cause more problems for users than it solves.


There are two types of aliases - identifiers and commands. You can determine how the alias is being used with the identifier "$isid", which will return $true if the alias is being used as an identifier, and false if it is being used as a command.

Identifiers



Identifiers, for the most part, are used to evaluate information and return it. Aliases used as an identifier look like: $alias

An example of an identifier looks like:

alias whatsmyname {  return $me }



Note that "return" is used to return the value of your $alias. Once "return" is used, the alias stops. The above alias could be used in a way such as, "msg $chan Hello my name is $whatsmyname $+ !"

Commands



A command alias is simply used to perform multiple commands at ease with a simple /command.

An exampe of a command alias looks like:

alias whatismyname {echo $me}



The above alias could be used as "/whatismyname".

You could combine both of those like this:

alias whatsmyname {  if ($isid) {	return $me  }  else {	echo I am $me $+ .  }}



Note how the $isid identifier is used to determine the output, and how the brackets are balanced.

Conclusion



I hope everything you have read in this guide has helped you understand the basics of beginning to use the mSL language. Please be aware that this guide covers only a few topics, and vaguely. If you have any questions, post them here and they will be answered. You can use the /help command in mIRC to view the mIRC Help files. Please take a look at my other tutorials for more advanced scripting help!


-Jay

emmawatsonjay.png

34rfuk5.png

(+`Obsession) jay is a legend

Link to comment
Share on other sites

Could you please explain the use of $<text> to me? Out of everything there, it would really be the thing I understand least.

 

I can understand $nick being a users nick and $me being 'my' nick but I don't have any idea where $1, $1 and $+ come from.

 

At first I thought they would be the values assigned to variables (after realising %Var is the variable itself) but that really just confuses me as I would presume the value is %var itself.

 

On another note, what about scripts for setting modes etc. I know that forward slash (/) is rarely needed in them for /mode. Why is this?

 

 

 

Edit: a friend tried to explain it to me, all they did was manage to confused me. "tokenized identifier" :P

Omni is my one. My only.
Link to comment
Share on other sites

Could you please explain the use of $<text> to me? Out of everything there, it would really be the thing I understand least.

 

I can understand $nick being a users nick and $me being 'my' nick but I don't have any idea where $1, $1 and $+ come from.

 

At first I thought they would be the values assigned to variables (after realising %Var is the variable itself) but that really just confuses me as I would presume the value is %var itself.

 

On another note, what about scripts for setting modes etc. I know that forward slash (/) is rarely needed in them for /mode. Why is this?

 

 

 

Edit: a friend tried to explain it to me, all they did was manage to confused me. "tokenized identifier" :P

 

I've added a section called "Tokens", I hope that helps you. If you still don't understand, tell me what's confusing you and I'll go more in-depth.

emmawatsonjay.png

34rfuk5.png

(+`Obsession) jay is a legend

Link to comment
Share on other sites

It was fine, thanks. really just the whole "what are they meant to be" is what gets me. I think of them as variables but then I remind myself there is %var so jump to the conclusion that I am mistaken..

 

My friend basically told me that they're tokenized identifiers and how $$# works also. Which, in my way of putting it, was more or less

If ($1 != $null) {   }else halt

Omni is my one. My only.
Link to comment
Share on other sites

  • 3 weeks later...

Didn't notice this section up until now :lol: Very nice introduction/guide.

 

 

gosh what is this even useful for?

 

Nice guide though

This stuff makes up the bots on IRC (runescript, vectra, babylon, ect..)

I think thats what you're trying to ask.

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...