Stat Bar Overlays

by DarkCampainger
Quickly add overlay stat bars for health, mana, experience--anything! [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://DarkCampainger.StatBarOverlays##version=6

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://DarkCampainger.StatBarOverlays##version=6

1539 downloads
Version 0.6
Date added: May 30 2011
Last updated: Oct 5 2013
6 fans
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

Comments

NSBR: (Sep 30 2013, 7:17 am)
Thanks! Did as told to.
DarkCampainger: (Sep 29 2013, 6:32 pm)
Sure, make a new post with what you tried, and I'll help you out tomorrow night.
NSBR: (Sep 29 2013, 5:54 pm)
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!
DarkCampainger: (Sep 29 2013, 4:40 pm)
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.
NSBR: (Sep 29 2013, 1:30 pm)
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.