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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Health and Experience and Bars, oh my!

Health and Experience and Bars, oh my!

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


Pages: 1 2  3  4  

Posted by Caelen   (81 posts)  [Biography] bio
Date Thu 10 Feb 2011 08:45 PM (UTC)

Amended on Thu 10 Feb 2011 08:48 PM (UTC) by Caelen

Message
I took a shot at combining the health and experience bar plugins into a single, one-window plugin. So far, I have met with a lot of success! I have, however, hit one snag. I can't figure out how to separate the draw_the_bars function in a way that will let me draw the hp/sp/ep gauges whenever I get the prompt, while also drawing the experience/money gauges whenever I use the commands that display my XP and CP. With no prompt configuration available, I can't use the easy route of a single trigger. So! I made a lot of triggers. The triggers work, they all return the values I need, and the draw_the_bars function is sending the right information to the DoGauge function. How do I separate it all out to redraw the xp/cp bars without erasing the hp/sp/ep bars?

Here are a couple snips from my script.
These triggers grab the values I need to level.

  <trigger
   enabled="y"
   match="^LEVEL (\d+) ADVANCEMENT$"
   regexp="y"
   script="do_prompt_level"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^Advancement will cost (\d+) experience and (\d+) coppers\.$"
   regexp="y"
   script="do_prompt_cost"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^You will need (\d+) more experience and (\d+) more coppers\.$"
   regexp="y"
   script="do_prompt_tnl"
   sequence="100"
  >
  </trigger>


These functions store the values.

function do_prompt_level (name, line, wildcards)

  next_level = tonumber (wildcards [1])
  level = next_level - 1
  
end -- do_prompt_level

function do_prompt_cost (name, line, wildcards)

  max_xp = tonumber (wildcards [1])
  max_cp = tonumber (wildcards [2])
  
end -- do_prompt_cost

function do_prompt_tnl (name, line, wildcards)

  tnl_xp = tonumber (wildcards [1])
  tnl_cp = tonumber (wildcards [2])
  xp = max_xp - tnl_xp
  cp = max_cp - tnl_cp
  
end -- do_prompt_tnl


This function draws it all, and is only called by my hp/sp/ep functions.

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 "red")
  DoGauge ("XP: ",  xp,  max_xp,  ColourNameToRGB "darkviolet")
  DoGauge ("CP: ",  cp,  max_cp,  ColourNameToRGB "gold")

  WindowShow (win, true)

end -- draw_the_bars


I tried splitting out the xp and cp parts into a second draw_the_xp_bars function, but when that was called it would erase my hp/sp/ep bars, which I don't want to do. I'd also like to somehow get the XP bar display to show "L5: " (or whatever my current level is) instead of "XP: ", which is why that first trigger and function is in there. Any idea how I can get this mess to work?

edit: Something I tried earlier was having the xp/cp triggers also call the draw_the_bars function, but when first installing the plugin, those values aren't all there, so it can't draw the bars!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 11 Feb 2011 03:16 AM (UTC)
Message
Just omit the line where it does the "fill entire box to clear it" (the line, not the comment) and then just draw each bar as you get it. I don't think clearing the bars is critical, as you are drawing over them anyway.

- Nick Gammon

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #2 on Fri 11 Feb 2011 04:38 AM (UTC)

Amended on Fri 11 Feb 2011 04:39 AM (UTC) by Caelen

Message
success! now I can draw either set of bars in the single large window :D


function draw_the_bars ()
  
  -- 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 "red")

  WindowShow (win, true)

end -- draw_the_bars

function draw_the_xp_bars ()
  
  -- Edge around box rectangle
  check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))

  vertical = 64  -- pixel to start at

  DoGauge ("XP: ",  xp,  max_xp,  ColourNameToRGB "darkviolet")
  DoGauge ("CP: ",  cp,  max_cp,  ColourNameToRGB "gold")

  WindowShow (win, true)

end -- draw_the_xp_bars


I'd still like to figure out how to change the "XP" part to read "L#" though... any ideas?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 11 Feb 2011 07:58 PM (UTC)
Message
I'm not sure I understand the question. You mean to change the label?

- Nick Gammon

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #4 on Fri 11 Feb 2011 08:02 PM (UTC)
Message
Right, change the label to be a variable. I don't know how to include variables inside quotes, if that's even possible.
[Go to top] top

Posted by NWAplayer   (1 post)  [Biography] bio
Date Reply #5 on Sat 12 Feb 2011 03:05 AM (UTC)
Message
Is there any way to get that full script for what you are doing posted here please?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sat 12 Feb 2011 04:02 AM (UTC)
Message
Caelen said:

Right, change the label to be a variable. I don't know how to include variables inside quotes, if that's even possible.


Do you mean:


DoGauge ("L#: ",  xp,  max_xp,  ColourNameToRGB "darkviolet")


Or if you want to "include a variable inside quotes" you can do something like this:


myvar = "foo"
DoGauge (myvar .. ": ",  xp,  max_xp,  ColourNameToRGB "darkviolet")


That concatenates a variable (myvar) with stuff in quotes.

- Nick Gammon

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #7 on Sat 12 Feb 2011 05:06 AM (UTC)

Amended on Sat 12 Feb 2011 06:44 AM (UTC) by Caelen

Message
Nick Gammon said:

That concatenates a variable (myvar) with stuff in quotes.


Exactly what I want :D assuming I'm interpreting what "concatenates" means correctly :x Thanks!
-checks google to see what it actually means-

edit: Indeed, does exactly what I want :D
[Go to top] top

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #8 on Sat 12 Feb 2011 09:39 PM (UTC)
Message
So! The plugin is a hit with everyone on Ateraan XD I now have some fun requests I'm trying to do!

Project one: Catch the experience gain from introductions and bonuses. The text is always the same sentence, and I know how to make it accept all the possible variables... but, the problem is that it's multiple lines. Is there a way to tell the client to "catch this sentence, ignoring extra spaces (indents), and trigger"?


Kethlyn tells you her name and a lot about herself. You feel
enlightened by the information and gain 2900 experience from the encounter.

Sythrivum tells you his name. You feel some enlightenment and gain 1100
experience from the encounter.


----------------

Project 2: Make the window more transparent! Several people don't like how much space it takes up, or don't like how it blocks some of the view. Is there a way to make the background clear, so that text can be read through it, and make the gauges themselves transparent as well?

----------------

Project 3: Expanded configuration. This one I know how to do, it's just a matter of doing it. I'm planning on pulling all the options I like tinkering with, like the font and colors and such, into the configuration.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Sat 12 Feb 2011 11:57 PM (UTC)
Message
Caelen said:
Project one: Catch the experience gain from introductions and bonuses. The text is always the same sentence, and I know how to make it accept all the possible variables... but, the problem is that it's multiple lines. Is there a way to tell the client to "catch this sentence, ignoring extra spaces (indents), and trigger"?


Kethlyn tells you her name and a lot about herself. You feel
enlightened by the information and gain 2900 experience from the encounter.

Sythrivum tells you his name. You feel some enlightenment and gain 1100
experience from the encounter.

Even though it's possible, it's not exactly clean or easy to do. It would be orders of magnitude easier if there were a config option for your MUD to disable line wrapping; on Achaea we have 'config screenwidth 0'.


Caelen said:
Project 2: Make the window more transparent! Several people don't like how much space it takes up, or don't like how it blocks some of the view. Is there a way to make the background clear, so that text can be read through it, and make the gauges themselves transparent as well?

As far as I recall, window pixels can only be 100% opaque or 100% transparent. Images have lots of leeway, but at some point they need to be drawn onto the window, and window pixels are all-or-nothing.

Caelen said:
Project 3: Expanded configuration. This one I know how to do, it's just a matter of doing it. I'm planning on pulling all the options I like tinkering with, like the font and colors and such, into the configuration.

Sounds like a great idea. I personally like having a separate file for configuration, but if you'd like to keep everything in one file that's fine too.

'Soludra' on Achaea

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #10 on Sun 13 Feb 2011 06:42 AM (UTC)
Message
How can I make the window 100% transparent?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #11 on Sun 13 Feb 2011 11:25 AM (UTC)
Message
100% transparent means the window itself is totally invisible. I don't think that's what you want. Window transparency is mostly only useful for making your windows into non-square shapes.

MUSHclient miniwindows use something called chroma-keying to implement transparency. What this means is, if a pixel on the window is a specific color, it will draw whatever's underneath it instead. So to use this, you need to pass flag 4 to WindowCreate(), so the background color you specify is the color marking transparency.

Template:function=WindowCreate WindowCreate

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



I'm guessing you want the window to blend with the background, which means making pixels on the window semitransparent. Unfortunately that's not possible. (Believe me, I'd like that too.)

'Soludra' on Achaea

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #12 on Fri 25 Feb 2011 11:00 PM (UTC)
Message
Not quite wanting it to blend, actually... what I want is opaque gauges with an invisible background. Rather than a background color of "black", I want no background at all. So, only the box around the gauge (including ticks), the text to the left of it, and the colored bar the fills the gauge will be visible.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Fri 25 Feb 2011 11:08 PM (UTC)
Message
That's pretty easy then. Just pick a color you think you'll never ever use, set it as the window background in WindowCreate, and pass the transparency flag (4) to WindowCreate as well. For example, if you picked #0F0532, then any window pixel with a value of #0F0532 will be replaced with the pixel behind it.

'Soludra' on Achaea

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

Posted by Caelen   (81 posts)  [Biography] bio
Date Reply #14 on Sat 26 Feb 2011 12:40 AM (UTC)
Message
Twisol said:

That's pretty easy then. Just pick a color you think you'll never ever use, set it as the window background in WindowCreate, and pass the transparency flag (4) to WindowCreate as well. For example, if you picked #0F0532, then any window pixel with a value of #0F0532 will be replaced with the pixel behind it.



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)
    
  -- 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, FONT_SIZE)
  font_height = WindowFontInfo (win, font_id, 1)  -- height


How do I get at the "windowinfo.window_flags" to make it "4"? Do I just change it to 4?
[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.


110,542 views.

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