Posted by
| Nick Gammon
Australia (23,000 posts) bio
Forum Administrator |
Message
| The plugin below detects whether you are "playing" Aardwolf. In this case "playing" is defined as "being logged in and able to enter commands". It was written so that other plugins (like spellups) would not uselessly try to do things if you were AFK, reading a help file, or otherwise not able to do things.
You are not playing if you:
- Are in the process of logging in (eg. name and password)
- Creating a new character ("er, I wonder if I should be a Dwarf?")
- Reading the Message of the Day (MOTD).
- At a "pager" prompt:
[ Paging : (Enter), (T)op, (Q)uit, (B)ack, (R)efresh, (L)ast, (A)ll ]:
- AFK (away from keyboard)
- Using the "note editor" to post a note on the forum
- Building new areas
In all these cases, if you try to do something like "cast aid" it will not only not work, but might cause a lot of confusion. For example, you might create a character called "cast aid", or you might post a note to the forum with "cast aid" in it 10 times.
The plugin works by detecting the new telnet negotiation options added to Aardwolf by using the OnPluginTelnetOption plugin callback. If you have just connected it also queries the server, in case you reconnected without logging out (eg. by reinstalling the plugin). Once the plugin knows if you are playing or not, or have changed playing status, it does a BroadcastPlugin to notify all other plugins, so they can react appropriately.
For example, if you were previously not playing, but are now playing, you might start casting spells.
Bear in mind that some commands only work if you are standing, so you might also want to use the "Stats Detection" plugin described here, to see if you are standing/fighting/sitting/sleeping etc.:
http://www.gammon.com.au/forum/?id=8776
Any plugin that needs to know if you are playing or not should use OnPluginBroadcast like this:
function OnPluginBroadcast (msg, id, name, text)
if id == "f5b05e8826711cdb0d141939" then
playing = text == "y"
end -- playing status changed
end
To use it, download the code below and save as Playing_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/Playing_Detector.xml
This plugin uses telnet negotation, so you also need this file:
http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua
The telnet options file is described here: http://www.gammon.com.au/forum/?id=8775
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>
<muclient>
<plugin
name="xPlaying_Detector"
author="Nick Gammon"
id="f5b05e8826711cdb0d141939"
language="Lua"
purpose="Detects if you are actually playing."
date_written="2008-07-02"
requires="4.33"
version="1.0"
>
<description trim="y">
[FOR PLUGIN AUTHORS ONLY]
Detects if you are playing (as opposed to logging in, creating
a new character, etc.)
Example:
function OnPluginBroadcast (msg, id, name, text)
if id == "f5b05e8826711cdb0d141939" then
playing = text == "y"
end -- playing status changed
end
To test if you are currently playing (after a reinstall):
playing = GetPluginVariable ("f5b05e8826711cdb0d141939", "playing")
</description>
</plugin>
<!-- Script -->
<script>
<![CDATA[
require "var"
playing = false
var.playing = "n"
function OnPluginTelnetOption (option)
--- ignore not type 100.
if string.byte(option,1) ~= 100 then return end
if option == string.char (100, 3) then
now_playing ()
else
stopped_playing ()
end -- if
end -- function
function now_playing (name, line, wildcards)
if playing then
return
end -- if already playing
playing = true
var.playing = "y"
BroadcastPlugin (1, "y")
end -- now_playing
function stopped_playing (name, line, wildcards)
if not playing then
return
end -- if already not playing
playing = false
var.playing = "n"
BroadcastPlugin (1, "n")
end -- stopped_playing
-- pull in telnet option handling
dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
function OnPluginInstall ()
-- if we are connected when the plugin loads, it must have been reloaded whilst playing
if IsConnected () then
TelnetOptionOn (TELOPT_REQUEST_STATUS) -- get actual status (eg. afk, playing)
end -- if already connected
end -- function OnPluginInstall
function OnPluginDisconnect ()
stopped_playing ()
end -- function OnPluginInstall
function OnPluginConnect ()
stopped_playing () -- wait for playing message
end -- function OnPluginConnect
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|