ID:113906
 
Stat Bar Overlays by DarkCampainger
Quickly add overlay stat bars for health, mana, experience--anything!
4 fans · Created May 31 2011
This library allows you to quickly create stat bar overlays for any of your variables. It even tracks which variables are associated with it, so you can just call Update()--with no parameter passing--and it takes care of the rest!

Demo implementation included.

////////////////////////
// //
// STAT BAR OVERLAYS //
// VERSION 0.6 //
// BY DARKCAMPAINGER //
// //
// REFERENCE //
// //
////////////////////////
//
// > Create a new bar overlay
//
new/bar_overlay(atom/owner, icon, states, var_stat, var_max, \
layer=FLOAT_LAYER, pixel_x=0, pixel_y=0, state_prefix="", \
timeout=0, auto_show=null, hide=null)
//
// > Arguments: (supports named arguments)
//
// - owner: the atom the bar is attached to
// - icon: icon to use for the bar
// - states: number of states, or levels, in the icon (optional)
// - var_stat: name of the variable that holds the stat
// - var_max: name of the variable that holds the stat's max value
// - (layer): layer to place the bar on (optional)
// - (pixel_x): pixel_x offset of the bar (optional)
// - (pixel_y): pixel_y offset of the bar (optional)
// - (state_prefix): prefix for bar's icon_states (optional)
// - (timeout): number of ticks to auto-hide bar after (optional)
// - (auto_show): whether to show bar on calls to Update() (optional)
// - (hide): whether to initially hide bar on creation (optional)
//
// All properties (except owner) can alternatively be defined at compile-time
// under a /bar_overlay subtype, at which point they become optional above
//
// > Returns:
//
// New bar_overlay attached to the specified owner, displaying percentage
// of [var_stat]/[var_max]. Uses states "[state_prefix]1" through
// "[state_prefix][states]" of [icon].
//
// > Update an existing bar overlay
//
bar_overlay/Update(_unused=null, force_show=null, force_timeout=null)
//
// > Arguments:
//
// - [_unused]: previously force_update, no longer needed, left for
// backwards compatibility
// - [force_show]: set to a true value to force the bar to be shown even
// if it is currently hidden (overrides bar's auto_show var)
// - [force_timeout]: set to number of ticks to timeout after and auto-hide
// (overrides bar's timeout var)
//
// > Show a bar overlay
//
bar_overlay/Show(force_timeout=null)
//
// > Arguments:
//
// - [force_timeout]: set to number of ticks to timeout after and auto-hide
// (overrides bar's timeout var)
//
// > Hide a bar overlay
//
bar_overlay/Hide()
//
//


Update History:

Version 0.6 (October 5th, 2013)

Fixed bug where calling Show() wouldn't have any effect if Update() hadn't been previously called

Deprecated Update()'s force_update argument, as it no longer had any effect

Version 0.5 (October 5th, 2013)

Fixed bug where a stat bar wouldn't check if its owner still existed before triggering a hide timeout

Version 0.4 (August 11th, 2012)

Fixed bug where auto_show and _hidden were not being correctly determined based on timeout

Moved and renamed demo icons so they're less likely to interfere with projects

Version 0.3 (March 26th, 2012)

Library now supports defining stat bar properties at compile-time by making a subtype of /bar_overlay (see mana_bar in updated demo)

Library can now determine the number of icon_states for a stat bar if it is not provided

Version 0.2 (November 12th, 2011)

Added Show() and Hide() functions

Added timeout, auto_show, and hide arguments to New()

Renamed Update()'s force argument to force_update

Added force_show and force_timeout arguments to Update()

Updated demo to demonstrate new timeout feature

Version 0.1 (June 5th, 2011)

Library renamed from "Quick Overlay Stat Bars" to "Stat Bar Overlays"
(Suggested you Uninstall and then re-Download the library to prevent old files from lingering)

Naming conventions brought in line with BYOND's
This will require some quick changes, which you can do with Find/Replace (Ctrl+H)

  • overlayBar -> bar_overlay
  • update() -> Update() (Be careful! Use Find Next to first check that it's the Update() for a /bar_overlay)
  • varStat -> var_stat (shouldn't be necessary unless you directly accessed a bar)
  • varMax -> var_max (same are above)
Stat bar overlay is now automatically removed when the /overlayBar is deleted

Changed default layer to FLOAT_LAYER

New property: state_prefix. Allows you to store multiple bar images in one icon file, by giving them a prefix (eg "health1","health2", ect)

New optional parameter for Update(): force. Forces the bar to update, even if nothing has changed. Useful when rebuilding overlay lists. Defaults to 0.

Added reference to library's code file.

Version 0.0 (May 31st, 2011)

Initial release
Going to quote myself here, hope that's okay.

"This should be used as the new standard for overlay bars."

Thank you very much for this library.
This is so easy to use, and really user-friendly.
I just slapped it in to one of my old projects, and it works like a charm.
Thanks for this!
Version 0.1 brings some minor changes, including some changes to the naming conventions to bring the library more in line with BYOND's style.

See the Update History at the bottom of the hub for a description of the changes, and the quick fixes you'll have to do to update to the new version.
It would be awesome if you added some support for displaying bars under enemies during combat.

I made my own but it could be a nice addition to the library :P
Kyle_ZX wrote:
It would be awesome if you added some support for displaying bars under enemies during combat.

I made my own but it could be a nice addition to the library :P

Can you be more specific? I'm always open to adding new features. Do you mean only displaying the bar when an enemy takes damage, and then automatically hiding it when it isn't updated in a while?
DarkCampainger wrote:
Kyle_ZX wrote:
It would be awesome if you added some support for displaying bars under enemies during combat.

I made my own but it could be a nice addition to the library :P

Can you be more specific? I'm always open to adding new features. Do you mean only displaying the bar when an enemy takes damage, and then automatically hiding it when it isn't updated in a while?

Yes, that's what I mean. The health bar shouldn't go away instantly though because the player might only be taking a rest from combat. Something like 20 seconds would be good or until the last agressor is of a certain distance away.
Kyle_ZX wrote:
DarkCampainger wrote:
Kyle_ZX wrote:
...
...

Yes, that's what I mean. The health bar shouldn't go away instantly though because the player might only be taking a rest from combat. Something like 20 seconds would be good or until the last agressor is of a certain distance away.

I'm worried that that's starting to get too game-specific to be in a library. What I can do, however, is include Show() and Hide() functions. Potentially, I could give them "timeout after 'x' ticks" and "auto-show on Update()" parameters (respectively) to help make implementing such a system easier for game developers.
Hey, so I'm using a save resource I found along with this library, and whenever I log out and log back in, the healthbar is frozen wherever it's at and won't go lower. Say, for example, my health is at 50% and I log out, and it saves. When I log back in, if my health goes down below 50%, it won't show. Curious how to fix this. Thanks.
Nerdy boy wrote:
Hey, so I'm using a save resource I found along with this library, and whenever I log out and log back in, the healthbar is frozen wherever it's at and won't go lower. Say, for example, my health is at 50% and I log out, and it saves. When I log back in, if my health goes down below 50%, it won't show. Curious how to fix this. Thanks.

Typically that happens if the statbar is in the player's overlays and you save the overlays. The solution is to either delete the statbar (if the player is logging out and won't need it) or to hide it before saving the player.

Also make sure that the variable you're using to store the statbar reference is marked as tmp.
Worked! Thank you so much!
Thanks so much man im about to cry ive been looking for something like this all day
In response to DarkCampainger (#9)
DarkCampainger wrote:
Nerdy boy wrote:
Hey, so I'm using a save resource I found along with this library, and whenever I log out and log back in, the healthbar is frozen wherever it's at and won't go lower. Say, for example, my health is at 50% and I log out, and it saves. When I log back in, if my health goes down below 50%, it won't show. Curious how to fix this. Thanks.

Typically that happens if the statbar is in the player's overlays and you save the overlays. The solution is to either delete the statbar (if the player is logging out and won't need it) or to hide it before saving the player.

Also make sure that the variable you're using to store the statbar reference is marked as tmp.

I have almost the same Problem. The overlays are saved so when people relog, they have 2 bars, one (new) full and the one they had before. I dont know how to remove this overlay, What Should I do? Thanks.
In response to NSBR (#12)
Call the Hide() proc before you save it, then show it again afterwards. Also make sure the variable referencing the stat bar is marked tmp.

Alternatively, use a save system that doesn't save overlays.
In response to DarkCampainger (#13)
DarkCampainger wrote:
Call the Hide() proc before you save it, then show it again afterwards. Also make sure the variable referencing the stat bar is marked tmp.

Alternatively, use a save system that doesn't save overlays.

I did that but it didnt work afterwards... Can I have u personally help me? It would help a lot!
In response to NSBR (#14)
Sure, make a new post with what you tried, and I'll help you out tomorrow night.
In response to DarkCampainger (#15)
Thanks! Did as told to.