This subject is always incredibly popular on the scripting channels, so this tutorial will go through the basic premises of how to make an away system. A lot of the documentation is in the comments for the code, so that you can learn what everything does, line by line. NOTE: The "" character you see throughout the tutorial is mIRC's bold (CTRL+B) character.Different Options
What is an Away System?
It's really just a way to let other people on IRC know that you are away from your keyboard (AFK)
mIRC as standard does have an away of its own:
/away <reason>
and to set back, just type /away again.
However, this is fairly mundane, and apart from setting you away on the server, doesn't really include any other goodies.
People tend to use a variety of methods. Popups, keyboard shortcuts, @windows, and of course dialogs to achieve the results they want. Some look good, some are rather colourful and complex, it's always good to bear in mind that not everyone will appreciate bright green text on a yellow background or other lurid colour combinations, so reasonable care should be taken to ensure the colour scheme is acceptable to people or you could find yourself being kicked rather a lot. Also, the repeating duration of the time spent away, should be sensible too, many ChanOps won't appreciate seeing things like this:
[11:51p] * Nuroticat is away -[ auto-away after 15 minutes idle ]- at 03:45p -[ P:Off / L:Off ]-
[11:52p] * Nuroticat is away -[ auto-away after 15 minutes idle ]- at 03:45p -[ P:Off / L:Off ]-
[11:53p] * Nuroticat is away -[ auto-away after 15 minutes idle ]- at 03:45p -[ P:Off / L:Off ]-
Common options for away systems include features like:The Basics
- ctcp paging
- message logging
- autoaway
- time set away
- duration of away
Some knowledge of basic scripting is neccessary to achieve this. You will need to understand aliases, timers, and remotes.More Advanced Functions
Ok, so how do I make one?
Example simple away system: (to add to your remotes)menu menubar { ;this tells mIRC where to place the popups away system .set away: setaway .set back: setback ; these activate the commands (note, by using an alias it offers more flexibility, as you can ; either use the popups, or a keyboard command) usage /setaway, and /setback } alias setaway { if ($1 == $null) set %away.reason $$?="Enter Reason" else set %away.reason $1- ;this pops up an input box to add your away reason ;unless you specified one, then it uses $1- away ( $+ %away.reason $+ ) ;this sets you away with your reason set %away.time $ctime ;this sets your away time, used to calculate how long you were away ame Away : [ $+ %away.reason $+ ] ;this tells all the channels you are on, that you are away, and the reason set .timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] ;this lets you choose the duration of repeating that you are away } alias setback { if ($away == $false) { echo -at ** You Aren't Away! | halt } ;this is basic error checking, if you aren't away it stops you from setting back .timer(away) off ;this turns the timer off ame Back : [ $+ %away.reason $+ ] Gone : [ $duration($calc($ctime - %away.time)) ] Did Ya Miss ME ? ;this tells your channels how long you were away for, i.e. gone for 1min 15secs away ;this sets you back, so you are no longer marked as away on the server unset %away.* ;and this removes your variables, just to make sure everything is kept tidy }
Silent AwayAutoaway (Extra)
If we build on the frame of the above example, we could include silent away/backmenu menubar { away system .set away: setaway .set back: setback .- .silent away: quietaway .silent back: quietback } alias quietaway { set %away.reason $$?="Enter Reason" away ( $+ %away.reason $+ ) } alias quietback { if ($away == $false) { echo -at ** You Aren't Away! | halt } away unset %away.* }This simply marks you away to the server (with a reason) and then marks you back, but silently, with no announcement
Time Set Away
This informs users on your channels of the time that your away was set.
We add this to the remote filealias rtime return $time(h:nntt)and replace this:.timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ]to this:.timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] $rtimeNow, whenever your repeat is shown, it will also display the time set away
[17:00] * Lisa^B Away : [ Bathtime.. No peeking :P ]
[17:25] * Lisa^B still Away : [ Bathtime.. No peeking :P ] since 5:00pm
[17:30] * Lisa^B Back : [ Bathtime.. No peeking :P ] Gone : [ 30mins 20secs ] Did Ya Miss ME ?
Paging
If we wished to add a page function, we could change the setaway alias to this:alias setaway { if ($1 == $null) set %away.reason $$?="Enter Reason" else set %away.reason $1- away ( $+ %away.reason $+ ) set %away.time $ctime if (%options.pager) { ame Away : [ $+ %away.reason $+ ] PAGE: /ctcp $me page << Your Msg >> .timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] PAGE: /ctcp $me page << Your Msg >> ;this means if pager is on, send this message } else { ame Away : [ $+ %away.reason $+ ] .timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] ;this means if the pager is Off, send this message } }Of course, if you wished to respond to the /ctcp $me page, then we need to add some additional code. First make a .txt file and rename it to page.txt, place this in the same directory as this remote file.ctcp *:page:*: { if (%options.pager) .notice $nick > Hello. Since you paged me, I'm probably busy or away for a while. I'll get back to you as soon as I can. ;this captures the page, (if the pager is On) and notices the user (silently) that you have seen the page echo -at ** [ You have been PAGED by $nick ] $address on $fulldate ;alerts you to the page sent to you write $scriptdir\page.txt paged by : $nick $address $fulldate MSG : $2- ;writes the page contents to a .txt file for future viewing }In your popups there are now two new sectionsmenu menubar { away system .set away: setaway .set back: setback .- .pager is ( $+ $iif(%options.pager, On, Off) $+ ) : { ;this is a dynamic On/Off for the pager if (%options.pager) echo -a ** Pager Now DISABLED else echo -a ** Pager Now ACTIVE ;informs the user if active or not %options.pager = $iif(%options.pager, 0, 1) } .silent away: quietaway .silent back: quietback .- .read pages: run NotePad.exe $scriptdir\page.txt ;this opens up notepad to allow you to view your page.txt .clear pages: { write -c $scriptdir\page.txt clearing all pages on $fulldate ;this erases any text in the file echo -at ** Page file now cleared ;this informs you that the text has been cleared } }
This feature automatically sets you away after a certain period of time (user specified)Summary
I.E. If you were idle for more than 30 minutes
Lets look at the code:on *:connect: .timer(autoaway) 0 30 autoaway.checkThis line, which goes in your remote section, will check every 30 seconds to see if you have been idle for more than the allowed time, and if you are, it will set you away.alias autoaway.check { if ($idle > %options.aatime) { ; set the user away setaway autoaway after $duration(%options.aatime) ; turn off the away check, since we are setting away .timer(autoaway) off } }This alias checks to see how long you have been idle (by checking the identifier $idle), and if you have been idle longer than the value in %options.aatime, it will set you away. It also stops the autoaway check timer, since you are away.
To use this in your script, you would need to make additions to your /setaway and /setback aliases. In your /setaway, you would add ".timer(autoaway) off", since you are setting away, you don't want the autoaway triggering. In your /setback, you would put ".timer(autoaway) 0 30 autoaway.check" to reenable the autoaway check. In your /setback, you will also need a "resetidle", to make sure the user's idle time is reset once he/she is set back.
You will also need to add the appropriate popup menus, to let the user set the autoaway time (%options.aatime).
We will leave you to experiment further on the autoaway, as it is really beyond the scope of this beginner's tutorial.
As you can see, an away system can be very flexible, the examples used here are only basic, but are intended to give you a taste of what can be achieved.
Hopefully, this will answer most questions you may have, and start you off, into making your own away system.
Exercise to try: Make the autoaway functional with the given code for it.
Here is the full source code (autoaway NOT included):menu menubar { away system .set away: setaway .set back: setback .- .pager is ( $+ $iif(%options.pager, On, Off) $+ ) : { if (%options.pager) echo -a ** Pager Now DISABLED else echo -a ** Pager Now ACTIVE %options.pager = $iif(%options.pager, 0, 1) } .silent away: quietaway .silent back: quietback .- .read pages: run NotePad.exe $scriptdir\page.txt .clear pages: { write -c $scriptdir\page.txt clearing all pages on $fulldate echo -at ** Page file now cleared } } alias setaway { if ($1 == $null) set %away.reason $$?="Enter Reason" else set %away.reason $1- away ( $+ %away.reason $+ ) set %away.time $ctime if (%options.pager) { ame Away : [ $+ %away.reason $+ ] PAGE: /ctcp $me page << Your Msg >> .timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] PAGE: /ctcp $me page << Your Msg >> } else { ame Away : [ $+ %away.reason $+ ] .timer(away) 0 $?="time in secs ?" ame still Away : [ $+ %away.reason $+ ] } } alias setback { if ($away == $false) { echo -at ** You Aren't Away! | halt } .timer(away) off ame Back : [ $+ %away.reason $+ ] Gone : [ $duration($calc($ctime - %away.time)) ] Did Ya Miss ME ? away unset %away.* } alias quietaway { set %away.reason $$?="Enter Reason" away ( $+ %away.reason $+ ) } alias quietback { if ($away == $false) { echo -at ** You Aren't Away! | halt } away unset %away.* } ctcp *:page:*: { if (%options.pager) .notice $nick > Hello. Since you paged me, I'm probably busy or away for a while. I'll get back to you as soon as I can. echo -at ** [ You have been PAGED by $nick ] $address on $fulldate write $scriptdir\page.txt paged by : $nick $address $fulldate MSG : $2- } alias rtime return $time(h:nntt)