ID:262140
 
Okay, I've been wanting a Health overly meter for along time for my game, and I finally found one, problem is, that it doesn't work on MY game. This is what I have:

mob
proc/Update()
for(var/obj/HP/O in src.client.screen)//For the on screen object
O.num = round((src.health/src.maxhealth)*O.width)
if(O.num >= O.rangemax)//if number exceedes icon states
O.icon_state = "30"//make the icon state 5
if(O.num <= O.rangemin)//if the number is below zero
O.icon_state = "0"//make the icon state 0
if(O.num < O.rangemax && O.num > O.rangemin)//if there is an icon state for that number
var/newnum = O.num - O.rangemin
O.icon_state = "[newnum]"// change the icon state
obj
var/num = 0
var/rangemax//How many icon states
var/rangemin//How few icon states
HP
layer = MOB_LAYER+11//The layer of the meter so it appears above things on the screen
var/width = 30
meter
icon = 'meter.dmi'
icon_state = "0"
rangemax = 30//vars fall into place here that i pointed up above
rangemin = 0//vars fall into place here that i pointed up above
mob/Login()
src.overlays += new/obj/HP/meter//Adds the meter to the screen


I think this is right since there 30 icon states to the meter.
Do you really need 30?

It hardly needs 10, in my opinion.

It's a 32 by 32 pixel square, and people aren't going to see a one pixel change in their healthbar and/or care.
> mob/Login()
> src.overlays += new/obj/HP/meter//Adds the meter


That(^) is adding the meter to your overlays, not to your screen. If you want to add it to your screen do this(v):

mob/Login()
var/obj/HP/meter/o=new
o.screen_loc="1,1"
src.client.screen+=o


Kholintian, there is no point on you commenting on this post telling Mega fart cannon what he should be doing rather than helping him. I think 30 icon_states are just fine for a health meter.
In response to Zaltron
BBZT! thanks for playing but no. all he needs is this line
mob/Login()
src.client.screen += new/obj/HP/meter//This one


The screen location etc is already set above.

[edit]

You should re-read my demo again Mega fart cannon ungh. This is how it is supposed to look.

obj
var/num = 0
var/rangemax//How many icon states
var/rangemin//How few icon states
HP
layer = MOB_LAYER+11//The layer of the meter so it appears above things on the screen
var/width = 5
meter
icon = 'meter.dmi'
icon_state = "0"
screen_loc="2,1"//Location of the object on the players screen
rangemax = 5//vars fall into place here that i pointed up above
rangemin = 0//vars fall into place here that i pointed up above


you forgot to set a screen_loc.

--Goz
In response to Goz
I know that's the proper way that you wrote the demo, but I didn't want actually ON the screen, I wanted it as an overlay just like in MJ and Seika. You code was only a strating point ;D
In response to Mega fart cannon
Mega fart cannon wrote:
I know that's the proper way that you wrote the demo, but I didn't want actually ON the screen, I wanted it as an overlay just like in MJ and Seika. You code was only a strating point ;D

Ah, i see well..you can do something like this:

obj
var/num = 0
var/rangemax
var/rangemin
HP
var/width = 30
meter
icon = 'meter.dmi'
icon_state = "0"
pixel_y=-32//New Line
layer=-4//New Line
rangemax = 30
rangemin = 0


then add it as an overlay,Just dont forget to call the Update() proc to change the overlay. Also in that proc you'll want to change this line:
 for(var/obj/HP/O in src.client.screen
because its not in the client.screen anymore.


--FSDU
In response to FSDU
So it would be something like this?

mob
proc/Update()
for(var/obj/HP/O in src.overlays)//For the on screen object
O.num = round((src.health/src.maxhealth)*O.width)
if(O.num >= O.rangemax)//if number exceedes icon states
O.icon_state = "30"//make the icon state 5
if(O.num <= O.rangemin)//if the number is below zero
O.icon_state = "0"//make the icon state 0
if(O.num < O.rangemax && O.num > O.rangemin)//if there is an icon state for that number
var/newnum = O.num - O.rangemin
O.icon_state = "[newnum]"// change the icon state
obj
var/num = 0
var/rangemax
var/rangemin
HP
var/width = 30
meter
icon = 'meter.dmi'
icon_state = "30"
pixel_y=-32//New Line
layer=-4//New Line
rangemax = 30
rangemin = 0
mob/Login()
src.overlays += new/obj/HP/meter//Adds the meter to the screen
In response to Mega fart cannon
I Haven't cracked open DreamMaker to test it so try it and reply with any problems you recieve.

--FSDU
In response to FSDU
I see the meter now, but it isn't updating. Im calling the Update() in the Increase Health, Decrease Health, and Level Up verbs. (This is in a serperate DM by the way. ;D)
In response to Mega fart cannon
You have to delete it then do the calculations then re add the overlay.
In response to Wanabe
Isn't that gonna create lots if not tons of lag?
In response to Mega fart cannon
Mega fart cannon wrote:
Isn't that gonna create lots if not tons of lag?


Only if you do it at specific times, like when a person is attacked, killed, etc.