In the Remote Events section I used an
auto-whois script to perform a /whois
command whenever someone
joins a channel. Another (sometimes) popular thing to do when people join a
channel is to get mIRC to greet them. As a lot of people don't like this, I'm
going to use this as an example of how you can switch on and off certain
parts of your scripts on the fly.
The auto greet is set up in exactly the same way as the auto-whois. It goes in the Remote section of the mIRC editor (which is what you've been using to enter aliases, popups and remote events). The code is:
on 1:JOIN:#:msg $chan Hello $nick - how's it going?
In this event I'm sending a message to the current channel as opposed to
using a /say
command. This is because most remote events need
you to specify the destination of the message, in this case,
$chan
. Of course you can put anything you like after the
msg $chan
, it's entirely up to you. In order to turn this off
and on (without having to edit the script and change the 'on' to 'off'), we
have to set it up in a group.
#autogreet on
on 1:JOIN:#:msg $chan Hello $nick - how's it going?
#autogreet end
This defines a group called autogreet (you can call it anything you like) and
it is initially on (use #autogreet off to set it initially off). To change
the setting while chatting use the /enable and /disable commands. Typing
/enable #autogreet
makes sure it is turned on, and
/disable #autogreet
makes sure it is turned off.
Now, as I'm sure you're aware by now, it is not easy to remember all these
commands. It is far easier to put them in a popup menu, and one of the popup
menus we can customise in mIRC is on the menubar - it's the 'commands' menu.
In the popups section of the mIRC editor,
select view | menubar and enter at the bottom:
-
Autogreet
.On: /enable #autogreet
.Off: /disable #autogreet
Now this will work, but it isn't very tidy. I personally don't like having
the sub-menu with just on/off settings. If you have a lot of settings you
want to switch on and off it can take you ages because of all the submenus. A
better way would be to use the $group
identifier which will tell
us the status of a specified group. Change the menu definition to read:
-
Change Autogreet: { if ($group(#autogreet) == on)
{ disable #autogreet }
else
{ enable #autogreet }
}
Now the menu prompts us to toggle the state of autogreet, but we still don't know what the current status is. There's a little trick we can use to get round this. The menus don't have to be fixed text - they can be variables too!
Open the mIRC Editor and click on the
variables tab. Define a variable as follows:
%automenu Turn off Autogreet
This is the initial, default, setting. As it is telling us to turn autogreet off, it shouldn't be too much of a mental step (I hope!) to realise that Autogreet is currently on.
Change the menu definition (for the last time) to read:
-
%automenu: { if ($group(#autogreet) == on) { .disable #autogreet | %automenu = Turn on autogreet }
else { .enable #autogreet | %automenu = Turn off autogreet }
}
And that's it! When autogreet is on, the menu option will say "Turn off autogreet" and when it is off, it will say "Turn on Autogreet". The dots before the enable and disable commands prevent mIRC echoing the result of the command to the window. Try the menu with the dots and without them to see the difference.
Note that if you have more than one remote event triggered at the same time then a slightly different technique has to be employed - the remote section of the script looks like this:
#autogreet on #autogreet end #autowhois on #autowhois end on 1:JOIN:#: { if ($group(#autowhois) == on) { whois $nick } if ($group(#autogreet) == on) { msg $chan Welcome $nick! } }
and of course you'd have another menu option to turn the auto-whois on and off. It will work in exactly the same way as the autogreet one, you just have to copy it and change 'autogreet' to read 'autowhois'. Note that we only have one on join event and it triggers different things depending on which groups are turned on or off.
To test all this you'll have to go on-line and join a channel. See if your mIRC autogreets people when you have the option turned on and doesn't autogreet people when you have the option turned off. You may have to wait a while to test this properly, as it depends on other people joining the channel, so pick a busy one!
Of course there are many different ways of achieving this - you may prefer
the on/off submenu, you may prefer to type the /enable
and
/disable
commands, but what I'm trying to do here is take ideas
you're familiar with and show you a practical example of how to use them.
Defining your own menus to turn on and off aspects of your scripts gives you
the power to customise mIRC while you're using it. You may be able to get
away with an autogreet in one channel, but you may get severely shouted at
for using it in another channel. The ability to turn it off with a simple
menu command is a heck of a lot more convenient than editing your scripts
while you're trying to chat.
New Techniques introduced in this section - see mIRC help file for more
information
Groups
- used to selectively process lines of code
/enable
- turns a group on
/disable
- turns a group off
mIRC comes with a /window
command that you can use to create
and manipulate your own windows. We're going to use it to create a window
that will show us the status of all the switches in our script. The window is
created in an alias as follows:
makestatwindow {
window +bts @switches /font courier new
if ( $group(#autowhois) == on ) { aline @switches on : whois on join }
else { aline @switches off: whois on join }
if ( $group(#autogreet) == on ) { aline @switches on : autogreet }
else { aline @switches off: autogreet }
if ( $group(#autospell) == on ) { aline @switches on : autospell }
else { aline @switches off: autospell }
if ( $group(#colournicks) == on ) { aline @switches on : nickname colouring }
else { aline @switches off: nickname colouring }
echo @switches Current IP Address is $ip
}
The first line creates a sizeable window with a border and a title bar. This window doesn't have maximise and minimise buttons, because, well, it's my window and I don't think it needs them. The window is called @switches and I've decided that the best font for this window is courier new. This is because the text in the window will look like this:
on : whois on join off: autogreet off: autospell on : nickname colouring
and if we use a fixed width font then all the colons will line up nicely. The last line tells me my current IP address. I'm allocated a different IP address each time I log on, and knowing the current one could be useful for cu-seeme, file serves or whatever.
I want this window to be created when I start mIRC, so I need to add another event to the remotes window:
on 1:START:{ makestatwindow }
I also need the contents of the window to be updated whenever I change a switch using the custom menu. To do this we need to change the menu definitions (again!) to look like this:
%whoismenu: { if ($group(#autowhois) == on) { .disable #autowhois | %whoismenu = Turn on autowhois ; check that switches window exists, if not recreate it. if ($window(@switches).state == $null) { makestatwindow } ; if it already exists change the message for the whois event else { rline @switches 1 off: whois on join } } else { .enable #autowhois | %whoismenu = Turn off autowhois if ($window(@switches).state == $null) { makestatwindow } else { rline @switches 1 on : whois on join } } }
The first line is as it was previously - if the #autowhois
group is enabled, then disable it and change the text for the menu. Then one
of the new bits of code comes up. We check the status of the
@switches
window. Remember that although the window doesn't have
a maximise or a minimise box, it does have a close box, and the user could
have closed it. If the status of the window is $null
it means
the window doesn't exist and we simply call our makestatwindow
alias to create it again. When the window is recreated it will show the
current status of the switches. If the window already existed, however, we
need to replace line 1 in the window with the text off: whois on
join
.
The second half is the same as the first except that it is executed when we want to turn the option on again.
New Techniques introduced in this section - see mIRC help file for
more information
aline
- adds a line to a list in a custom window
rline x
- replaces line x in the list with different text
on START event
- event that is triggered when mIRC is started.
$window
- tells us information about a specific window