| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
| The plugin below detects if you are AFK on the client side. That is, if you have wandered away from the keyboard.
The reason for this is that some of the other plugins I have developed - in particular the spellups one - keep casting spells quite frequently, which can make it look to the MUD that you are there in person, and thus the MUD never times you out. However this is confusing for your friends who wonder why you are not responding, as you appear to be standing there, casting spells, not AFK, but not replying to them.
What it does is detect when you last typed a command, and reset an internal timer. If the timer is not reset, it puts you into "client-side AFK" mode. Other plugins can detect that, and stop issuing commands (like spellups) until you return to the keyboard.
To use it, download the code below and save as AFK_Detector.xml in the Aardwolf subdirectory below your Plugins directory. If you haven't used any Aardwolf plugins before you may need to make the Aardwolf directory.
Alternatively, RH click the link below and choose "Save Link As" (or "Save Linked File As") to save the linked file.
http://www.gammon.com.au/mushclient/plugins/Aardwolf/AFK_Detector.xml
In a standard MUSHclient installation these two files should to into this directory:
C:\Program Files\MUSHclient\worlds\plugins\Aardwolf\
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient [
<!ENTITY timer_mins "5" >
<!ENTITY timer_secs "0" >
]>
<!-- Saved on Saturday, June 30, 2007, 10:48 -->
<!-- MuClient version 4.13 -->
<muclient>
<plugin
name="xAFK_Detector"
author="Nick Gammon"
id="0e191dc7829ff2ac2433c2d8"
language="Lua"
purpose="Detects if you are AFK"
date_written="2008-06-24"
requires="4.28"
version="1.0"
>
<description trim="y">
[FOR PLUGIN AUTHORS ONLY]
Detects if you are AFK, for the benefit of other plugins.
Example:
function OnPluginBroadcast (msg, id, name, text)
if msg == 1 and id == "0e191dc7829ff2ac2433c2d8" then
AFK = text == "y"
end -- AFK status changed
end
</description>
</plugin>
<triggers>
<trigger
enabled="y"
match="You are now in AFK mode."
script="gone_afk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You cannot use that command while AFK."
script="gone_afk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="^AFK mode removed\."
script="not_afk"
regexp="y"
sequence="100"
>
</trigger>
</triggers>
<timers>
<timer name="afk_timer"
second="&timer_secs;"
minute="&timer_mins;"
send_to="12"
enabled="y"
>
<send>
ColourNote ("salmon", "", "You are now AFK (client-side).")
SetStatus ("AFK")
check (EnableTimer ("afk_timer", 0))
BroadcastPlugin (1, "y")
</send>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
function gone_afk (name, line, wildcards)
SetStatus ("AFK")
check (EnableTimer ("afk_timer", 0))
BroadcastPlugin (1, "y")
end -- gone_afk
function not_afk (name, line, wildcards)
FixTimer ()
end -- not_afk
-- 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 (client-side).")
SetStatus ("Ready")
BroadcastPlugin (1, "n")
end
-- turn timer back on
check (EnableTimer ("afk_timer", 1))
-- make sure the full time interval elapses
check (ResetTimer ("afk_timer"))
end
assert (GetOption ("enable_timers") == 1, "Timers not enabled")
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|