ID:269760
 
How would I go about making a stat meter overlay? I've seen 2 on the hub that make them as overlays but they are missing files or don't work.
Search the forums.
Well, I'm not sure how well this will work for you but I used a library for stat meter overlays (although I don't remember who created it), but I can post the code if you would like....
What do you mean? Like a HUD that shows a bar with HP/MP or what?
If I understand you correctly, you want a small stat bar over the character's icon. If that's what you mean, then image objects are your best bet here.

You could use overlays, but using image objects gives you more control, since you can make specific people see your healthbar.

We start with an image object. But we need to keep track of it, so we reference it to a mob's variables. Let's assume we have an icon with 10 states. 0 is an empty statbar, and 10 is a full statbar. So, draw those icons.

Next, we have to draw the icon. Since the icon will have 10 states, we can do simple math. Get the percentage of HP you have. Multiply it by 100, round it, then divide it by 10. It should fit in evenly, since 100 divides well to 10 states.

Now that we know the icon_state, create the image object, and stick it onto the player. Make the world see it, or whomever you want.

Create a proc which updates your image object, and changing it's icon_state, since we have it referenced to it. It would be really convenient if you had one proc which takes care of damaging, so you don't have to keep on calling the image object refresh proc.

Here is a small snippet of what I described:
mob
var
maxhp
hp
image/statmeter_img

proc/refresh_hud()
var/formula = "[round((maxhp/hp)*10,1)]"
if(statemeter_img)
if(src.icon_state != formula)
statmeter_img.icon_state = formula
else
src.statmeter_img = image('statmeter.dmi',src, formula)
world << src.statmeter_img

proc/takedamage() // assuming you have a takedamage variable
// damaging stuff
src.refresh_hud()


Be careful about making your maxhp and hp 0, since BYOND gives a runtime error when you divide by zero.

If you don't understand a concept, ask.

~~> Dragon Lord
In response to Killerdragon
Yes I mean a meter that will be above the mob's head..I've been looking at spuzzums tyring to make my own and got this so far :

obj
Meter
icon = 'meter.dmi'
num = 0
width = 16
proc
Update()
if(num <= 0)
num = 0
else
if(num >= width)
num = width
else
src.icon_state = "[round(src.num)]"

mob
New()
..()
src.Meter = new

mob
var
obj/Meter/

src.Meter.num = (src.hp/src.maxhp)*16
src.overlays += src.Meter


But now I get a runtime error of null num and/or width. But uh, I'm gonna try a bit more though first..