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

Improved health bar plugin - can be dragged around

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


Pages: 1  2  3  4 5  6  7  

Posted by Nick Gammon   Australia  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #45 on 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 Basyiel   (10 posts)  [Biography] bio
Date Reply #46 on 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  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #47 on 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 Reply #48 on 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  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #49 on 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 Crowe   (21 posts)  [Biography] bio
Date Reply #50 on 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  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #51 on 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 Indico   (16 posts)  [Biography] bio
Date Reply #52 on 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 Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #53 on 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 Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #54 on 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 Gorgar   (2 posts)  [Biography] bio
Date Reply #55 on Fri 31 Dec 2010 04:07 PM (UTC)  quote  ]
Message
How would I change this trigger to gag the line it matched from the client?
[Go to top] top

Posted by Gorgar   (2 posts)  [Biography] bio
Date Reply #56 on Fri 31 Dec 2010 04:33 PM (UTC)  quote  ]
Message
Ignore me, figured it out for myself.

Answer was: omit_from_output="y"
[Go to top] top

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #57 on Sun 06 Feb 2011 05:19 AM (UTC)  quote  ]
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #58 on Sun 06 Feb 2011 05:44 AM (UTC)  quote  ]
Message
No. Get rid of the word "local" on the (3) lines which get the maxima. Otherwise those variables only last for that function.

- Nick Gammon

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #59 on Sun 06 Feb 2011 05:51 AM (UTC)  quote  ]

Amended on Sun 06 Feb 2011 05:52 AM (UTC) by Caelen

Message

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


64,752 views.

This is page 4, subject is 7 pages long:  [Previous page]  1  2  3  4 5  6  7  [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]