
The mIRC Token Commands
By DocSavag
The $token commands, added in mIRC 4.5 and enhanced in mIRC 4.7 , are some of the most powerful features of the new mIRC scripting language. They are also probably the most unused and misunderstood features. For some reason I took to these identifiers very quickly and use them often, sometimes drawing strange looks from my fellow #mIRC ops. In this short tutorial I will attempt to explain them in simple terms. Hopefully this will be use full to some of you.
[Warning Most of these commands and examples are specific for mIRC 5.0 if you have 4.6 or or earlier this stuff just won't work for you. Upgrade if you want to use them.]
The commands:
Ok. About now you are saying to yourself "Hey!?! This is in the help file! What do I need you for?" And you would be right. :) But let's take a look at some explanation of the terms we are looking at and see if it becomes more clear.
Terms:
String: any text. (Examples: {my dog has fleas} {14,100,=12} { 123.421.04.123. } )
Token: a specific element or piece of a string. (Examples: { dog } { 100 } { 123 } )
Delimiter: any character (expressed in it's ASCII code number) that can be used to find a token in a given string. Examples: ( { [space] } { , } { . } ) the examples would be expressed as 32 (space) 44 (comma) and 46 (period)
OK.. So taking one of the examples I used earlier:
String: my dog has fleas Delimiter: 32 (space)
Ok.. Say you want to get the 3 word in this sentence. You would use:
$gettok(my dog has fleas,3,32)
This takes "my dog has fleas" looks at each piece of it that is separated a [space] and returns to you the 3rd one. Or "has"
Now, before we go any further I must tell you that because Mirc uses , as the separator for the parts of the token commands it doesn't take kindly to you putting them in the string parameter. To use a , as a separator in your string you have to use a variable so mIRC doesn't get confused.
So.. next example.
String: 14,100,=12
set %string 14,100,-12 $gettok(%string,3,44) You get -12 echo'd to your status.
Let's say we wanted to change something about our string:
string: my dog has fleas
set %string my dog has fleas $instok(%string,no,4,32) Your echo would be My dog has no fleas
We used $instok to insert the word no before the word fleas.
Up to now we have been using just some basic strings to get used to the way that the token commands work. In the real world of mIRC scripting none of these examples are very useful because they require you to know exactly what is in the string.
Some Applications: The most common application for gettok in my usage is
$snicks. I use snicks for various things. And token commands allow me to manipulate the $snicks in various ways.
$snicks: coasty,DocSavag,Kimmy,Kirk`Vtec,No_one,johno set %snicks $snicks
The First thing we might want to know about this list is .. how many of them are there? $gettok has the added job of returning the number of total tokens in a string if you specify 0 as the position of the token you want.
$gettok(%snicks,0,44) tells us that there are in fact 6 names in our list
Ok..I really don't want to send stuff to myself (most of the time) so lets see what we can do about removing me from it.
$findtok(%snicks,$me,44) alerts me that I am token 2 in the list. If I wasn't in the list the value of $findtok(%snicks,$me,44) would be $null. This is very useful for searching a list for a certain token.
$remtok(%snicks,$me,44) shows the list without me in it at all (coasty,Kimmy,Kirk`Vtec,No_one,johno )
Oops.. Hey, I forgot Dancr in this snicks list earlier..but hey it isn't too late to put her in somewhere:
$reptok(%snicks,$me,Dancr,44) would replace my nick with that of Dancr (coasty,Dancr,Kimmy,Kirk`Vtec,No_one,johno )
$addtok(%snicks,Dancr,44) (coasty,DocSavag,Kimmy,Kirk`Vtec,No_one,johno,Dancr) would add Dancr at the end. Earlier we showed the method for inserting an element.
So much for simple token tasks. Below is a sample part of my script. It is designed to scan incoming text for certain words and react to those words. For the faint of heart I am using some comical replacements for the actual words I scan for in my text. :)
%badwords ducklover plumber bricklayer
ON +1:TEXT:*:#: {
if %pottymouth != OFF {
set %x 1
:scan
if $gettok(%badwords,%x,32) isin $strip($1-) && $gettok(%badwords,%x,32) != $null {
ban -u30 $chan $nick 3
kick $nick Expand Your Vocabulary
echo 12 -a [Kicking $nick for Badword $token(%x,32,%badwords) $+ ]
halt
}
inc %x
if $gettok(%badwords,%x,32) != $null {
goto scan
}
unset %x
}
}
This takes each token in the variable %badwords and looks to see if that word is in the incoming text from the user. If so it kicks. If not it cycles through the tokens until it gets a $null token. ( the end of the tokens )
I hope this has provided some insight into the way tokens work in mIRC and I would appreciate any feedback on this that you have.