Improved health bar plugin - can be dragged around

Posted by Nick Gammon on Tue 24 Feb 2009 03:08 AM — 98 posts, 409,547 views.

Australia Forum Administrator #0
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.

Template:saveplugin=Health_Bar_Miniwindow
To save and install the Health_Bar_Miniwindow plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. 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.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Health_Bar_Miniwindow.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. 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="^\&lt;(\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>


Amended on Wed 19 Aug 2009 06:46 AM by Nick Gammon
Australia Forum Administrator #1

Example of it in operation:

Australia Forum Administrator #2
If you like a bigger window, just change WINDOW_WIDTH inside the plugin.

For example, I tried a larger window:


WINDOW_WIDTH = 400


Australia Forum Administrator #3

That gave this result:

#4
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\>(.*?)$"

I don't see bars or anything.
Australia Forum Administrator #5
Can you show an example of your prompt please? If the trigger doesn't match then it won't display the health bars.
#6
My prompt is <100% 100% 100% 76(0) 73%% NEW>

Australia Forum Administrator #7
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.
#8
Is there a way to display perhaps endurance and willpower along with the health and mana and remove movement points from the bar?
#9
You would need to modify the trigger that captures the stats to match your MUD. Then modify the mini-window to display it.

What MUD are you playing?
#10
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.
#11
Until an Achaea player can answer have a look here.
Template:post=8915
Please see the forum thread: http://gammon.com.au/forum/?id=8915.
Australia Forum Administrator #12
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


Then a bit further on it draws the gauges:


  DoGauge ("HP: ",   hp_percent,    ColourNameToRGB "darkgreen")
  DoGauge ("Mana: ", mana_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("Move: ", move_percent,  ColourNameToRGB "gold")


So to remove the movement points you would omit the lines with "move" on them, but use them as a model for your endurance and willpower stats.

Of course, the trigger needs to be modified to pick up the endurance and willpower from your prompt.
Amended on Wed 04 Nov 2009 04:15 AM by Nick Gammon
#13
Great! Thank you guys a lot. I'll dabble with this a bit.
#14
Alright. I made an effort and cannot seem to get this to work. I keep getting errors. My prompt looks like this:

2300h, 2860m, 10400e, 11900w exdb-

and at times there are more letters on the end than just the exdb

In the trigger, I've tried to match my prompt but can't seem to get it right. Here is what I've tried:

^(\d+)h\, (\d+)m(?:\, \d+e)?(?:\, \d+w)? [cexkdb@]*\-

What is wrong with this?
#15
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?

Thanks in advance,
KeB
USA #16
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.
#17
Cool, many thanks sir.
Australia Forum Administrator #18
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.
USA #19
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.
Australia Forum Administrator #20
Oh, it's just he said he "tried a gradient fill".

If you want to simply modify the colour used in the existing fill, try:

Template:function=FilterPixel
FilterPixel

The documentation for the FilterPixel script function is available online. It is also in the MUSHclient help file.



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.
#21
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.

Thanks for all the help,
KeB
Amended on Sun 03 Jan 2010 11:18 PM by Keberus
USA #22
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.)
Amended on Sun 03 Jan 2010 11:45 PM by Twisol
#23
I guess I'm a bit confused. If you are talking about this line

win2 = GetPluginID ()

I thought GetPluginID() got a unique name/id for the window. If that's not the case, then how do you set the id of the windows?

Thanks,
KeB
USA #24
GetPluginID() gets the plugin's ID. You know, the part at the very beginning of the plugin's XML, in the <plugin> tag, called id="some stuff here".

You generally get a unique identifier by taking GetPluginID() and tacking something on to the end, like GetPluginID() .. "_gauge".
USA #25
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
Amended on Sun 03 Jan 2010 11:50 PM by Twisol
Australia Forum Administrator #26
Keberus said:

I guess I'm a bit confused. If you are talking about this line

win2 = GetPluginID ()

I thought GetPluginID() got a unique name/id for the window. If that's not the case, then how do you set the id of the windows?



If you want a whole bunch of unique IDs, you can use:

Template:function=GetUniqueID
GetUniqueID

The documentation for the GetUniqueID script function is available online. It is also in the MUSHclient help file.



This is what is used anyway to generate plugin IDs.

So, change:


win2 = GetPluginID ()


to:


win2 = GetUniqueID ()



Of course, Twisol's suggestion is perfectly fine, and is what I normally do anyway.
#27
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.

Thanks again,
KeB
USA #28
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.)
#29
Okay, didn't even realize there was a pastebin. Anywho, here's the link http://mushclient.pastebin.com/f66d2a798
Amended on Mon 04 Jan 2010 12:56 AM by Keberus
USA #30
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.
Amended on Mon 04 Jan 2010 01:01 AM by Twisol
#31
Alright, applied your suggested changes.

Thanks again,
KeB
#32
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'.

Thanks,
KeB
Australia Forum Administrator #33
Triggers fire on a newline, so you will have to add one if you want it to be the latest info.
#34
That's what I wanted to know.

Thanks,
USA #35
Nick,

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?

I eagerly wait a reply.

Sincerely,
Forral
Amended on Thu 14 Jan 2010 05:13 AM by forral
Australia Forum Administrator #36
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.
#37
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-



It shows adrenaline % in combat thats the A
Australia Forum Administrator #38
To show a bar it needs to know your current and maximum. Just seeing:


5932 health, 9292 endurance, 276 guile x A:100% -


... I wouldn't know if you are almost dead, 50% healthy or 100% healthy.


Can you change your prompt to something like:


5932/6000 health, 9292/11000 endurance, 276/300 guile x A:100% -


Then a simple change to the trigger would pick all that up.

Alternatively, it might have to change to deduce your maximum from the highest figure it ever sees.

For example, if your health is 5932, and is never seen to be higher, it might assume that 5932 is your maximum.
#39
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--


Am i outta luck? no status bar for me then?
Amended on Fri 12 Feb 2010 05:51 AM by Basyiel
#40
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.
Amended on Fri 12 Feb 2010 09:18 PM by Nick Gammon
Australia Forum Administrator #41
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).
Australia Forum Administrator #42
The version below uses the "score" command instead of guesswork. It has a multi-line trigger which matches the two lines:


Health: 6280/6280 Endurance: 9562/9562
Guile: 272/278


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").


Template:saveplugin=Health_Bar_Miniwindow2
To save and install the Health_Bar_Miniwindow2 plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. 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.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Health_Bar_Miniwindow2.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. 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>

#43
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

Thanks again :-)
Amended on Fri 12 Feb 2010 09:03 PM by Basyiel
Australia Forum Administrator #44
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.
Australia Forum Administrator #45
There are extra spaces in the score I didn't notice before because you didn't use the [code] forum code feature.

Maybe change the trigger match for the score to:


match="^Health\:\s+(\d+)\/(\d+)\s+Endurance\:\s+(\d+)\/(\d+)\nGuile:\s+(\d+)/(\d+)\Z"


That is allowing for more than one space between things.
#46
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 :-)
Amended on Fri 12 Feb 2010 10:37 PM by Basyiel
Australia Forum Administrator #47
Glad it's working!

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>
Amended on Sat 13 Feb 2010 02:18 AM by Nick Gammon
#48
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..
Australia Forum Administrator #49

You are welcome. :)

Here is what it looks like with the mouse-over - I think it looks pretty cute.

#50
I was wondering how to get the window balloon to put onto the other health bar mini-window.
Australia Forum Administrator #51
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.


Template:saveplugin=Health_Bar_Miniwindow
To save and install the Health_Bar_Miniwindow plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. 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.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Health_Bar_Miniwindow.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. 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="^\&lt;(\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>
#52
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.
USA #53
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 ;)


[1] http://img514.imageshack.us/img514/1741/leftside.png

[2] http://jonathan.com/?page_id=29
USA #54
I loaded it up for you anyways.

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.

^(?:\(p\) )?(\d+)h,? (?:(\d+)m,? )?(?:(\d+)e,? )?(?:(\d+)w,? )?(?:\d{1,3}%,? )?c?e?x?k?d?b?@? ?(?:Vote)?-


And now it works as expected. :)
#55
How would I change this trigger to gag the line it matched from the client?
#56
Ignore me, figured it out for myself.

Answer was: omit_from_output="y"
#57
I am attempting to modify the plugin a bit, to suit my needs (and the limitations of the game).

Prompt when using command "hp":
HP:###/###  SP:###/###  EP:###/###


Prompt appended to end of every attack action done by self during combat:
HP:###  SP:###  EP:### TargetInfo


That's the info on the game. Here are a couple specific examples from my log files.

HP:192/192  SP:192/256  EP:148/148
HP:192  SP:150  EP:77 Boar(nearly dead)


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"


<triggers>
  <trigger
   enabled="y"
   match="HP\:(.*?)\/(.*?)  SP\:(.*?)\/(.*?)  EP\:(.*?)\/(.*?)$"
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="HP\:(.*?)  SP\:(.*?)  EP\:(.*?) .*"
   regexp="y"
   script="do_prompt2"
   sequence="100"
  >
  </trigger>
</triggers>


function do_prompt (name, line, wildcards)

  local hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
  local sp, max_sp = tonumber (wildcards [3]), tonumber (wildcards [4])
  local ep, max_ep = tonumber (wildcards [5]), tonumber (wildcards [6])
    
  local hp_percent = hp / max_hp
  local sp_percent = sp / max_sp
  local ep_percent = ep / max_ep

  -- 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 ("SP: ", sp_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("EP: ", ep_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)
  
end -- draw_bar

function do_prompt2 (name, line, wildcards)

  local hp = tonumber (wildcards [1])
  local sp = tonumber (wildcards [2])
  local ep = tonumber (wildcards [3])
    
  local hp_percent = hp / max_hp
  local sp_percent = sp / max_sp
  local ep_percent = ep / max_ep

  -- 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 ("SP: ", sp_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("EP: ", ep_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)
  
end -- draw_bar


Have I set it up correctly? Do the "max" values carry over between prompts? :x
Australia Forum Administrator #58
No. Get rid of the word "local" on the (3) lines which get the maxima. Otherwise those variables only last for that function.
#59

<triggers>
  <trigger
   enabled="y"
   match="^HP\:(\d+)\/(\d+)  SP\:(\d+)\/(\d+)  EP\:(\d+)\/(\d+)$"
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^HP\:(\d+)  SP\:(\d+)  EP\:(\d+) .*"
   regexp="y"
   script="do_prompt2"
   sequence="100"
  >
  </trigger>
</triggers>


Is this trigger matching set up correctly?


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.
Amended on Sun 06 Feb 2011 05:52 AM by Caelen
Australia Forum Administrator #60
You have a lot of duplication. I would move the repeated stuff into another function:


function draw_the_bars ()
  local hp_percent = hp / max_hp
  local sp_percent = sp / max_sp
  local ep_percent = ep / max_ep

  -- 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 ("SP: ", sp_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("EP: ", ep_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)

end -- draw_the_bars

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])
    
  draw_the_bars ()
  
end -- do_prompt 

function do_prompt2 (name, line, wildcards)

  hp = tonumber (wildcards [1])
  sp = tonumber (wildcards [2])
  ep = tonumber (wildcards [3])

  draw_the_bars ()
      
end -- do_prompt2


The font stuff looks OK. Why not test it and see?
Amended on Sun 06 Feb 2011 05:56 AM by Nick Gammon
#61
Yay, it all works :D Thanks for the help ^^
#62
And now it doesn't work :/

http://i1224.photobucket.com/albums/ee371/AvilonRayne/GuageFail.png

Empty gauge window. :(


<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])
  sp, max_sp = tonumber (wildcards [3]), tonumber (wildcards [4])
  ep, max_ep = tonumber (wildcards [5]), tonumber (wildcards [6])
    
  draw_the_bars ()
  
end -- do_prompt 

function do_prompt2 (name, line, wildcards)

  hp = tonumber (wildcards [1])
  sp = tonumber (wildcards [2])
  ep = tonumber (wildcards [3])

  draw_the_bars ()
      
end -- do_prompt2

function draw_the_bars ()
  local hp_percent = hp / max_hp
  local sp_percent = sp / max_sp
  local ep_percent = ep / max_ep

  -- 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 ("SP: ", sp_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("EP: ", ep_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)

end -- draw_the_bars



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 = "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
  
  -- 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, "SP: "))
  gauge_left = math.max (gauge_left,  WindowTextWidth (win, font_id, "EP: "))
  
  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 sp and max_sp and ep and max_ep then
    do_prompt ("", "", { hp, max_hp, sp, max_sp, ep, max_ep } )
  end -- if know hp, sp and ep
end -- OnPluginEnable

function OnPluginSaveState ()
   -- save window current location for next time  
  movewindow.save_state (win)
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>
Australia Forum Administrator #63
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:


function DoGauge (sPrompt, current, max, Colour)


-- add this:

print ("In DoGauge, prompt=", sPrompt, "current=", current,
          "max=", max)



That might clarify what it is doing.
#64

HP:204/204  SP:272/272  EP:155/155
In DoGauge, prompt= HP:  current= 1 max= 25600
In DoGauge, prompt= SP:  current= 1 max= 13434880
In DoGauge, prompt= EP:  current= 1 max= 55295


*boggles*

edit: the triggers section

<triggers>
  <trigger
   enabled="y"
   match="^HP\:(\d+)\/(\d+)  SP\:(\d+)\/(\d+)  EP\:(\d+)\/(\d+)$"
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^HP\:(\d+)  SP\:(\d+)  EP\:(\d+) .*"
   regexp="y"
   script="do_prompt2"
   sequence="100"
  >
  </trigger>
</triggers>


edit 2: more testing!


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?
Amended on Thu 10 Feb 2011 10:00 AM by Caelen
Australia Forum Administrator #65
Well let's see now ...


function DoGauge (sPrompt, current, max, Colour)


That is expecting 4 arguments.

You are sending it:


DoGauge ("HP: ", hp_percent,  ColourNameToRGB "darkgreen")


That's 3 arguments, including the colour code.

So, current will be 204/204 (that is, 1) and ColourNameToRGB ("darkgreen") gives 25600, so that's where the figures come from.

Did you change the way you called DoGauge?
#66
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
Amended on Thu 10 Feb 2011 11:23 AM by Caelen
#67
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! =)
#68
Run-time error
Plugin: Health_Bar_Miniwindow (called from world: Mage)
Function/Sub: do_prompt called by trigger
Reason: processing trigger ""
[string "Plugin"]:110: attempt to perform arithmetic on local 'hp' (a nil value)
stack traceback:
[string "Plugin"]:110: in function <[string "Plugin"]:104>
Error context in script:
106 : local hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
107 : local mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
108 : local move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
109 :
110*: local hp_percent = hp / max_hp
111 : local mana_percent = mana / max_mana
112 : local move_percent = move / max_move
113 :
114 : -- fill entire box to clear it


Player saved.

[116/116hp|122/122mp|100/100mv]
Trigger function "do_prompt" not found or had a previous error.
#69
Thats the error i got.
Australia Forum Administrator #70
What is the trigger?
#71
^(.*?)\[(.*?)\/(.*?)hp\|(.*?)\/(.*?)mp\|(.*?)\/(.*?)mv\]$


thats the regular expression i'm using for my prompt....
Australia Forum Administrator #72
Those extra brackets threw out the wildcard numbers. When I checked them I got:


1 
2 116
3 116
4 122
5 122
6 100


Wildcard 1 was empty.

Either change the regexp to:


^.*?\[(.*?)\/(.*?)hp\|(.*?)\/(.*?)mp\|(.*?)\/(.*?)mv\]$


OR change the code in the plugin to read:


local hp, max_hp = tonumber (wildcards [2]), tonumber (wildcards [3])
local mana, max_mana = tonumber (wildcards [4]), tonumber (wildcards [5])
local move, max_move = tonumber (wildcards [6]), tonumber (wildcards [7])


(I added 1 to each wildcard number).
Amended on Wed 01 Jun 2011 07:03 AM by Nick Gammon
#73
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?
#74
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?
Amended on Wed 01 Jun 2011 08:05 AM by Renox Dashin
Australia Forum Administrator #75
Did you reinstall the plugin? And only do one suggestion, not both of them.
#76
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]



how can i make this work? without the MV
Australia Forum Administrator #77
The plugin was supposed to be a guide to the general idea. To get rid of the MV part, look for these lines:


 DoGauge ("HP: ",    hp ,   max_hp,    ColourNameToRGB "darkgreen")
 DoGauge ("Mana: ",  mana,  max_mana,  ColourNameToRGB "mediumblue")
 DoGauge ("Move: ",  move,  max_move,  ColourNameToRGB "gold")


Delete the last line.

And for the asterisks (which will make it fail) change the regexp to match on digits, eg.


^.*?\[(\d+)\/(\d+)hp\|(\d+)\/(\d+)mp\|(\d+)\/(\d+)mv\]$



The \d+ thing matches on one or more digits (so it won't match on an asterisk.

And no, you don't need a plugin per prompt. Just add another trigger to the existing plugin to match the different prompt, the rest being the same.

So you would have:


<triggers>
  <trigger
   enabled="y"
   match="first prompt whatever it is"
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>

<triggers>
  <trigger
   enabled="y"
   match="second prompt whatever it is"
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>


Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.
Amended on Wed 01 Jun 2011 08:32 AM by Nick Gammon
#78
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 %
Australia Forum Administrator #79
Er, well, how do *you* know your group's health? Can you post some example prompts?

Making a script is basically taking information that you normally see, and getting a trigger to capture that.
#80
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.
Australia Forum Administrator #81
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.
#82
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 :(
Australia Forum Administrator #83
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:

http://www.gammon.com.au/forum/?bbtopic_id=120

It validates the time I have taken to produce those, if people look at them, and experiment with the ideas shown there.
USA #84
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.
Australia Forum Administrator #85
If you open world configuration, and near the bottom at the Variables tab, do you see the variable "MaxEnd"?
USA #86
Yes, I do.

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.
Australia Forum Administrator #87
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".

However it can be done.

Template:function=GetPluginVariable
GetPluginVariable

The documentation for the GetPluginVariable script function is available online. It is also in the MUSHclient help file.



If you call that with an empty string as the plugin ID then you will get the main world variable. eg.


maxend = GetPluginVariable ("", "MaxEnd")


You don't need to use tostring, GetVariable always returns strings (or nil if the variable doesn't exist).
USA #88
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!
#89
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]


Script:
To follow
Amended on Fri 23 Sep 2011 11:14 PM by Nick Gammon
#90
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>
#91
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?

so instead it would read

- <triggers>
<trigger enabled="y" match="promptbar"

Then I would make a trigger called promptbar and have it fire on

HP%1/%2 M%3/%4 MV%5/%6 ST%7/%8

That would work if my staus bar read as above, right?
Australia Forum Administrator #92
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?
#93
Nick Gammon said:

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.



USA Global Moderator #94
Quote:
I don't have a mud output...

Uhhh...yes you do. Copy and paste what the game sends you.
Netherlands #95
what lines would i have to add to show an hunger bar and a thirst bar in the same window?
USA Global Moderator #96
Quote:

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.
Netherlands #97
ah, i see. that would mean an updating plugin using some invisible 'hunger' syntax every tick :P fun to look into.
would make a nice first assignment.