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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Improved health bar plugin - can be dragged around
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Improved health bar plugin - can be dragged around
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  

Posted by Twisol   USA  (1,483 posts)  [Biography] bio
Date Sat 20 Feb 2010 05:56 PM (UTC)  quote  ]
Message
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. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (1,483 posts)  [Biography] bio
Date Sat 20 Feb 2010 05:36 PM (UTC)  quote  ]
Message
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

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Indico   (16 posts)  [Biography] bio
Date Sat 20 Feb 2010 11:16 AM (UTC)  quote  ]
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Sat 13 Feb 2010 09:00 PM (UTC)  quote  ]
Message
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 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="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>

- Nick Gammon

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

Posted by Crowe   (11 posts)  [Biography] bio
Date Sat 13 Feb 2010 02:57 PM (UTC)  quote  ]
Message
I was wondering how to get the window balloon to put onto the other health bar mini-window.
[Go to top] top

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Sat 13 Feb 2010 05:35 AM (UTC)  quote  ]
Message

You are welcome. :)

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


- Nick Gammon

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

Posted by Basyiel   (10 posts)  [Biography] bio
Date Sat 13 Feb 2010 01:40 AM (UTC)  quote  ]
Message
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..
[Go to top] top

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Sat 13 Feb 2010 01:14 AM (UTC)  quote  ]

Amended on Sat 13 Feb 2010 02:18 AM (UTC) by Nick Gammon

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

- Nick Gammon

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

Posted by Basyiel   (10 posts)  [Biography] bio
Date Fri 12 Feb 2010 09:57 PM (UTC)  quote  ]

Amended on Fri 12 Feb 2010 10:37 PM (UTC) by Basyiel

Message
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 :-)
[Go to top] top

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Fri 12 Feb 2010 09:20 PM (UTC)  quote  ]
Message
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.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Fri 12 Feb 2010 09:18 PM (UTC)  quote  ]
Message
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.

- Nick Gammon

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

Posted by Basyiel   (10 posts)  [Biography] bio
Date Fri 12 Feb 2010 08:15 PM (UTC)  quote  ]

Amended on Fri 12 Feb 2010 09:03 PM (UTC) by Basyiel

Message
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 :-)
[Go to top] top

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Fri 12 Feb 2010 07:22 PM (UTC)  quote  ]
Message
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 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_Miniwindow2.xml
  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"



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


- Nick Gammon

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

Posted by Nick Gammon   Australia  (15,754 posts)  [Biography] bio
Date Fri 12 Feb 2010 07:08 PM (UTC)  quote  ]
Message
My first attempt is to assume the maxima are the largest figures you ever see (eg. when you are at full health), like this:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Health_Bar_Miniwindow2"
   author="Nick Gammon"
   id="78dcd04fc1096e8988f03892"
   language="Lua"
   purpose="Shows stats in a mini window"
   date_written="2010-02-12"
   requires="4.40"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Endurance, 
and Guile points shown as a bar.

The window can be dragged to a new location with the mouse.
]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^(\d+)h, (\d+)e, (\d+)g "
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   match="^maxima (\d+) (\d+) (\d+)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
max_hp = %1
max_endurance = %2
max_guile = %3

-- draw gauge again if possible
if hp and endurance and guile then
  do_prompt ("", "", { hp, endurance, guile } )
end -- if know hp, endurance and guile

</send>
  </alias>
</aliases>


<!--  Script  -->


<script>
<![CDATA[

GAUGE_HEIGHT = 15

WINDOW_WIDTH = 300
WINDOW_HEIGHT = 65
NUMBER_OF_TICKS = 5

BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"

function DoGauge (sPrompt, Percent, Colour)

  local Fraction = tonumber (Percent)
  
  if Fraction > 1 then Fraction = 1 end
  if Fraction < 0 then Fraction = 0 end
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt, gauge_left - width, vertical, 0, 0, FONT_COLOUR)

  WindowRectOp (win, 2, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
                          BACKGROUND_COLOUR)  -- fill entire box
 
  
  local gauge_width = (WINDOW_WIDTH - gauge_left - 5) * Fraction
  
   -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (gauge_width) > 0 then
    
    -- top half
    WindowGradient (win, gauge_left, vertical, gauge_left + gauge_width, vertical + GAUGE_HEIGHT / 2, 
                    0x000000,
                    Colour, 2) 
    
    -- bottom half
    WindowGradient (win, gauge_left, vertical + GAUGE_HEIGHT / 2, 
                    gauge_left + gauge_width, vertical +  GAUGE_HEIGHT,   
                    Colour,
                    0x000000,
                    2) 

  end -- non-zero
  
  -- show ticks
  local ticks_at = (WINDOW_WIDTH - gauge_left - 5) / (NUMBER_OF_TICKS + 1)
  
  -- ticks
  for i = 1, NUMBER_OF_TICKS do
    WindowLine (win, gauge_left + (i * ticks_at), vertical, 
                gauge_left + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
  end -- for

  -- draw a box around it
  check (WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
          ColourNameToRGB ("lightgrey")))  -- frame entire box
  
  vertical = vertical + font_height + 3
end -- function

function do_prompt (name, line, wildcards)

  hp = tonumber (wildcards [1])
  endurance = tonumber (wildcards [2])
  guile = tonumber (wildcards [3])
    
  -- guess maxima
  max_hp = math.max (hp, max_hp)
  max_endurance = math.max (endurance, max_endurance)
  max_guile = math.max (guile, max_guile)
  
  local hp_percent = hp / max_hp
  local endurance_percent = endurance / max_endurance
  local guile_percent = guile / max_guile

  -- fill entire box to clear it
  check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR))  -- fill entire box
  
  -- Edge around box rectangle
  check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))

  vertical = 6  -- pixel to start at

  DoGauge ("HP: ",   hp_percent,    ColourNameToRGB "darkgreen")
  DoGauge ("Endurance: ", endurance_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("Guile: ", guile_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)
  
end -- draw_bar


function OnPluginInstall ()
  
  win = GetPluginID ()
  font_id = "fn"
  
  require "movewindow"  -- load the movewindow.lua module

  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 7)  -- default to 7 (on right, center top/bottom)
                   
  font_name = "Fixedsys"    -- the font

  -- get maxima from last time
  max_hp, max_endurance, max_guile = 
      tonumber (GetVariable ("max_hp")) or 0,
      tonumber (GetVariable ("max_endurance")) or 0,
      tonumber (GetVariable ("max_guile")) or 0
    
  -- make miniwindow so I can grab the font info
  check (WindowCreate (win, 
                 windowinfo.window_left,
                 windowinfo.window_top,
                 WINDOW_WIDTH, 
                 WINDOW_HEIGHT,  
                 windowinfo.window_mode,   
                 windowinfo.window_flags,   
                 BACKGROUND_COLOUR) )

  -- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, 0)
                 
  check (WindowFont (win, font_id, font_name, 9, false, false, false, false, 0, 0))  -- normal
  
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  
  -- work out how far in to start the gauge
  gauge_left = WindowTextWidth (win, font_id, "HP: ")
  gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Endurance: "))
  gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Guile: "))
  gauge_left = gauge_left + 5  -- allow gap from edge
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
 
end -- OnPluginInstall

function OnPluginDisable ()
  WindowShow (win, false)
end -- OnPluginDisable

function OnPluginEnable ()
  WindowShow (win, true)
  -- draw gauge again if possible
  if hp and endurance and guile then
    do_prompt ("", "", { hp, endurance, guile } )
  end -- if know hp, endurance and guile
end -- OnPluginEnable

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


]]>
</script>

</muclient>


The lines in bold above set your maxima to whatever the largest you ever see is.

This should work OK, but might fail if your health temporarily went higher than usual (eg. a buff). So I added an alias, which you can type to reset the maxima like this:



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

- Nick Gammon

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

Posted by Basyiel   (10 posts)  [Biography] bio
Date Fri 12 Feb 2010 05:57 PM (UTC)  quote  ]

Amended on Fri 12 Feb 2010 09:18 PM (UTC) by Nick Gammon

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


10,000 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]