Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Plugins ➜ 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 page


Pages: 1  2  3  4  5 6  7  

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #60 on Sun 06 Feb 2011 05:55 AM (UTC)

Amended on Sun 06 Feb 2011 05:56 AM (UTC) by Nick Gammon

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #61 on Sun 06 Feb 2011 05:58 PM (UTC)
Message
Yay, it all works :D Thanks for the help ^^
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #62 on Thu 10 Feb 2011 05:11 AM (UTC)
Message
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>
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #63 on Thu 10 Feb 2011 05:58 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #64 on Thu 10 Feb 2011 08:02 AM (UTC)

Amended on Thu 10 Feb 2011 10:00 AM (UTC) by Caelen

Message

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

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #65 on Thu 10 Feb 2011 10:54 AM (UTC)
Message
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?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #66 on Thu 10 Feb 2011 11:18 AM (UTC)

Amended on Thu 10 Feb 2011 11:23 AM (UTC) by Caelen

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

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #67 on Wed 01 Jun 2011 05:15 AM (UTC)
Message
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! =)
Top

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #68 on Wed 01 Jun 2011 05:32 AM (UTC)
Message
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.
Top

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #69 on Wed 01 Jun 2011 05:33 AM (UTC)
Message
Thats the error i got.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #70 on Wed 01 Jun 2011 05:53 AM (UTC)
Message
What is the trigger?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #71 on Wed 01 Jun 2011 05:56 AM (UTC)
Message
^(.*?)\[(.*?)\/(.*?)hp\|(.*?)\/(.*?)mp\|(.*?)\/(.*?)mv\]$


thats the regular expression i'm using for my prompt....
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #72 on Wed 01 Jun 2011 07:02 AM (UTC)

Amended on Wed 01 Jun 2011 07:03 AM (UTC) by Nick Gammon

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #73 on Wed 01 Jun 2011 07:15 AM (UTC)
Message
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?
Top

Posted by Renox Dashin   (17 posts)  Bio
Date Reply #74 on Wed 01 Jun 2011 07:19 AM (UTC)

Amended on Wed 01 Jun 2011 08:05 AM (UTC) by Renox Dashin

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


296,341 views.

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

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

Go to topic:           Search the forum


[Go to top] top

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