Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Message
| This plugin, written in Lua, tries to handle going AFK automatically, in case your MUD doesn't do it for you.
What it does is set up a timer, defaulting to 5 minutes, and when the timer fires, sends "afk" to the MUD. Whenever you type something, which is caught by OnPluginCommand, the timer is reset, to make the 5 minute timer start again.
A bit of testing revealed that the first version was a bit fiddly to get right, as it was possible for the MUD, and the plugin, to be out of step. This was because SMAUG uses "afk" to turn AFK on, and "afk" again to turn it back off.
To work around this the plugin detects the string "You are now afk." to resynchronise its timer.
To customise, change the first few lines directly below to be the AFK command, the number of minutes and seconds you want to wait before being AFK, and the exact message the MUD sends when you go AFK and back again.
The plugin does a Note in salmon colour to notify you when it thinks you are AFK, and not AFK, so you can see when it is working.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient [
<!ENTITY afk_command "afk" >
<!ENTITY timer_mins "5" >
<!ENTITY timer_secs "0" >
<!ENTITY afk_message "You are now afk." >
<!ENTITY not_afk_message "You are no longer afk." >
]>
<!--
Customising (change above entities) ...
Change "afk_command" to whatever sets you AFK.
Default: afk
Change "timer_mins" to be the number of minutes before you are AFK.
Default: 5 minutes
Change "timer_secs" to be the number of seconds before you are AFK.
Default: 0 seconds
In other words, to be AFK after 2.5 minutes, timer_mins would be 2, and
timer_secs would be 30.
-->
<!-- Saved on Saturday, October 08, 2005, 10:37 AM -->
<!-- MuClient version 3.66 -->
<!-- Plugin "AFK_timer" generated by Plugin Wizard -->
<muclient>
<plugin
name="AFK_timer"
author="Nick Gammon"
id="4d167d47cac26fb36e161e48"
language="Lua"
purpose="Sends AFK to the MUD when 5 minutes elapse"
date_written="2005-10-08 10:32:50"
requires="3.52"
version="1.0"
>
<description trim="y">
<![CDATA[
After the specified interval (default 5 minutes) elapse, sends "afk" to the MUD.
]]>
</description>
</plugin>
<!-- Timers -->
<timers>
<timer name="afk_timer"
second="&timer_secs;"
minute="&timer_mins;"
send_to="12"
enabled="y"
>
<send>
ColourNote ("salmon", "", "You are now AFK.")
Send ("&afk_command;")
EnableTimer ("afk_timer", 0)
</send>
</timer>
</timers>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="¬_afk_message;"
send_to="12"
>
<send>
FixTimer () -- make sure timer is back on
</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="&afk_message;"
send_to="12"
>
<send>
EnableTimer ("afk_timer", 0) -- make sure timer is off
</send>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
-- when they type something, reset AFK status
function OnPluginCommand (sText)
FixTimer ()
return true -- process the command
end
-- when you connect to the MUD, presumably you are not AFK
function OnPluginConnect ()
FixTimer ()
end
-- shared routine to handle turning AFK off
function FixTimer ()
if GetTimerOption ("afk_timer", "enabled") == 0 then
ColourNote ("salmon", "", "You are no longer AFK.")
end
-- turn timer back on
EnableTimer ("afk_timer", 1)
-- make sure the full time interval elapses
ResetTimer ("afk_timer")
end
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|