Hello! I've been trying to make custom health bars for my mod, but with sad results. What I want is a small dialog (100px width frame), which consists out of green bars, which amount is calculated from the health a unit has, and divided by 200. So for example, if the unit has 1000 HP, the health bar frame would consist of 5 bars, all of them being 20px width, resulting in a 100px frame. Because it's a healthbar, I would also like to change it's current value at 0.5 seconds (which is easy to do).
Where should I begin? Have you got any description, or points I could follow?
I won't even bother telling what I've done, because it didn't work, and I couldn't even find how to get the health amount from an unit... not talking about drawing dialog, which sounds like a very hard thing to do! I've searched old topics, but they didn't seem to answer my problem.
Health is a property of the unit which can be read by triggers. It will return a real value, so make sure you save it in a "real" variable (real is a data type).
To make a bar which is fixed on the player screen, you need a dialog and a image.
Then you have 2 options:
- resizing the image (-> image stretches)
- resizing the dialog (-> image is cut off)
While creating the image, the anchor of the image is important.
If you want to make dialogs attached for something like heroes (as seen in SOTIS and Hive Keeper or in other MOBA games like League of Legends), you would need to calculate for each player, if the dialog needs to be set visible or not because it overlaps with the default's game UI.
If you want that, waiting for Heart of the Swarm and learning other things now instead might be better.
At least I hope Heart of the Swarm adds that functionality properly because they need this for their DOTA map.
Thanks. But that seems like it changes the total width of the main health bar, doesn't it? I want the width to be the same, but to increase the amount of small bars in the big bar. Like that:
Thanks. But that seems like it changes the total width of the main health bar, doesn't it? I want the width to be the same, but to increase the amount of small bars in the big bar. Like that:
No it does not. It just hide/show given health block.
so at 60% it will be [###__] and at 100% [#####]
you can simply put some background image behind the area of bar
Even though that is nothing that I want, I will probably use it, if no one really knows the good way to accomplish that. Thing is (I dunno if you're unable to understand or I fail at explaining, in which case I'm very sorry) - what if a unit suddenly gets another 200hp, and now has 6 bars instead of 5? The solution you said counts % of HP per bar, and I need flat amount, PLUS fit them all in a fixed width.
I know some programming, but I just can't find the right events/actions.
Yes, that is what I want. Any explanation how sotis does it? :p
You create a dialog for each hero and attach it to the hero.
Then you create an action definition which updates the health bars and all information as images how you want them onto that dialog. The health bars would be resized images on the dialog.
You would update the dialog whenever the unit takes damage and/or within a neverending loop with waits.
Now you only need a way to hide the dialog, if the dialog is above the HUD of the game. I would ask Bibendus how that is done because I'm bad with trigonometry and didn't do much with cameras.
Also, you might need the player's screen resolution for that. Just search for get resolution and you should find a library where someone implemented a method to receive it.
I guess with HotS you could do that properly because that functionality (fully working dialog on unit in terms of default UI underlapping) is used in Blizzard Dota.
I was working on a similar system a while back. It's pretty basic, but it at least demonstrates how to implement a basic health bar system.
I used custom images. Their dimensions are 172 x 24. So, the width of the dialog item (image) is set to:
(172 / 100) * [% Of Unit's Health]
If you were wanting multiple bars, it will be more complicated. The easier way is multiple images, but that is not necessarily the better way of doing it.
Even though that is nothing that I want, I will probably use it, if no one really knows the good way to accomplish that. Thing is (I dunno if you're unable to understand or I fail at explaining, in which case I'm very sorry) - what if a unit suddenly gets another 200hp, and now has 6 bars instead of 5? The solution you said counts % of HP per bar, and I need flat amount, PLUS fit them all in a fixed width.
I know some programming, but I just can't find the right events/actions.
concept is similar, it would just require some additional dynamic check and setup, something like:
count parts: simply by max hp / 200 rounded up
WHILE: (current parts amount < parts)
IF: bar[current parts amount] == no dialog item
create new image ... at offset part*x
save last dialog item as bar[part]
ELSE: set show bar[part]
modify current parts amount + 1
while (current parts amount > parts)
hide bar[current parts amount]
modify current parts amount -1
Something like that, it would probably require some tweaks. After this you go into setting part where you first set up width of each bar up to 'bar[current parts amount]' to dialog (width / current parts amount) and then check the health and hide/show it in similar way i shown in my last code.
It would be best to wait for HotS to come out, it will simplify things like this a lot.
How? You expect function like "Create health bar dialog with separate health blocks" ?
Whatever added will just provide more core functionality. Blocks for you to build from, not prebuilt structures.
I could build this and it would be not much larger than what i already typed here but in case like this i really don't feel to do someone's homework when he just neglects any suggested ideas.
No matter what problem you have to solve it you need to think in steps.
Identify the problem (or design)
Split it into basic steps. What should happen first from code perspective, what's next and so on.
Type it in code form step by step task after task.
The only limitation ever you can hit is if the language does not support something, but we are at stage were any language provides more than enough functionality to create anything, It's just matter of design.
Games on NES had such health bars and they didn't had "HotS"
I got confused at what you wrote, can you comment on what each variable does?
How I understood: first I get variable count parts, which is like max units hp/200; then I got confused what is current parts variable and part*x calculation... what is x? Anything else I quite got :) Thanks!
Thing is, I have the basic knowledge of C+ + and all that, but Galaxy Editor is just so confusing. I can't get simple values easily (like units health), or write a trigger without knowing EVERY existing action... that is very hard to memorize :(
If you feel that I'm neglecting your suggestion - I'm sorry. I'm just really stubborn with the health bar idea, and I really need it :p
-
Also unrelated, but maybe you can link to a tutorial on how to work on units abilities with triggers? Right now I'm trying to make this ability with triggers: "2% of units health is transfered to health regeneration" - sounds easy and I have the basic idea in mind, but I just can't find the right actions, nor how to start the trigger (aka event???).
I got confused at what you wrote, can you comment on what each variable does?
How I understood: first I get variable count parts, which is like max units hp/200; then I got confused what is current parts variable and part*x calculation... what is x? Anything else I quite got :) Thanks!
current parts would be global int variable holding last index of last health bar part dialog item (ofc per player/unit)
part*x was actually offset part*x where x would be offset X of image from left. For example first bar part would be at offset 0*20 = 20, another at 1*20=20, so they all position themselves right next to each other. Yes you would have to calculate offset from 'parts' amount and resize old ones or simply create another part of code to resize and reposition all bars. It's just one way of doing it, also i didn't put much effort into this, it was more of pseudo code.
EDIT: Actually now i realized it should not be shown when exist.
You could use my List <T> library if your familiar with it. Since dialog item is integer it would be a lot easier to add/remove and iterate thru them all.
Don't you want something like sotis or LoL hp bar? Or did I misunderstand? Also, I uses the triggers blizzard has kindly provided us, it's not as fast as actual custom code, but it helps a ton, especially when you can search for any action that is support by the editor. HotS would just make this problem easier, because blizzard is adding an HP bar like this into their DotA.
Also, with the 2% hp regen ability thing, what is the regen time currently? Like every second... Or 2... Or 5?
If you use the actions blizzard provided, you can get a units HP/HP percent easily using variables, or any real value.
yes, you understood correctly :)
well the regen and hp would change all game long, so the ability just buffs him, depending on his health. So when he gets 2000 hp, he also gets bonus 40 hp regen (a lot). That is very easy to do, though, I don't know how to get units health or return any other attribute (in this case - regen). I don't know which actions are these, and what kind of event is needed.
Isn't there a tutorial about making abils in triggers?
I still don't get how you get the health from an unit. Is it this one: SetDialogItemTooltip? Other than that - thank you for your hp bar!!! :)
It changes the health amount in the response trigger as in this image below:
The variable I have highlighted is the length and the math calculation however the very first action called is what changes the health bar. This action is using the variable I defined earlier.
Basically when damaged, the health bar's size changes. In order to adapt the size of the health bar, I am using the math as I mentioned earlier plus the function Unit Property passing in the Triggering Unit and Life (Percent). Look at Value 2 in the image below.
However, all of this can only be done using a function of type conversion called Real to Integer. The reason you need this is because the way the health bar changes is by changing the dialog item image's length and dialog item lengths only use whole numbers. Look above Value 1 in the image below.
Dont use damage taken events for health bars because
1) It wont work properly since it ignores heals and life regeneration
2) It can cause big overhead in the game since damage taken might trigger very often in certain situations
On topic, i think your questions were answered several times. If you still dont know how to do this you should start with basics before trying to do stuff like this.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello! I've been trying to make custom health bars for my mod, but with sad results. What I want is a small dialog (100px width frame), which consists out of green bars, which amount is calculated from the health a unit has, and divided by 200. So for example, if the unit has 1000 HP, the health bar frame would consist of 5 bars, all of them being 20px width, resulting in a 100px frame. Because it's a healthbar, I would also like to change it's current value at 0.5 seconds (which is easy to do).
Where should I begin? Have you got any description, or points I could follow?
I won't even bother telling what I've done, because it didn't work, and I couldn't even find how to get the health amount from an unit... not talking about drawing dialog, which sounds like a very hard thing to do! I've searched old topics, but they didn't seem to answer my problem.
@Simoneon: Go
I don't think this can be done through triggers - if it could, it woulda be very hard for a computer to handle.
Health is a property of the unit which can be read by triggers. It will return a real value, so make sure you save it in a "real" variable (real is a data type).
To make a bar which is fixed on the player screen, you need a dialog and a image.
Then you have 2 options:
- resizing the image (-> image stretches)
- resizing the dialog (-> image is cut off)
While creating the image, the anchor of the image is important.
If you want to make dialogs attached for something like heroes (as seen in SOTIS and Hive Keeper or in other MOBA games like League of Legends), you would need to calculate for each player, if the dialog needs to be set visible or not because it overlaps with the default's game UI.
If you want that, waiting for Heart of the Swarm and learning other things now instead might be better.
At least I hope Heart of the Swarm adds that functionality properly because they need this for their DOTA map.
@Simoneon: Go
make a dialog with those 5 bar images. store them in bararray[5]
On update.
@Nerfpl: Go
Thanks. But that seems like it changes the total width of the main health bar, doesn't it? I want the width to be the same, but to increase the amount of small bars in the big bar. Like that:
[_|_|_|_|_] is equal in width with this:
[||||||||||]
@Ahli634: Go
Yes, that is what I want. Any explanation how sotis does it? :p
No it does not. It just hide/show given health block.
so at 60% it will be
[###__]
and at 100%[#####]
you can simply put some background image behind the area of bar
@Nerfpl: Go
Even though that is nothing that I want, I will probably use it, if no one really knows the good way to accomplish that. Thing is (I dunno if you're unable to understand or I fail at explaining, in which case I'm very sorry) - what if a unit suddenly gets another 200hp, and now has 6 bars instead of 5? The solution you said counts % of HP per bar, and I need flat amount, PLUS fit them all in a fixed width.
I know some programming, but I just can't find the right events/actions.
You create a dialog for each hero and attach it to the hero.
Then you create an action definition which updates the health bars and all information as images how you want them onto that dialog. The health bars would be resized images on the dialog.
You would update the dialog whenever the unit takes damage and/or within a neverending loop with waits.
Now you only need a way to hide the dialog, if the dialog is above the HUD of the game. I would ask Bibendus how that is done because I'm bad with trigonometry and didn't do much with cameras.
Also, you might need the player's screen resolution for that. Just search for get resolution and you should find a library where someone implemented a method to receive it.
I guess with HotS you could do that properly because that functionality (fully working dialog on unit in terms of default UI underlapping) is used in Blizzard Dota.
@Ahli634: Go
thanks, that sounds nice, although, how to get unit health? And what are the calculations I need to adjust the bars?
I was working on a similar system a while back. It's pretty basic, but it at least demonstrates how to implement a basic health bar system.
I used custom images. Their dimensions are 172 x 24. So, the width of the dialog item (image) is set to: (172 / 100) * [% Of Unit's Health]
If you were wanting multiple bars, it will be more complicated. The easier way is multiple images, but that is not necessarily the better way of doing it.
I hope this helps!
concept is similar, it would just require some additional dynamic check and setup, something like:
Something like that, it would probably require some tweaks. After this you go into setting part where you first set up width of each bar up to 'bar[current parts amount]' to dialog (width / current parts amount) and then check the health and hide/show it in similar way i shown in my last code.
The only limitation is initial bar[] array size
This would be very hard I think... It would be best to wait for HotS to come out, it will simplify things like this a lot.
I can still try to create what you want, would you like me too? I enjoy a challenge, but if you don't need it then there is no need for me to make it.
How? You expect function like "Create health bar dialog with separate health blocks" ?
Whatever added will just provide more core functionality. Blocks for you to build from, not prebuilt structures.
I could build this and it would be not much larger than what i already typed here but in case like this i really don't feel to do someone's homework when he just neglects any suggested ideas.
No matter what problem you have to solve it you need to think in steps.
The only limitation ever you can hit is if the language does not support something, but we are at stage were any language provides more than enough functionality to create anything, It's just matter of design.
Games on NES had such health bars and they didn't had "HotS"
@VoidPotato: Go
I still don't get how you get the health from an unit. Is it this one: SetDialogItemTooltip? Other than that - thank you for your hp bar!!! :)
@Nerfpl: Go
I got confused at what you wrote, can you comment on what each variable does?
How I understood: first I get variable count parts, which is like max units hp/200; then I got confused what is current parts variable and part*x calculation... what is x? Anything else I quite got :) Thanks!
@Oparcus: Go
Thanks! But thing is - I'd like to learn everything first, so next time same question wouldn't appear...
@Nerfpl: Go
Thing is, I have the basic knowledge of C+ + and all that, but Galaxy Editor is just so confusing. I can't get simple values easily (like units health), or write a trigger without knowing EVERY existing action... that is very hard to memorize :(
If you feel that I'm neglecting your suggestion - I'm sorry. I'm just really stubborn with the health bar idea, and I really need it :p
-Also unrelated, but maybe you can link to a tutorial on how to work on units abilities with triggers? Right now I'm trying to make this ability with triggers: "2% of units health is transfered to health regeneration" - sounds easy and I have the basic idea in mind, but I just can't find the right actions, nor how to start the trigger (aka event???).
current parts would be global int variable holding last index of last health bar part dialog item (ofc per player/unit)
part*x was actually offset part*x where x would be offset X of image from left. For example first bar part would be at offset 0*20 = 20, another at 1*20=20, so they all position themselves right next to each other. Yes you would have to calculate offset from 'parts' amount and resize old ones or simply create another part of code to resize and reposition all bars. It's just one way of doing it, also i didn't put much effort into this, it was more of pseudo code.
EDIT: Actually now i realized it should not be shown when exist.
You could use my List <T> library if your familiar with it. Since dialog item is integer it would be a lot easier to add/remove and iterate thru them all.
Don't you want something like sotis or LoL hp bar? Or did I misunderstand? Also, I uses the triggers blizzard has kindly provided us, it's not as fast as actual custom code, but it helps a ton, especially when you can search for any action that is support by the editor. HotS would just make this problem easier, because blizzard is adding an HP bar like this into their DotA.
Also, with the 2% hp regen ability thing, what is the regen time currently? Like every second... Or 2... Or 5?
If you use the actions blizzard provided, you can get a units HP/HP percent easily using variables, or any real value.
@Nerfpl: Go
thanks! I'll try this asap and tell you the results :) where is your List?
@Oparcus: Go
yes, you understood correctly :) well the regen and hp would change all game long, so the ability just buffs him, depending on his health. So when he gets 2000 hp, he also gets bonus 40 hp regen (a lot). That is very easy to do, though, I don't know how to get units health or return any other attribute (in this case - regen). I don't know which actions are these, and what kind of event is needed.
Isn't there a tutorial about making abils in triggers?
here, i made it just for sake of it. The visual part is basic tho
both versions.
Second uses my List <T> so you need to get familiar with it
in my sig or libraries section
(sigs are by default shown only in first post per thread)
It changes the health amount in the response trigger as in this image below:
The variable I have highlighted is the length and the math calculation however the very first action called is what changes the health bar. This action is using the variable I defined earlier.
Basically when damaged, the health bar's size changes. In order to adapt the size of the health bar, I am using the math as I mentioned earlier plus the function Unit Property passing in the Triggering Unit and Life (Percent). Look at Value 2 in the image below.
However, all of this can only be done using a function of type conversion called Real to Integer. The reason you need this is because the way the health bar changes is by changing the dialog item image's length and dialog item lengths only use whole numbers. Look above Value 1 in the image below.
I hope this clears it up. Good luck!
Dont use damage taken events for health bars because
1) It wont work properly since it ignores heals and life regeneration
2) It can cause big overhead in the game since damage taken might trigger very often in certain situations
On topic, i think your questions were answered several times. If you still dont know how to do this you should start with basics before trying to do stuff like this.