Programming Events

Lets take the simple 'on start' event, and make it do something basic. If savIRC is open press Alt+E and type.

on start * {
    echo Hello $me(nick)!
}
		

Now save it, and close the Script Center, and savIRC. Reopen it and you should see something like this:

Hello [SQ]werl!
		

Now, I can hear some of you out there saying “Duh, I already knew that!”. Well ok, lets move onto something more interesting. Lets say that we want to send a message to everyone who joins the channel #savIRC. And we do not want to send it to ourselves, so we would do something like this.

On join * {
   # - When working with channel names you must include the prefix
   # - Notice that we did not need to bring the variable $me(nick) into scope
   if {$chan == "#savIRC"} {

	# - This will send a message to anyone who does not have the
	# - nick in the $me(nick) variable.

	if {$nick != $me(nick) } {
		msg $nick welcome to savIRC!
		}
	}
}
		

Tip

If you have problems, echo the variable to see what it contains. Most of the time, when your code does not work the variable contains information that is incorrect.

Notice that whenever you want to be channel specific you must use either an 'if' statement, or a 'switch' statement. Let's say that we now want to voice everyone in #savIRC and welcome everyone to the #savIRC_newbies channel.

On join * {
	  #available vars:  $id $nick $user $host $chan

	set chan_lower [string tolower $chan]
	# - We aren't sure if the user will join the channel with weird combinations
	# - of uppercase, and lowercase, or whatever, so we make it all lowercase
	# - for easier handling.

	 if {$nick != $me(nick)} {
	 # - We don't want to msg our voice ourselves.

		switch -glob $chan {
		# - we add in the ? Marks instead of the # marks because if we
		# - don't tcl will consider it a comment. ? Stands for a single
		# - character wild card, when using the -glob option.
		?savirc { mode +v $nick }
		?savirc_newbies { msg $nick Welcome to savIRC_newbies!}
		}
	}
}
		

This will voice everyone who joins the channel #savirc, and will message everyone a welcome message, to everyone who joins the channel #savirc_newbies. This is designed to help you get started working with savIRC events.

Lets say that we are on two networks most of the time, so we need to be network specific. On Undernet we want to message everyone when they part. But on Dalnet we don't want to do anything when a user parts.

on part  Undernet {
 	 #available vars:  $id $nick $user $host $chan
	if {$nick != $me(nick)} {
		msg $nick Come back to $chan soon!
		}
}