MIRC Scripting/BeyondBasics/Timers

Chapter 4: Timers 75% developed  as of 14:23, 31 March 2008 (UTC)




Timers are basically delays, that fire a command after a specified time. You can use them for all sort of things, from setting a command that should be run each minute, to a 1 second delay to wait for another action to finish first.

The syntax is /timer[N/name] [-cdeomhipr] [time] <repetitions> <interval> <command> This may look confusing, but we'll look at it step by step.


First, the OPTIONAL [N/name] part. You can identify your timer with this (in order to turn it off later, for example), or you can leave it empty, in which case mIRC will automatically assign the lowest unused N to it.

Example:
/timerBAN ......
/timer1 .......
/timer ....


Now, the OPTIONAL [-cdeomhipr] part. These are options, which we'll go by one by one.

-c: This will make mIRC try to "catch up" a timer, by executing it more than once per interval if needed. EG, if your mIRC lags, and one of the executes is skipped, it will execute it twice instead of just skipping one.
-d: This ensures that this timer and the ones started after it will run in the order they started.
-e: This executes the command associated with the specified timer name, also works if you specify a wildcard name.
-o: This will create a offline timer, which will run whether you're connected to a server or not. Timers are online by default, unless you start them when you're not connected to a server, in which case they're offline by default.
-m -h: This will create a interval delay in milliseconds, instead of the default seconds -h specifies a high-resolution multimedia timer, which will heavily use system resources, and thus should only be used in time critical situations.
-i: This will make the timer dynamically associate with whatever happens to be the active connection. If a server window is closed, the timer is associated with the next available server window.
-p -r: This will pause/resume a timer.


Now, for the OPTIONAL [time] part. This will specify the time the timer should be started, e.g. "/timer 15:00 ...." will start at 3pm


Now we're getting to the main parts of the timers, first the <repetitions>. This will set how many times the timer has to be run before it is ended, e.g. "/timer 5 ...." is ran 5 times, and after that it gets deleted. If you specify 0, it will repeat itself until you stop it.


The main part of them timer, <interval>. This specifies how much the timer should be delayed, in seconds (unless you use the -h or -m switch).
e.g.
timer 1 10 .... will run after 10 seconds.
/timer 5 10 .... will run after 10 seconds, and repeat itself 5 times (it will run at 10, 20, 30, 40 and 50 seconds after starting it)


And now the last part, the <command>. This is the command to be executed each time a timer is run, the function you want it to perform. Please note that any identifier is only evaluated when STARTING the timer, so if the value it returns would change the timer would NOT change. To force a identifier to be evaluated each time the timer is run, use $!
Example
/timer 5 600 /echo -a $me will return the same nickname each time, regardless of what your nick is at the moment.
/timer 5 600 /echo -a $!me would return your current nick.


Examples:
/ban $nick
/timer 1 10 /unban $nick
This will ban someone, and then unban him/her after 10 seconds.

/timer 0 600 /msg $chan This is the auto-announce of $chan - Please enjoy your stay on $chan
This will start a timer which will continue till you stop it, and which will send the message "This is the auto-announce of <chan> - Please enjoy your stay on <chan>" to the $chan each 10 minutes.


Now, there are some miscellaneous commands.
/timers This will list all timers.
/timer[N/name] off This turns a timer off
$ltimer This will return the number of the timer that was just started.

Example:
/timer1 1 2 /echo Hello World!!!!
/timer2 1 2 /echo Hello World!!!!
/timer 1 2 /echo Hello World!!!!
$ltimer > will return 3

/timerwho 0 600 /who $chan
$ltimer > will return who