Message
| Below is an improved health-bar plugin. It uses a trigger that works off standard SMAUG prompts, providing you change them a bit to show the maximum health, mana and movement points.
For example:
prompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp>
fprompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp>
This plugin shows a nice 3D-looking health bar, with tick marks, and has the advantage it can be dragged around the output window. Simply click anywhere in it, drag it to a new location, and let go.
The new location is remembered in the plugin state file for next time you use it.
The plugin requires MUSHclient 4.40 (or above), which allows dragging miniwindows around. For a copy of version 4.40, see: http://www.gammon.com.au/forum/?id=9264
Below is the plugin.
|
To save and install the Health_Bar_Miniwindow plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Health_Bar_Miniwindow.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Health_Bar_Miniwindow.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Health_Bar_Miniwindow"
author="Nick Gammon"
id="48062dcd6b968c590df50f32"
language="Lua"
purpose="Shows stats in a mini window"
date_written="2009-02-24 13:30"
requires="4.40"
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.
The window can be dragged to a new location with the mouse.
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^\<(\d+)\s*\/(\d+)\s*hp (\d+)\s*\/(\d+)\s*m (\d+)\s*\/(\d+)\s*mv "
regexp="y"
script="do_prompt"
sequence="100"
>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
GAUGE_LEFT = 55
GAUGE_HEIGHT = 15
WINDOW_WIDTH = 200
WINDOW_HEIGHT = 65
NUMBER_OF_TICKS = 5
BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"
function mousedown(flags, hotspot_id)
-- find where mouse is so we can adjust window relative to mouse
startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)
-- find where window is in case we drag it offscreen
origx, origy = WindowInfo (win, 10), WindowInfo (win, 11)
end -- mousedown
function dragmove(flags, hotspot_id)
-- find where it is now
local posx, posy = WindowInfo (win, 17),
WindowInfo (win, 18)
-- move the window to the new location
WindowPosition(win, posx - startx, posy - starty, 0, 2);
-- change the mouse cursor shape appropriately
if posx < 0 or posx > GetInfo (281) or
posy < 0 or posy > GetInfo (280) then
check (SetCursor ( 11)) -- X cursor
else
check (SetCursor ( 1)) -- hand cursor
end -- if
end -- dragmove
function dragrelease(flags, hotspot_id)
local newx, newy = WindowInfo (win, 17), WindowInfo (win, 18)
-- don't let them drag it out of view
if newx < 0 or newx > GetInfo (281) or
newy < 0 or newy > GetInfo (280) then
-- put it back
WindowPosition(win, origx, origy, 0, 2);
end -- if out of bounds
end -- dragrelease
function DoGauge (sPrompt, Percent, Colour)
local Fraction = tonumber (Percent)
if Fraction > 1 then Fraction = 1 end
if Fraction < 0 then Fraction = 0 end
local width = WindowTextWidth (win, font_id, sPrompt)
WindowText (win, font_id, sPrompt,
GAUGE_LEFT - width, vertical, 0, 0, FONT_COLOUR)
WindowRectOp (win, 2, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
BACKGROUND_COLOUR) -- fill entire box
local gauge_width = (WINDOW_WIDTH - GAUGE_LEFT - 5) * Fraction
-- box size must be > 0 or WindowGradient fills the whole thing
if math.floor (gauge_width) > 0 then
-- top half
WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2,
0x000000,
Colour, 2)
-- bottom half
WindowGradient (win, GAUGE_LEFT, vertical + GAUGE_HEIGHT / 2,
GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT,
Colour,
0x000000,
2)
end -- non-zero
-- show ticks
local ticks_at = (WINDOW_WIDTH - GAUGE_LEFT - 5) / (NUMBER_OF_TICKS + 1)
-- ticks
for i = 1, NUMBER_OF_TICKS do
WindowLine (win, GAUGE_LEFT + (i * ticks_at), vertical,
GAUGE_LEFT + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
end -- for
-- draw a box around it
check (WindowRectOp (win, 1, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
ColourNameToRGB ("lightgrey"))) -- frame entire box
vertical = vertical + font_height + 3
end -- function
function do_prompt (name, line, wildcards)
local hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
local mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
local move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
local hp_percent = hp / max_hp
local mana_percent = mana / max_mana
local move_percent = move / max_move
-- fill entire box to clear it
check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR)) -- fill entire box
-- Edge around box rectangle
check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))
vertical = 6 -- pixel to start at
DoGauge ("HP: ", hp_percent, ColourNameToRGB "darkgreen")
DoGauge ("Mana: ", mana_percent, ColourNameToRGB "mediumblue")
DoGauge ("Move: ", move_percent, ColourNameToRGB "gold")
WindowShow (win, true)
end -- draw_bar
function OnPluginInstall ()
win = GetPluginID ()
font_id = "fn"
font_name = "Fixedsys" -- the actual font
local x, y, mode, flags =
tonumber (GetVariable ("windowx")) or 0,
tonumber (GetVariable ("windowy")) or 0,
tonumber (GetVariable ("windowmode")) or 8, -- bottom right
tonumber (GetVariable ("windowflags")) or 0
-- make miniwindow so I can grab the font info
check (WindowCreate (win,
x, y, WINDOW_WIDTH, WINDOW_HEIGHT,
mode,
flags,
BACKGROUND_COLOUR) )
-- make a hotspot
WindowAddHotspot(win, "hs1",
0, 0, 0, 0, -- whole window
"", -- MouseOver
"", -- CancelMouseOver
"mousedown",
"", -- CancelMouseDown
"", -- MouseUp
"Drag to move", -- tooltip text
1, 0) -- hand cursor
WindowDragHandler(win, "hs1", "dragmove", "dragrelease", 0)
check (WindowFont (win, font_id, font_name, 9, false, false, false, false, 0, 0)) -- normal
font_height = WindowFontInfo (win, font_id, 1) -- height
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
end -- OnPluginInstall
function OnPluginDisable ()
WindowShow (win, false)
end -- OnPluginDisable
function OnPluginSaveState ()
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("windowx", tostring (WindowInfo (win, 10)))
SetVariable ("windowy", tostring (WindowInfo (win, 11)))
SetVariable ("windowmode", tostring (WindowInfo (win, 7)))
SetVariable ("windowflags", tostring (WindowInfo (win, 8)))
end -- OnPluginSaveState
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|