Message
| My first attempt is to assume the maxima are the largest figures you ever see (eg. when you are at full health), like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Health_Bar_Miniwindow2"
author="Nick Gammon"
id="78dcd04fc1096e8988f03892"
language="Lua"
purpose="Shows stats in a mini window"
date_written="2010-02-12"
requires="4.40"
version="1.0"
save_state="y"
>
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Endurance,
and Guile 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+)h, (\d+)e, (\d+)g "
regexp="y"
script="do_prompt"
sequence="100"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="^maxima (\d+) (\d+) (\d+)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
max_hp = %1
max_endurance = %2
max_guile = %3
-- draw gauge again if possible
if hp and endurance and guile then
do_prompt ("", "", { hp, endurance, guile } )
end -- if know hp, endurance and guile
</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
GAUGE_HEIGHT = 15
WINDOW_WIDTH = 300
WINDOW_HEIGHT = 65
NUMBER_OF_TICKS = 5
BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"
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)
hp = tonumber (wildcards [1])
endurance = tonumber (wildcards [2])
guile = tonumber (wildcards [3])
-- guess maxima
max_hp = math.max (hp, max_hp)
max_endurance = math.max (endurance, max_endurance)
max_guile = math.max (guile, max_guile)
local hp_percent = hp / max_hp
local endurance_percent = endurance / max_endurance
local guile_percent = guile / max_guile
-- 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 ("Endurance: ", endurance_percent, ColourNameToRGB "mediumblue")
DoGauge ("Guile: ", guile_percent, ColourNameToRGB "gold")
WindowShow (win, true)
end -- draw_bar
function OnPluginInstall ()
win = GetPluginID ()
font_id = "fn"
require "movewindow" -- load the movewindow.lua module
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, 7) -- default to 7 (on right, center top/bottom)
font_name = "Fixedsys" -- the font
-- get maxima from last time
max_hp, max_endurance, max_guile =
tonumber (GetVariable ("max_hp")) or 0,
tonumber (GetVariable ("max_endurance")) or 0,
tonumber (GetVariable ("max_guile")) or 0
-- make miniwindow so I can grab the font info
check (WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
WINDOW_WIDTH,
WINDOW_HEIGHT,
windowinfo.window_mode,
windowinfo.window_flags,
BACKGROUND_COLOUR) )
-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, 0)
check (WindowFont (win, font_id, font_name, 9, false, false, false, false, 0, 0)) -- normal
font_height = WindowFontInfo (win, font_id, 1) -- height
-- work out how far in to start the gauge
gauge_left = WindowTextWidth (win, font_id, "HP: ")
gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Endurance: "))
gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Guile: "))
gauge_left = gauge_left + 5 -- allow gap from edge
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 OnPluginEnable ()
WindowShow (win, true)
-- draw gauge again if possible
if hp and endurance and guile then
do_prompt ("", "", { hp, endurance, guile } )
end -- if know hp, endurance and guile
end -- OnPluginEnable
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("max_hp", max_hp or 0)
SetVariable ("max_endurance", max_endurance or 0)
SetVariable ("max_guile", max_guile or 0)
end -- OnPluginSaveState
]]>
</script>
</muclient>
The lines in bold above set your maxima to whatever the largest you ever see is.
This should work OK, but might fail if your health temporarily went higher than usual (eg. a buff). So I added an alias, which you can type to reset the maxima like this:
Just supply the three figures in that order and it remembers them for next time. And if you would rather always do it that way, just comment out the lines in bold (put "--" in front of them).
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|