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 the code below (in the code box) to the Clipboard
Open a text editor (such as Notepad) and paste the plugin code into it
Save to disk on your PC, preferably in your plugins directory, as Health_Bar_Miniwindow.xml
The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
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"
Save your world file, so that the plugin loads next time you open it.
<?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>
Is there something i have to install besides the plugin to see the bar because ive been trying to use the status bar plugins and everything and whenever i enable it all i see is:
TRACE: Matched trigger "^\<\-?(\d+)\/(\d+) hp \-?(\d+)\/(\d+) m \-?(\d+)\/(\d+) mv\>(.*?)$"
Unless you have changed the trigger in the plugin, that won't match. It matches something like:
<46h/100 hp 32/80 m 100/200 mv 1000/2000 xp>
The plugin cannot just somehow know your health from the many, many prompts that each MUD has. You have to adjust the trigger (near the top) to match your unique prompt. See http://www.gammon.com.au/regexp for hints about making regular expressions.
I'm playing Achaea. I was just curious as there are no movement points and we also have the endurance and willpower points. I'm very new to using MUSH so I'm not up to par with the coding yet.
Look at the function do_prompt in the middle of the plugin. You don't have to be a wizard scripter to see that basically it is getting the numbers from the wildcards, like this:
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])
Then it divides the current by the max to get the percentage:
local hp_percent = hp / max_hp
local mana_percent = mana / max_mana
local move_percent = move / max_move
I've been toying with this plugin for a bit, and have my own kinda look to it now. But, I'm having an issue, I would like to change the color of the bar as it decreases, initially I was going to do a gradient fill, but even with that method I ran into troubles. So, if I know that I want it to start as one color, and end as another how would I code this to happen with the plugin?
If I understand what you're asking, you could draw a gradient between the two colors you want on another window (an invisible one), 100 pixels length, 1 pixel height, and use WindowGetPixel() to get the pixel colour at a certain point of the gradient based on the current status of the gauge.
Basically, if the gate is 100% full, you would take the (100-1)th pixel (the 99th, the right-most) from the gradient, and use its color to fill the gauge. If it's 1% full, you'd take the (1-1)th pixel (the 0th, the left-most) and use its color to fill the gauge. And if it's 0% full, you wouldn't draw anything.
You shouldn't need to do it pixel by pixel, as WindowGradient does gradients. The plugin already uses that to do a gradient from top to bottom to get a 3D effect, but if you wanted a left-to right gradient, and weren't too picky about the 3D effect, you could just change the direction of it, with a bit of calculating about its limits.
I don't think he wanted an actual gradient on-screen, he just wanted to modulate the absolute color of the gauge depending on the gauge's percentage. All green if full, and tending towards red as the percentage drops. It's not really a pixel-by-pixel thing, it's just like, mm, the eyedropper tool on MS Paint. It grabs the appropriate color (based on a gradient) and fills the gauge with that color.
You could take the current colour (eg. green) which is going to be supplied to draw the bar, and apply a modification to it, like gamma, brightness or contrast, and use the resulting colour instead.
A few issues, first of all, it seems that nothing at all happens if I try to make a 1x1 window, secondly I can't seem to pull the right color from the gradient rectangle that I've made, instead it just keeps pulling the background color and setting it. This is the code that I'm currently trying to use:
showing only relevant code because of post length limit:
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)
WindowCircleOp (win, 3, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
BACKGROUND_COLOUR, 0, 2, BACKGROUND_COLOUR, 10, 25, 25) -- 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
-- WindowRectOp (win2, 1, 2, 2, 100, 2, ColourNameToRGB ("lightgrey"))
--create the gradient line
WindowGradient (win2, 50, 1, 50, 1,
ColourNameToRGB ("red"),
Colour, 1)
-- top half
--old method commented out
-- WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2,
-- 0x000000,
-- Colour, 2)
WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2,
0x000000,
WindowGetPixel( win2, Fraction, 1 ), 2)
-- bottom half
WindowGradient (win, GAUGE_LEFT, vertical + GAUGE_HEIGHT / 2,
GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT,
WindowGetPixel( win2, Fraction, 1 ),
0x000000, 2)
end -- non-zero
function OnPluginInstall ()
win = GetPluginID ()
win2 = 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) )
check (WindowCreate (win2,
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
-- make a hotspot
WindowAddHotspot(win2, "hs2",
0, 0, 0, 0, -- whole window
"", -- MouseOver
"", -- CancelMouseOver
"mousedown",
"", -- CancelMouseDown
"", -- MouseUp
"Drag to move", -- tooltip text
1, 0) -- hand cursor
WindowShow( win2, false )
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)
WindowShow (win2, 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>
Everything else works, but I can't seem to be able to pull the right color.
Well, first of all, you're using the same ID for both windows. The latter will overwrite the former. (I'll edit in some other suggestions, but I think that's your biggest issue, so I'll submit now.)
Here's an example of the gradient sampling technique from earlier. I've tested it, so it should work if you just paste it straight into Ctrl+I and run it. You'll obviously need to modify it to fit your plugin though.
-- a unique identifier
win = GetPluginID() .. "_gradient"
-- the hidden gradient we take the color from
WindowCreate(win,
0, 0, -- location doesn't really matter
100, 1, -- 100x1 window: a straight line gradient
0, 2, -- absolute positioning, nothing special
0x000000) -- black background, doesn't really matter though
-- load the window with our gradient
WindowGradient(win,
0, 0, 0, 0, -- cover the whole window
0x0000FF, -- red, the left color
0x00FF00, -- green, the right color
1) -- horizontal gradient
-- pretend we have a gauge
-- get the percentage of the gauge that is full
-- local percentage = WhateverStuffGoesHere() - 1
local percentage = 75 - 1
-- subtract 1 because pixel coordinates are 0-based
-- get the color value at that point of the gradient
local color = WindowGetPixel(win, percentage, 0)
-- another unique identifier
win2 = GetPluginID() .. "_view"
-- the window we actually make visible
WindowCreate(win2,
0, 0, -- wherever you want
200, 200, -- whatever you want
0, 2, -- absolute positioning
0x000000) -- black background, doesn't really matter
WindowRectOp(win2,
2, -- fill
0, 0, percentage * 200 / 100, 200, -- cover everything up to the percentage line
color, -- fill with the color we sampled from the gradient
nil) -- color2 doesn't matter for a fill action
WindowShow(win2, true) -- show it
Sweet, you guys are awesome. I got it doing exactly what I wanted now. Thanks for all the help. Was gonna post it all, but it's too big. I'll have to link back to it at some point from my website or something.
You could paste it to mushclient.pastebin.com and link it to us here. (It might be helpful if you set its expiry time to forever, because otherwise forum lurkers in the future won't be able to see the plugin.)
The neat thing about pastebin.com is that you can add whatever gibberish you want for a subdomain, and it'll work. All of the below urls go to different unique pastebins:
mushclient.pastebin.com
www.pastebin.com (aka just pastebin.com)
etaijaeltkjtkjaeta.pastebin.com
Your changes look good! I particularly like how you use the sampled pixel as input to two more WindowGradient() calls, to give it a 3D/glassy look. :)
EDIT: For what it's worth, since you've basically created a new plugin, you might want to give it a new ID, update the written date, and add yourself as the author (all in the <plugin> tag at the top). (Of course, I'd add a comment noting Nick's original as the inspiration, for good measure.)
EDIT 2: You could also move the first WindowGradient() call, the one that creates the gradient line, into OnPluginInstall, because the colors are constant and it's not going to change every time you draw the same gradient.
I know that I'm still a newb and everything. But, initially I didn't notice this, but now I do. The status box is always one step behind my prompt, upon further testing it's because my prompt doesn't have a newline at the end. So, is there a way to modify the trigger so it will still catch even without the newline, or do I have to put the newline in my prompt if I want the box to be 'up to date'.
I was wondering if I could get your help in setting my bar up in the mud I play? (Materia Magica). I've asked numerous times in game but no one has been able to help me.
My prompt looks like this: [*]<2366hp 1595sp 1689st>
the * means I'm affected by invisibility.
Also, would I be able to apply something similar to my ship's remaining hull? Prompt is:
(450hull --dir ANCHOR --wind 100%shld 1190,965)
And also, when I used to use Portal, it had a bar that showed the enemy's remaining health in numerical terms, i.e. it converted the expressions from the game into a % on the graphical bar, are we able to do that in MUSH?
The health bar works by knowing your current and maximum HP etc.
Your prompt:
<2366hp 1595sp 1689st>
... only shows the current value, thus it can't display a bar because it doesn't your maximum HP. You need to find a way to show that, for example, by changing your prompt to look more like what was shown on page 1 of this thread.
Id like to get a nice health/status bar going if someone could help me, new to to this, trying to learn as fast as i can, anyways here's my stats bar in game:
5932 health, 9292 endurance, 276 guile x A:100% -
You are no longer in the throes of combat.
5932 health, 9292 endurance, 275 guile x-
Ugh, I checked all the command prompt options and splitting isnt one of them, asked in game an told it isnt an option, all i could do was add/remove stats and shorten them.. which i did it now looks like:
6280h, 9562e, 274g x A:59% - (in battle)
6280h, 9562e, 277g xb- (out of battle)
all stats are full at the moment.. except Adrenaline at 59%
(I made a level since the last post so now they are all slightly higher.)
---by the way the xb is just x = standing b = balance--
Ya know.. when you check "score" it lists my stats in the format youre looking for, is it possible to pull the stats from the score and just get the adrenaline from the prompt?
Basyiel (male Northlands Goblin)
You are level 65 (Enshrined) and 1.88% of the way to the next level.
Health: 6280/6280 Endurance: 9562/9562
Guile: 272/278
You are ranked 84th in Midkemia.
You stand tall as a proud Clansman of Sar-Sargoth.
You are a Hatchling in the Clan Raven.
You are a Rogue.
You are a Worldwalker in the Fellowship of Explorers.
You are 17 years old, having been born on the 6th of Yamiev, 12 years before the
Darkness at Sethanon.
You carry 8 copper in Kingdom currency.
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:
maxima 6280 9562 274
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).
That tells it the current and maxima, so it can draw the bar immediately. Afterwards it shows the current from the prompt. Now you only need to type "score" each time you level.
(You could make a trigger that matches whatever it says when you level and automatically send "score").
To save and install the Health_Bar_Miniwindow2 plugin do this:
Copy the code below (in the code box) to the Clipboard
Open a text editor (such as Notepad) and paste the plugin code into it
Save to disk on your PC, preferably in your plugins directory, as Health_Bar_Miniwindow2.xml
The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
Go to the MUSHclient File menu -> Plugins
Click "Add"
Choose the file Health_Bar_Miniwindow2.xml (which you just saved in step 3) as a plugin
Click "Close"
Save your world file, so that the plugin loads next time you open it.
<?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>
<trigger
enabled="y"
lines_to_match="2"
match="^Health\: (\d+)\/(\d+) Endurance\: (\d+)\/(\d+)\nGuile: (\d+)/(\d+)\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
hp = %1
max_hp = %2
endurance = %3
max_endurance = %4
guile = %5
max_guile = %6
-- draw gauge
do_prompt ("", "", { hp, endurance, guile } )
</send>
</trigger>
</triggers>
<!-- 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])
-- don't know maxima yet? can't proceed
if max_hp == 0 or
max_endurance == 0 or
max_guile <= 0 then
return
end
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>
Thanks a ton for all your effort Nick, really enjoying the MUSHclient, just need to take some time and learn some programming.
After loading the bar didnt come up, after reading boards i noticed normally this happens because something doesnt match, i looked at the triggers and it doesnt mention the xb and adrenaline factors.. could that possibly be the problem?
I also have seen some code for the game others have tried and it includes it in an example such as this:
^(\d+)h, (\d+)e(, (\d+)[mfg])? x?b?( A:(\d+)%)?-$
6280h, 9562e, 274g x A:59% - (in battle)
6280h, 9562e, 277g xb- (out of battle)
ya had mentioned the code was basing it off the score, but does it read the prompt at all too? if so, i think this maybe why it doesnt match.
I replaced the trigger code with what i have above and the window came up but no stats were displayed, so must be on the right track.. just need little help to tweak it
I tried it with that exact prompt and it appeared. The match string:
match="^(\d+)h, (\d+)e, (\d+)g "
... has no terminating $ so it simply matches anything that starts with something like:
6280h, 9562e, 274g
You know that triggers don't match until a newline? Maybe hit <enter> a couple of times. Also it won't display the bars unless it knows the maximum, so try typing "score" first.
Of coarse your right,I retried the original code, its up and doin its thing.. to be ideal, i need Adrenaline on the bar as well.. that really a primary fighting ability knowing where its at...
Im very happy with what ya've shown me, I'll take that, learn from it and try to expand features on my own, if i mess up, ill just reload the original and try again..
Thank you Very much for ya patience gettin that up for me :-)
I just remembered my more recent health bars show the percentage in balloons when you mouse-over the three bars. This amended version will do that:
<?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>
<trigger
enabled="y"
lines_to_match="2"
match="^Health\:\s+(\d+)\/(\d+)\s+Endurance\:\s+(\d+)\/(\d+)\nGuile:\s+(\d+)/(\d+)\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
hp = %1
max_hp = %2
endurance = %3
max_endurance = %4
guile = %5
max_guile = %6
-- draw gauge
do_prompt ("", "", { hp, endurance, guile } )
</send>
</trigger>
</triggers>
<!-- 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, current, max, Colour)
if max <= 0 then
return
end -- no divide by zero
-- fraction in range 0 to 1
local Fraction = math.min (math.max (current / max, 0), 1)
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
WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
ColourNameToRGB ("lightgrey")) -- frame entire box
-- mouse-over information: add hotspot if not there
if not WindowHotspotInfo(win, sPrompt, 1) then
WindowAddHotspot (win, sPrompt, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + font_height,
"", "", "", "", "", "", 0, 0)
end -- if
-- store numeric values in case they mouse over it
WindowHotspotTooltip(win, sPrompt, string.format ("%s\t%i / %i (%i%%)",
sPrompt, current, max, Fraction * 100) )
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])
-- don't know maxima yet? can't proceed
if max_hp <= 0 or
max_endurance <= 0 or
max_guile <= 0 then
return
end
-- fill entire box to clear it
WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR)
-- Edge around box rectangle
WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1)
vertical = 6 -- pixel to start at
DoGauge ("HP: ", hp , max_hp, ColourNameToRGB "darkgreen")
DoGauge ("Endurance: ", endurance, max_endurance, ColourNameToRGB "mediumblue")
DoGauge ("Guile: ", guile, max_guile, 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 = tonumber (GetVariable ("max_hp")) or 0
max_endurance = tonumber (GetVariable ("max_endurance")) or 0
max_guile = tonumber (GetVariable ("max_guile")) or 0
-- make miniwindow so I can grab the font info
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)
WindowFont (win, font_id, font_name, 9)
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.")
EnablePlugin (GetPluginID (), false)
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>
Again, im sure ya've heard it 1000x times, but ya the man.. especially if ya can get a complete 'newbie' like me gettin this goin.. i learn fast tho, sorry i was such a drain on your patience and resources..
Below is an improved version of the original one on page 1.
Improvements are:
Neatened up the code, to make it easier to modify in future (eg. the width of the word "Mana" and "Move" are now calculated, to get the offset of the bar from the edge).
Shows mouse-over information (like the example above)
Incorporates the movewindow module for dragging rather than having code inline, which makes it all smaller.
Hides the window if you disable the plugin, and shows it again if you enable it.
To save and install the Health_Bar_Miniwindow plugin do this:
Copy the code below (in the code box) to the Clipboard
Open a text editor (such as Notepad) and paste the plugin code into it
Save to disk on your PC, preferably in your plugins directory, as Health_Bar_Miniwindow.xml
The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
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"
Save your world file, so that the plugin loads next time you open it.
<?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="2010-02-14 09:00"
requires="4.40"
version="2.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.
For Smaug your prompt needs to be set like this:
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>
]]>
</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_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, current, max, Colour)
if max <= 0 then
return
end -- no divide by zero
-- fraction in range 0 to 1
local Fraction = math.min (math.max (current / max, 0), 1)
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
WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
ColourNameToRGB ("lightgrey")) -- frame entire box
-- mouse-over information: add hotspot if not there
if not WindowHotspotInfo(win, sPrompt, 1) then
WindowAddHotspot (win, sPrompt, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + font_height,
"", "", "", "", "", "", 0, 0)
end -- if
-- store numeric values in case they mouse over it
WindowHotspotTooltip(win, sPrompt, string.format ("%s\t%i / %i (%i%%)",
sPrompt, current, max, Fraction * 100) )
vertical = vertical + font_height + 3
end -- function DoGauge
function do_prompt (name, line, wildcards)
hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
-- 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 , max_hp, ColourNameToRGB "darkgreen")
DoGauge ("Mana: ", mana, max_mana, ColourNameToRGB "mediumblue")
DoGauge ("Move: ", move, max_move, ColourNameToRGB "gold")
WindowShow (win, true)
end -- function do_prompt
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
-- make miniwindow so I can grab the font info
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)
WindowFont (win, font_id, font_name, 9)
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, "Mana: "))
gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Move: "))
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))
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 max_hp and mana and max_mana and move and max_move then
do_prompt ("", "", { hp, max_hp, mana, max_mana, move, max_move } )
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)))
end -- OnPluginSaveState
]]>
</script>
</muclient>
I noticed I few people at the begining asking for an Achaean version, so as an Achaea player myself, I tried to make one. I seem to have hit a roadblock, however. Upon installation there are multiple errors, and I don't know how to fix them.
http://mushclient.pastebin.com/m31bde1e1
If you could take a look and see what's wrong, it'd be much appreciated.
You'll probably get more assistance if you post the errors as well: not everyone is going to load up your code, many errors can be fixed just by glancing at the error message and scanning the source for the right line.
Also, you might perhaps be glad to hear that I am also an Achaean, and I develop and maintain an ATCP-based Gauges plugin (originally written by Trevize of Achaea). It looks a lot like the gauges that the official Nexus client have (another player made the images), and you can find a screenshot here [1]. It also has the benefit of working automatically, without sending SCORE or parsing the prompt, since it uses the hidden ATCP data Achaea sends. You can download it (and other ATCP-based plugins, including the ATCP plugin itself) here [2].
If that doesn't interest you, I'd be glad to help fix your version, but again, it's a lot easier on us if you just paste the errors yourself. "I have errors" doesn't tell us much ;)
Quote: Compile error
Plugin: Achaean_Health_Bar (called from world: Achaea)
Immediate execution
[string "Plugin"]:81: 'then' expected near ','
Error context in script:
77 : willpower = tonumber (wildcards [4])
78 :
79 : -- don't know maxima yet? can't proceed
80 : if max_hp <= 0 or
81*: max_mana ,= 0
82 : max_endurance <= 0 or
83 : max_willpower <= 0 then
84 : return
85 : end
By glancing at the if's conditional, I notice you used ,= instead of <=. You also forgot the "or" after that check as well.
After fixing that, it loads properly, however there's four gauges and the window only has room for three. I changed WINDOW_HEIGHT at the top from 65 to 80 to fix that (with a bit of math assuming that there's 10px padding, that's 15px per gauge, so I added 15px more).
Now it doesn't update automatically unless I hit SCORE, which I believe is an issue with the prompt trigger. I have a " Vote-" bit right after my willpower, because I have my voting prompt enabled (config voting prompt), but I haven't voted yet. You're also missing the other prompt statuses besides the "ex". Here's my prompt pattern that matches almost any prompt as long as it has health at the beginning.
Alteration of script:
When using hp command, both values are grabbed, the "maximum" value is stored for later use, and the bars are adjusted accordingly.
When in combat, current hp/sp/ep are updated by the combat prompt and the bars are adjusted accordingly.
Maximum values are -only- updated by using the "hp" command to get the full prompt, since it is the only method that will pull those numbers.
My current attempt at editing the script is in two parts. Editing the triggers, and editing the "function do_prompt"
function do_prompt (name, line, wildcards)
hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
sp, max_sp = tonumber (wildcards [3]), tonumber (wildcards [4])
ep, max_ep = tonumber (wildcards [5]), tonumber (wildcards [6])
-- 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, max_hp, ColourNameToRGB "darkgreen")
DoGauge ("SP: ", sp, max_sp, ColourNameToRGB "mediumblue")
DoGauge ("EP: ", ep, max_ep, ColourNameToRGB "gold")
WindowShow (win, true)
end -- function do_prompt
function do_prompt2 (name, line, wildcards)
hp = tonumber (wildcards [1])
sp = tonumber (wildcards [2])
ep = tonumber (wildcards [3])
-- 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, max_hp, ColourNameToRGB "darkgreen")
DoGauge ("SP: ", sp, max_sp, ColourNameToRGB "mediumblue")
DoGauge ("EP: ", ep, max_ep, ColourNameToRGB "gold")
WindowShow (win, true)
end -- function do_prompt2
Like so? and...
font_name = "Courier New" -- the font
-- make miniwindow so I can grab the font info
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)
WindowFont (win, font_id, font_name, 10)
font_height = WindowFontInfo (win, font_id, 1) -- height
Did I change the font correctly? Fixedsys bothers me is all. I changed that to Courier New and, I hope, switched it to font size 10.
Can you post the prompts that are coming through? Sounds like the trigger is matching but it is getting a low figure. You could add some debugging like this:
HP:204/204 SP:272/272 EP:151/155
In DoGauge, prompt= HP: current= 1 max= 25600
In DoGauge, prompt= SP: current= 1 max= 13434880
In DoGauge, prompt= EP: current= 0.9741935483871 max= 55295
It seems to be grabbing the fraction, rather than the min and max, for whatever reason. I haven't changed the triggers at all though... why would it do that?
aha, that's it. A few posts back you suggested a different way to do the two prompts, with the combined section as draw_the_bars (). That's where it got changed. I'll switch it and see if that fixes it. The switchup happened when I used the older version of the plugin at first, I think. I didn't update it all like I should have for the newer version.
Fixed :D
function draw_the_bars ()
-- 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, max_hp, ColourNameToRGB "darkgreen")
DoGauge ("SP: ", sp, max_sp, ColourNameToRGB "mediumblue")
DoGauge ("EP: ", ep, max_ep, ColourNameToRGB "gold")
WindowShow (win, true)
end -- draw_the_bars
so here goes, I've NEVER coded at all in my life, i just did some editing earlier on the chat box window. Got it working for my MUD Atlas. i'm experienced with triggers. But heres my question
my prompt
[116/116hp|122/122mp|100/100mv] and sometimes has
[Bellrog 98%][116/116hp|122/122mp|100/100mv]
to show me what my party members health is. this will disappear if the person is at 100% being replaced with My name
[Dragonrider 100%][116/116hp|122/122mp|100/100mv]
Okay i need to get MY stats on a health bar, I don't know what part of the script i need to use, so if you could just edit the script with my information so all i have to do is copy and paste i would be most grateful!
Would be nice if above this bar it would put the party members health in normal text [Bellrog 98%] where bellrog is a wildcard *
I'm very new, and its like learning a foreign language, Any help would be amazing, specially to you Nick, I'm 25 and have been mudding since i was 12. I have used mushclient for many years and I will never change to another client. Please help! =)
and if i wanted to do a different prompt from a different character on the same plugin, i just add another trigger right? or would i have to change more again :(
[358/358hp|247/247mp]
would be the secondary prompt
regular expression would be
^\[(.*?)\/(.*?)hp\|(.*?)\/(.*?)mp\]$
How would I incorperate that? so it works for both?
And i tried both of those suggestions, and nothing... :(
-----I retract this statement, It is working for the first prompt, is it possible to make it match for a second one? or should i just make a separate plugin for each characters prompt?
i eventually ended up changing the other characters prompt to match. I was having problems trying to do the other chars because theres only 2 gauges. Didn't want to butcher the code. Is there a way to put your group members hp% on there?
[Neravar *%][*/*hp|*/*mp|*/*mv]
Honestly the MV in this MUD is completely useless. and the
[Neravar *%] is only there if your in a group. If your NOT in a group it shows up as [*/*hp|*/*mp|*/*mv]
Okay so how would i convert the third bar, to read a percentage of my group members health?
It doesn't show their hp and max. Just like 56% or 99% once it hits 100% it switchs to a different party member. How hard would it be to convert it to work with this? only on the third bar?
I'm sorry i'm being such a handful, i've never coded before and im kinda having trouble grasping it. I did get the chatbox AND the healthbar to work however, i just want to replace MV bar with Group health %
grouped - [Bellrog 98%][87/124hp|101/132mp|100/100mv]
not grouped - [87/124hp|101/132mp|100/100mv]
if partymembers are at 100% it shows my name in their spot.
I can add this as the third bar on the HP/MP bar right?
Can i add a fourth one too right?
for example if i changed my prompt to show exp as follows
[Bellrog 98%][87/124hp|101/132mp|100/100mv|65,447 tnl]
i can also make it pick up exp right? this is tricky for me because the groupmember health box isn't there if your not in a group.
It can all be done, why not try it? I prefer to help debug scripts after someone has tried, not just answer general questions "can this be done?".
Virtually anything can be done, we have mappers that show hundreds of rooms at once. You will learn by trying, you can't break anything. Make a copy of the plugin if you are worried about going backwards.
Honestly when i look at the coding i see jibberish so i look for keywords and edit small things. I'm not that good with coding to do like any of the simplest things :(
I don't have the resources to actually code plugins for individual players, for each one of the 1000 or so MUDs around.
I try to distribute examples and explain how they work. If they work without change, that's great. Hopefully the changes needed to make them work on a different MUD are minor.
And indeed it sounds like you got it to work for your MUD as well. But to make major changes like incorporating members of a group, for a MUD I don't play (and I don't think you mentioned the name of), requires some work by you, the player.
You will learn a lot more, and empower yourself to make even better plugins, by trying to do things yourself. If I do it, you haven't learned anything, and tomorrow you will want me to do something else.
If you aren't sure, try reading the "Programming in Lua" online book:
http://www.lua.org/pil/
Experiment with the Immediate window to see how simple script commands work.
I've done a number of YouTube videos showing how to do things, like scripting, making aliases, triggers and plugins:
I've got the code and got it working with a few minor modifications. Works beautifully, save for one thing.
I, too, have a prompt which does not define the maximum values. At present, I have them hard coded in. Due to the way that I've been building up my system, I DO have the values readily available in variables.
But I can't seem to CALL them. Tried several variations of a standard getvariable line, to no avail. Is there a way to call a variable into this script, and if so, how does one do it?
What I've got at present is as follows:
max_endurance = world.GetVariable ("MaxEnd") or 402
It's picking up the 402, so if nothing else I'm pretty certain that I have the line in the right area of the script.
Any assistance you can give me would be much appreciated.
And if I execute
ColourNote("","",tostring(GetVariable("MaxEnd")))
It does respond appropriately. So the variable itself seems to be okay, as long as I'm executing it from the world and not the plugin.
Well you didn't exactly mention that you were trying to get a variable inside a plugin that exists outside the plugin. Each plugin, and the main world, have independent script and variable "spaces".
Ah, apologies. I was under the impression that I could pull variables like I usually do (I usually do all of my work inside the world, with only minor projects in plugins).
With GetPluginVariable, it works beautifully. Thank you very much for the help, as well as for the link up to the functions' page. Much appreciated on both counts!
I've edited the script to need one to type score and the prompt formatting. I load it and it type score and hit enter a few times and get no errors but the miniwindow does not display.
Prompt:
[Fury: 100]
[PL: 84,587,890][KI: 83,331,246][STA: 83,316,014][TNL: 21,025,070][ 7 PM][Zen: 5,263]>
Score:
O==========================={ Health }==============================O
|CUR Pl: [ 84,587,890] CUR KI: [ 83,331,246] CUR STA: [ 83,316,014]
|MAX Pl: [ 84,587,890] MAX KI: [ 83,331,246] MAX STA: [ 83,316,014]
It wont let me add the entire thing so i'm adding only the parts that I changed.
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^[PL\: (\d+)][KI\: (\d+)][STA\: (\d+)] "
regexp="y"
script="do_prompt"
sequence="100"
>
</trigger>
<trigger
enabled="y"
lines_to_match="2"
match="^\|CUR Pl\: [(\d+)] CUR KI\: [(\d+)] CUR STA\: [(\d+)]\n|MAX Pl\: [(\d+)] MAX KI\: [(\d+)] MAX STA\: [(\d+)]"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
hp = %1
max_hp = %4
endurance = %2
max_endurance = %5
guile = %3
max_guile = %6
-- draw gauge
do_prompt ("", "", { pl, ki, sta } )
function do_prompt (name, line, wildcards)
pl = tonumber (wildcards [1])
ki = tonumber (wildcards [2])
sta = tonumber (wildcards [3])
-- don't know maxima yet? can't proceed
if max_pl == 0 or
max_ki == 0 or
max_sta <= 0 then
return
end
local pl_percent = pl / max_pl
local ki_percent = ki / max_ki
local sta_percent = sta / max_sta
DoGauge ("PL: ", pl_percent, ColourNameToRGB "red")
DoGauge ("KI: ", ki_percent, ColourNameToRGB "mediumblue")
DoGauge ("STA: ", sta_percent, ColourNameToRGB "gold")
WindowShow (win, true)
-- get maxima from last time
max_pl, max_ki, max_sta =
tonumber (GetVariable ("max_pl")) or 0,
tonumber (GetVariable ("max_ki")) or 0,
tonumber (GetVariable ("max_sta")) or 0
function OnPluginEnable ()
WindowShow (win, true)
-- draw gauge again if possible
if pl and ki and sta then
do_prompt ("", "", { pl, ki, sta } )
end -- if know pl, ki and sta
end -- OnPluginEnable
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("max_pl", max_pl or 0)
SetVariable ("max_ki", max_ki or 0)
SetVariable ("max_sta", max_sta or 0)
end -- OnPluginSaveState
]]>
</script>
</muclient>
Hi, I'm new to this whole plugin/scripting thing, and I'm trying to figure out how I would get this to work to capture the prompt bar from a trigger.
In the plugin script it says
- <triggers>
<trigger enabled="y" match="^.*?\[(\d+)\/(\d+)hp\|(\d+)\/(\d+)mp\|(\d+)\/(\d+)mv\]$"
I'm not sure if I'm getting this right but in there I'd create a Trigger, like one with the name Promptbar, that would be the trigger to match on instead of the actual promt text itself, then I could modify what the trigger fires on, right?
I'm not sure I understand the question. The whole thread is about capturing from a trigger to make health bar.
Can you explain in more detail? Like, give actual MUD output?
I don't have a mud output, I'm trying to figure out how to get this to work with Armageddon Mud, and was wondering how I get this to read my promptbar. I noticed in the script it said 'get trigger=' then a group of variables.
Is this a trigger I write if so how? How do I change the plugin to read it, then use it?
For instance, I use a prompt format of:~
HP%H/%h ST%T/%t MV%V/%v\n %A/%n/%E/%e >
%H/h Health %T/t Stun
%V/v Movement \n New line
%A Armed status %n name
%E Encumberance level %e time of day
the parts I'd want to grab are Health Stun and Movement (with an extra option for a mana addition to the prompt bar)
So seeing as the Prompt values vary between PC and PC I'd need a trigger that read my first line of prompt values as wildcards, right?
so something like HP%1/%2 ST%3/%4 MV%5/%6
This would fire every-time my health, stun, movement, and mana if present are sent to Mush-client, correct?
I'm new at this, and this would be the first bit of scripting past single command aliases I've ever done, so getting it from the MUD to the script is getting me stuck.
what lines would i have to add to show an hunger bar and a thirst bar in the same window?
It's not clear that you can do that with this particular plugin idea, since Aardwolf does not send hunger or thirst through the prompt. You'd have to read those values another way.