
Custom Identifiers By CoolMaster


What Is a custom identifier? 
Well a custom identifier is an alias that return somethig, they can be edited on
aliase section or remote section (using alias prefix). Here i use the alias prefix
if you want to put some of the custom identifers on aliase section please remote
alias prefix. To read an identifier on editbox you need to put // example //echo -a $me
The return command must be used for return something.

Some explanation about return.
When you leave return alone, you only be stop that event, alias or other and if some script
is depending that alias, the scripts go on. Is like an halt for that event, the diference
is that the halt stop all. 
If you specify something after return this will return what you spectify.


The basic of custom identifiers is:

alias g return *g*

So $g return *g* when you do this //echo $g you will print to screen *g*
Easy? I guess. 

Now for example:

alias mynick if ($me == CoolMaster) { return You're da man } | else { return You're just you: $me }

$mynick if your nick is CoolMaster return 'You're da man' else return 'You're just you: yournick'

Try something diferent before go in doc.


Now we want and identifier that returns the some of 2 numbers.

alias some return $calc($1 + $2)

When you do $some(5,1) you will get 6.


One of the most used and apreciated custom identifiers is the one that return the percentage of
something

alias percent return $calc(($1 / $2) * 100)

Just put $percent(2,30) and return 6,67
Let's complicate a bit :P

alias percent return $round($calc(($1 / $2) * 100),$iif($3,$3,2))

This alias is like the first but! You can round for what you want. So the usage is
$percent(number,total,N) when the N is optional if you Use N will be a percentage rounded
to N else to 2.
$percent(2,30,1) return 6.7


Making a custom identifier that returns the comchans for a nick.

Some explanation: $comchan(nick,0) returns the number of comchans to a nick,
$comchan(nick,1) the first, $comchan(nick,2) the second...
All we have to do is using a loop.

alias comchans {
if ($comchan($1,0) > 0) {
;the following code is only triggered when the nick have one or more comchans
var %x = 1, %comchan
;here set a local variable with value 1, and %comchan without any value
while (%x <= $comchan($1,0)) {
;this will loop until the %x is equal or more that total number of comchan
set %comchan %comchan $comchan($1,%x)
;this set the variable %comchan with is value and one more channel.
inc %x
;this increment the %x
}
return $sorttok(%comchan,32)
;this return the variable %comchan that contain all of comchans for that nick
;the $sorttok make comchans sorted. /help token identifiers
}
else {
return $null
;if the first condition is false return $null
}
}
;the usage is $comchans(nick)

Now you understand the power of this custom identifiers? :]


If you understand lets go on to $prop identifier!
The $prop identifier in a few words is the properties of an identifier can 'suport'.

The next code will return the number of op, voices on a channel. We use prop
to switch to op, voice. If no prop as specified will return the total of users.

alias usersc {
if ($prop == op) { return $opnick($1,0) }
elseif ($prop == voice) { return $vnick($1,0) }
else { return $nick($1,0) }
}

Usage: $usersc(#script3rs).op Will return the number of ops. $userc(#script3rs).voice
will return the number of voices. and $usersc(#script3rs) will return the total of
ppl.


Conclusion:
Custom identifiers is a good and in some cases powerfull tool for scripters.
I make this because some newbie ppl on scripting never use custom identifiers and
complicate to much. When using a useful custom identifier the code will be more 
cleared, more fast to find bugs and more professional.
Well I want apollogies for my english :) I know it sucks.
Be cool :]



				CoolMaster <coolmaster@aeiou.pt>
				http://coolmaster.org
  				Copyright coolmaster 2001
