mIRC -> Tutorials -> 02

Having mastered the basics of On Text events I figured we could do something useful for a change, and still keep it simple so...a little thing to remind people that we're away when they mention our nick might be a good idea. I know most scripts already have this but it's still nice to know how to make your own should you want to.

Here's a basic template for what we want our script to do:

     
on *:text:ournick:#:{
  notice $nick hi $nick -- I'm away right now, try later!
}
     
    
As you can see right away this will never work, "ournick" isnt a really good thing to have mIRC identify people mentioning us. We have to use another little trick to find out if our nick is mentioned...

     
on *:text:*:#:{
  if ($me isin $1-) {
    notice $nick hi $nick -- I'm away right now, try later!
  }
}
     
    
Now I stuck a little more into our event, a IF command and some weird $me and $1- identifiers. Lemme explain what I just did; we have to see if our nick occurs anywhere in what someone just said on a channel, this is what the IF function is for - it performs a check whether $me (use the helpfile and you will learn that $me returns your current nickname), our nick, is found anywhere in $1- (this is what the nick said, beginning with the first word -- if you'd want to get everything he said from the third word you'd use $3- instead), and if it is the code within the two { } is executed.

Now we have a working script that checks for people speaking about us and tells them that we're away...wait a minute! What if we're not away, then it would still be telling people that we are, that's no good. We need to make sure it only triggers if we've set ourselves away, perhaps with another IF function...?

     
on *:text:*:#:{
  if (($me isin $1-) && ($away == $true)) {
    notice $nick hi $nick -- I'm away right now, try later!
  }
}
     
    
This is much better, the $away will return $true or $false depending on our away status and in this case the code will only be executed if BOTH ($me isin $1-) and ($away == $true) match. If either of the two are "broken" nothing happens.

Now we're almost done, except for one little detail...

     
on *:text:*:#:{
  if (($me isin $1-) && ($away == $true) && (%awayflood == $null)) {
    set -u60 %awayflood 1
    notice $nick hi $nick -- I'm away right now, try later!
  }
}
     
    
It's never a good idea to let people flood you off the server, so a protection from floods is a important part of the code for any good scripter. If you think the set command and the %awayflood thing looks weird you can read the fourth tutorial for an explanation of variables. It simply sets %awayflood to 1 for 60 seconds and also looks at %awayflood each time to make sure it's $null (zero, empty, null, nothing) meaning if it has been set to 1 the script will not send notices for the next minute until %awayflood is unset again. Use the helpfile and look at /set and $null :)

If you had any problems following the steps read everything again and look carefully at the code, it's not as hard as it seems...


<< Previous | Next >>