Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Aardwolf AFK detection plugin

Aardwolf AFK detection plugin

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Sat 12 Jul 2008 11:34 PM (UTC)
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

Posted by Solaris   (1 post)  Bio
Date Reply #1 on Tue 22 Jul 2008 09:19 AM (UTC)
Message
I have a problem when i add this script:

Run-time error
Plugin: xAFK_Detector (called from world: aardwolf)
Function/Sub: OnPluginCommand called by Plugin xAFK_Detector
Reason: Executing plugin xAFK_Detector sub OnPluginCommand
[string "Plugin"]:34: attempt to call global 'check' (a nil value)
stack traceback:
[string "Plugin"]:34: in function 'FixTimer'
[string "Plugin"]:14: in function <[string "Plugin"]:13>
Error context in script:
30 : BroadcastPlugin (1, "n")
31 : end
32 :
33 : -- turn timer back on
34*: check (EnableTimer ("afk_timer", 1))
35 :
36 : -- make sure the full time interval elapses
37 : check (ResetTimer ("afk_timer"))
38 :
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 22 Jul 2008 09:11 PM (UTC)

Amended on Tue 22 Jul 2008 09:13 PM (UTC) by Nick Gammon

Message
Recent versions of MUSHclient have the "check" function built in.

I suggest you download version 4.33, see this page:

http://mushclient.com/forum/?id=8765

If this post is older than a week or so, check for an even later version by going to:

http://mushclient.com/forum/?bbtopic_id=1

Most of the Aardwolf plugins require the new functionality in the latest version.

This particular one can probably be corrected by adding one line:


<script>
<![CDATA[

require "check"  --> add this line



However upgrading MUSHclient is the safer option, if you are planning to use the other plugins.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,415 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.