• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with HP dialog bar

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
Hey, so I made an HP bar for my zealot and it initializes just fine, but whenever I need to update it, it comes out funky. Here are some images to show what happens:


Screenshot2010-07-24at115017AM.png


Screenshot2010-07-24at115026AM.png



Screenshot2010-07-24at115032AM.png


As you can see, it looks fine normally. When the Zealot takes damage, the bar expands for whatever reason, then when it dies the bar doesn't shrink all the way. It's very odd.

Basically, the text needs to update, I need a Label above the bar saying "Health" and the bar should shrink toward the middle and disappear when the zealot dies. Can anyone help me out?

Here are my triggers:

Variables:
  • healthBar = No Dialog <Dialog[16]>
  • healthDialogItem = No Dialog Item <Dialog Item[16]>
  • healthBarWidth = 400 <Integer>
  • healthBarHeight = 75 <Integer>
  • healthBarImageWidth = 340 <Integer>
  • healthBarImageHeight = 40 <Integer>
  • setHealthBar
    • Options: Action
    • Return Type: (None)
    • Parameters
      • player = 0 <Integer>
      • unit = No Unit <Unit>
    • Grammar Text: setHealthBar(player, unit)
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
      • unitCurHPInt = (Integer((unit Life (Current)))) <Integer>
      • unitMaxHPInt = (Integer((unit Maximum Life (Current)))) <Integer>
      • hpBarImgHtPercentInt = (Integer(((Real(healthBarImageHeight)) * 0.7))) <Integer>
      • hpImgWthPercentInt = (Integer(((Real(healthBarImageWidth)) * 0.4))) <Integer>
    • Actions
      • Dialog - Create a Modal dialog of size (healthBarWidth, healthBarHeight) at (0, -500) relative to Center of screen
      • Variable - Set healthBar[player] = (Last created dialog)
      • Dialog - Create an image for dialog healthBar[player] with the dimensions (healthBarImageWidth, healthBarImageHeight) anchored to Center with an offset of (0, 0) setting the tooltip to "Health" using the image Assets/Textures/ui_loadingbarsegment_center.dds as a Normal type with tiled set to false tint color White and blend mode Normal
      • Variable - Set healthDialogItem[player] = (Last created dialog item)
      • Dialog - Create a label for dialog healthBar[player] with the dimensions (hpImgWthPercentInt, hpBarImgHtPercentInt) anchored to Center with an offset of (0, 0) with the text (Combine ((Text(unitCurHPInt)), "/", (Text(unitMaxHPInt)))) color set to White text writeout set to false with a writeout duration of 0.0
  • UpdateHealthBar
    • Events
      • Unit - Any Unit Life changes
    • Local Variables
      • unit = (Triggering unit) <Unit>
      • player = (Owner of unit) <Integer>
      • unitCurHPInt = (Integer((unit Life (Current)))) <Integer>
      • unitMaxHPInt = (Integer((unit Maximum Life (Current)))) <Integer>
    • Conditions
      • unit == camUnit[player]
    • Actions
      • Dialog - Set healthDialogItem[player] text to (Combine ((Text(unitCurHPInt)), "/", (Text(unitMaxHPInt)))) for (Player group(player))
      • Dialog - Set healthDialogItem[player] size to ((* (healthBarImageWidth, (Integer((unit Life (Percent) (Current)))))), healthBarImageHeight) for (Player group(player))
Whenever I need to set the health bar to a new unit and player I just call setHealthBar(player, unit)
 
Last edited:
Level 10
Joined
Sep 29, 2006
Messages
447
Okay so I solved the text issue. I needed an extra variable to reference the text label for the health bar.

I still need to know how to fix the graphics of the health bar (the green bar). Can anyone help? It's incredibly frustrating.

Edit:

Okay so I aligned it to the left and that's fine. I figured out that I had a math problem when setting the size of the bar.

I now set it to the (default size of the bar)*(unit current health/unit maximum health) and that works up until the unit dies. Once the unit dies, the bar never fully depletes, in fact it expands a little bit, and I don't know why. Can anyone help?

Here's an image to show what it looks like when a unit dies:




Screenshot2010-07-25at90756AM.png


My new update trigger looks like this:

[wc3]
UpdateHealthBar
Events
Unit - Any Unit Life changes
Local Variables
unit = (Triggering unit) <Unit>
player = (Owner of unit) <Integer>
curHPInt = (Integer((unit Life (Current)))) <Integer>
barFactor = ((unit Life (Current)) / (unit Maximum Life (Current))) <Real>
barSize = ((Real(vitalsBarImageWidth)) * barFactor) <Real>
MaxHPInt = (Integer((unit Maximum Life (Current)))) <Integer>
Conditions
unit == camUnit[player]
Actions
Dialog - Set healthDialogLabel[player] text to (Combine ((Text(curHPInt)), "/", (Text(MaxHPInt)))) for (Player group(player))
Dialog - Set healthDialogImage[player] size to ((Integer(barSize)), vitalsBarImageHeight) for (Player group(player))
[/wc3]
 
Last edited:
Status
Not open for further replies.
Top