Displaying the health of an object?

  • If you're asking a question make sure to set the thread type to be a question!

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
I am working on a new map (Not gonna say exactly what, bit of a secret, but I will be uploading it here when I am done :p) and it relies heavily on func_breakable objects. Is there any way to create some sort of a counter displaying the health of one of these objects?

Any help will be greatly appreciated, thanks in advance! :)
 

Fish 2.0

L6: Sharp Member
Nov 22, 2012
324
262
bit of a secret

relies heavily on func_breakable objects



dont tell anyone, I think you may have struck some gold

I'm not sure there is. If there is a damage output trigger, like onHit or something.
 

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,669
func_breakable provides OnHealthChanged which outputs a decimal value representing the current health where 1 is full health and 0 is dead. It's up to you how you want to use/display this value depending on what you are doing. My own "secret project" from a couple years ago died because I couldn't display it the way I wanted, so good luck.
 

LeSwordfish

semi-trained quasi-professional
aa
Aug 8, 2010
4,102
6,597
There are various ways to display a counter- env_sprites with the material set to the "number" overlays work reasonably well, though look funny at times. Methods to make a brushwork "health bar" have been suggested, and can be found elsewhere on the site.

You'll need to change the decimal value to an integer (i'm not sure how- booj?) but when that's done you can send the integer to a logic_case. This allows you to get a range of outputs based on the integer you put in- let me grab some screenshots of the one i'm using in my buildables list.

43EmB.png

43EpP.png


Alright, this logic_case is set up so that as the integer input to the case increases, the "case number" decreases. Each case activates a different sprite- when 4 is input, the number 1 appears. I have another output that disables ALL the sprites just before one is enabled- this prevents more than one activating at once.
 

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
This allows you to get a range of outputs based on the integer you put in- let me grab some screenshots of the one i'm using in my buildables list.

For some reason, the screenshots aren't showing up for me. Your idea sounds like it would work but it would be much easier for me to follow if the screenshots worked. :p
 

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,669
You'll need to change the decimal value to an integer (i'm not sure how- booj?)
Easier said than done. It's a decimal out to about 5 places and the only feasible way to convert it to integers would be to set up a series of logic_compare operations to check when it falls past a given value and then send a corresponding integer.
 

henke37

aa
Sep 23, 2011
2,076
513
Or you could just use math_remap.
 

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,669
No... you couldn't. Logic_case requires individual specific values to match up with it's cases. Math_remap supports decimals so feeding it a 5 digit decimal will effectively always get you a 5 digit decimal out the other end. Hence the need for a compare to merely check when it has passed a specific integer, because there is no way to convert the decimals to integers.
 

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
I took a short break, getting back to mapping now so I can test some stuff out. Also, if it will help anyone, I have 4 objects with a Strength value of 7500 and 2 objects with a Strength value of 15000.

Edit 1: Right off the bat, I notices this "OnTakeDamage" output... maybe some sort of brush based healthbar could be made off of this? Will certainly work on it.
Edit 2: Nevermind that, it won't work because it doesn't read how much damage the func_breakable takes, just whether or not it has taken damage.
Edit 3: I found a workaround that, while not solving the problem of how to create a health bar, does roundabout the same sort of thing I wanted the health bars to do. Essentially, I needed the health bars to indicate that you should be shooting some object and as a way to display how much health that particular object has. Rather than using a health bar to indicate that you should be shooting this object, I am using trigger_multiple fields that activate game_text entities. Sadly, this doesn't accomplish the goal of displaying the object's health, but if a sign tells you "Shoot this a lot to make things happen", hopefully people will be bright enough to do just that. It would be nice to see some way to make a health bar work, but at the very least a big part of what I needed was accomplished.
 
Last edited:

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
I took a look at the map, decompiled it to have a quick peek around... the thing is a maze. I have no clue what anything does, I will keep looking around but I doubt that I will be able to find anything in here. However, the video did indeed show a health bar of some sort related to the shield, so there is hope yet I suppose.

Edit 1: I did learn something - apparently there is an entity called game_text_tf. I've never seen it before, but it apparently can be used to display those text boxes instead of just having text on the screen. It could be very useful.
 
Last edited:

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
I did a search for a way to create a health bar instead of a way to create a number counter and I did find something: http://forums.tf2maps.net/showthread.php?t=16271

The thread I linked to says to use the output OnHealthChanged to set a func_movelinear's SetPosition input. The thread also mentions how to fix a small bug where the health bar moves in the wrong direction, emptying out the health bar completely when the func_breakable is hit, and filling up until the func_breakable is broken. Switching the func_movelinear's start position to 1 and switching the move direction (i.e. I originally had the move direction set to "down", so I changed the start position to 1 and set the move direction to "up") fixes the issue.

There is still one issue: The health bar stays at the fully opened position until the func_breakable is hit, making the health bar appear empty. Is there any way to use an input to damage the func_breakable? I see a SetHealth input, but I dunno if that would work, I just get the feeling it wouldn't be considered "damage". I will try it out and post my results.

Edit 1: I used a logic_auto to set the health of the Func_breakable on map spawn, and that worked to change the position of the func_movelinear. Looking back on it, the output for the Func_breakable is "OnHealthChanged" so I guess it makes sense.

When I get the chance, I will put together a quick prefab to show off how to make a health bar. Thanks for the help, everyone!
 
Last edited: