[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Improved health bar plugin - can be dragged around

Improved health bar plugin - can be dragged around

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  3  4  5  6  7  

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Tue 24 Feb 2009 03:08 AM (UTC)

Amended on Wed 19 Aug 2009 06:46 AM (UTC) by Nick Gammon

Message
Below is an improved health-bar plugin. It uses a trigger that works off standard SMAUG prompts, providing you change them a bit to show the maximum health, mana and movement points.

For example:


prompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp> 
fprompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp> 


This plugin shows a nice 3D-looking health bar, with tick marks, and has the advantage it can be dragged around the output window. Simply click anywhere in it, drag it to a new location, and let go.

The new location is remembered in the plugin state file for next time you use it.

The plugin requires MUSHclient 4.40 (or above), which allows dragging miniwindows around. For a copy of version 4.40, see: http://www.gammon.com.au/forum/?id=9264

Below is the plugin.

Template:saveplugin=Health_Bar_Miniwindow To save and install the Health_Bar_Miniwindow plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Health_Bar_Miniwindow.xml
  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"




<?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>



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 24 Feb 2009 03:08 AM (UTC)
Message

Example of it in operation:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Tue 24 Feb 2009 03:13 AM (UTC)
Message
If you like a bigger window, just change WINDOW_WIDTH inside the plugin.

For example, I tried a larger window:


WINDOW_WIDTH = 400



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 24 Feb 2009 03:13 AM (UTC)
Message

That gave this result:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Keith   (21 posts)  [Biography] bio
Date Reply #4 on Wed 13 May 2009 08:45 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 14 May 2009 04:12 AM (UTC)
Message
Can you show an example of your prompt please? If the trigger doesn't match then it won't display the health bars.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Keith   (21 posts)  [Biography] bio
Date Reply #6 on Thu 14 May 2009 04:31 AM (UTC)
Message
My prompt is <100% 100% 100% 76(0) 73%% NEW>

[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 14 May 2009 06:21 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Syrius   (4 posts)  [Biography] bio
Date Reply #8 on Tue 03 Nov 2009 06:42 PM (UTC)
Message
Is there a way to display perhaps endurance and willpower along with the health and mana and remove movement points from the bar?
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #9 on Tue 03 Nov 2009 09:56 PM (UTC)
Message
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?
[Go to top] top

Posted by Syrius   (4 posts)  [Biography] bio
Date Reply #10 on Tue 03 Nov 2009 11:50 PM (UTC)
Message
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.
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #11 on Wed 04 Nov 2009 12:37 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Wed 04 Nov 2009 04:14 AM (UTC)

Amended on Wed 04 Nov 2009 04:15 AM (UTC) by Nick Gammon

Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Syrius   (4 posts)  [Biography] bio
Date Reply #13 on Thu 05 Nov 2009 12:15 AM (UTC)
Message
Great! Thank you guys a lot. I'll dabble with this a bit.
[Go to top] top

Posted by Syrius   (4 posts)  [Biography] bio
Date Reply #14 on Fri 06 Nov 2009 02:56 AM (UTC)
Message
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?
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


265,971 views.

This is page 1, subject is 7 pages long: 1 2  3  4  5  6  7  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]