Aardwolf health bar plugin

Posted by Nick Gammon on Sun 13 Jul 2008 01:45 AM — 2 posts, 10,498 views.

Australia Forum Administrator #0
The plugin below shows a nice health bar under your command window, so you can see at a glance your health, compared to the mob you are fighting.


To use it, download the code below and save as Aardwolf_Health_Bar.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/Aardwolf_Health_Bar.xml

This plugin also uses the "stats detector" plugin, so you also need this file:

http://www.gammon.com.au/mushclient/plugins/Aardwolf/Stats_Detector.xml

The "Stats detector" plugin uses telnet negotation, so you also need this file:

http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua

In a standard MUSHclient installation these three files should to into this directory:


C:\Program Files\MUSHclient\worlds\plugins\Aardwolf\


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

<!-- Plugin "Health_Bar" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Aardwolf_Health_Bar"
   author="Nick Gammon"
   id="cfdf0a7e0a13bd77e0d970d7"
   language="Lua"
   purpose="Shows Aardwolf HP, Mana, Movement points in a colour bar"
   date_written="2008-06-28 09:50:05"
   requires="4.00"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Mana, 
and Movement points shown as a bar (between 0 and 10 blocks).
If you are fighting the enemy's name and health are also displayed.
]]>
</description>

</plugin>

<!--  Script  -->


<script>
<![CDATA[

require "checkplugin"

function capitalize (s)
  return string.sub (s, 1, 1):upper () .. string.sub (s, 2):lower ()
end -- capitalize 

function DoGauge (sPrompt, iPercent, sGoodColour, sBadColour)
local count = 0

  iPercent = (tonumber (iPercent) or 0) / 10
  
--
--  Do prompt in black Arial
--
  InfoColour "black"
--  InfoFont ("Dina", 9, 0)
  InfoFont ("Arial", 9, 0)
  Info (sPrompt)

--
--  Use Webdings for gauge (black square)
--

  InfoFont ("Webdings", 10, 0)


--
--  Below 30% warn by using different colour
--

  if iPercent < 3 then
    InfoColour (sBadColour)
  else
    InfoColour (sGoodColour)
  end -- if

--
--  Draw active part of gauge
--
  while count <= iPercent do
    Info "g"
    count = count + 1
  end -- for

--
--  Draw rest of gauge in grey (ie. unfilled bit)
--

  InfoColour "dimgray"
  while count <= 10 do
    count = count + 1
    Info "g"
  end -- while

end -- function

function draw_bar ()

  InfoClear ()
  
   -- item 7 is our HP
  DoGauge ("  HP: ",   stats.hp_percent, "darkgreen", "maroon")

  -- item 13 is enemy HP and item 12 is what we are doing, which should be "... fighting (enemy)"
  if stats.enemy_percent ~= "9999" then
    DoGauge ("  " .. stats.enemy .. ": ", stats.enemy_percent, "darkred", "red")
  end -- if fighting 

  -- item 8 is our mana
  DoGauge ("  Mana: ", stats.mana_percent, "mediumblue", "mediumblue")
  
  --  item 9 is our movement points
  DoGauge ("  Move: ", stats.moves_percent, "gold", "gold")

end -- draw_bar

function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
  
   -- get all variables
   stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
     
   draw_bar ()
   
  end -- stats changed
end

function OnPluginInstall ()

  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
  
  OnPluginEnable ()  -- do initialization stuff
  
end -- OnPluginInstall

function OnPluginEnable ()

  checkplugin ("8a710e0783b431c06d61a54c", "Stats_Detector.xml")
  
  ShowInfoBar (true)

end -- OnPluginEnable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>

</muclient>
Australia Forum Administrator #1

Example of plugin in operation: