1. For issues you find with the Console 1.3 release, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
    A FAQ with notes and workarounds can be found HERE. Please check this first to see if this helps your issue.

tModLoader Yet Another Boss Health Bar

Discussion in 'Works-in-Progress' started by Flashkirby99, Feb 27, 2017.

  1. Flashkirby99

    Flashkirby99 Skeletron

    Yet Another Boss Health Bar
    v1.2.1, for tModLoader v0.10.0.2​

    (This is not Boss Health Bars)

    What's the difference between this and Boss Health Bars? Preference mostly. Barack Obama Ross' one has more customisation, whereas this one is more silly effects.

    DISCLAIMER: I wrote this half asleep, so sorry for any half finished- sentences.

    By default this mod supports single NPC bosses, and worm-type bosses. Since some vanilla and mod bosses have more complicated ways of determining damage throughout a fight, you may want to mod in your own specific behaviour:

    Available on GitHub

    Since 1.2 it's much easier to add quick support for this mod.

    METHOD 1
    Adding a boss bar for a single NPC (in this case, Zombies). Normally any single NPC boss with the boss flag set as true will be detected by this mod. Stick this in your Load() method, or somwhere similar that gets called at startup. You can add as many as you want (within reason).
    Code:
    public override void Load()
    {
      Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
      if (yabhb != null)
      {
        yabhb.Call("RegisterHealthBar", NPCID.Zombie);
        yabhb.Call("RegisterHealthBar", NPCID.FemaleZombie);
        yabhb.Call("RegisterHealthBar", NPCID.SwampZombie);
      }
    }
    
    For these standard health bars, the following preset styles are available via the first method:
    RegisterHealthBar
    RegisterDemonHealthBar
    RegisterMechHealthBar
    RegisterDD2HealthBar

    Additionally, if you want a miniboss with a tiny health bar:
    RegisterHealthBarMini


    METHOD 2
    However worms and other multi-NPC enemies are a different story. If your boss is using some form of multiple health bars, consider the following:
    Code:
    public override void Load()
    {
      Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
      if (yabhb != null)
      {
        yabhb.Call("RegisterHealthBarMulti",
          NPCID.EaterofWorldsHead,
          NPCID.EaterofWorldsBody,
          NPCID.EaterofWorldsTail);
      }
    }
    
    Like method 1, there are preset multi-npc bars available:
    RegisterHealthBarMulti
    RegisterDemonHealthBarMulti
    RegisterMechHealthBarMulti
    RegisterDD2HealthBarMulti
    RegisterHealthBarMultiMini


    METHOD 3 (Semi-advanced)
    These are more complicated. Say you have some custom textures you want to use. Then the "RegisterCustomHealthBar" method call lets you define several settings, or leave them as null to use default behaviour. The format follows:
    Code:
    string "RegisterCustomHealthBar",
    int NPCID, // this one cannot be null
    bool? ForceSmall,
    string displayName,
    Texture2D fill,
    Texture2D left,
    Texture2D mid,
    Texture2D right,
    int midBarOffsetX,
    int midBarOffsetY,
    int fillDecoOffsetX,
    int bossHeadCentreOffsetX,
    int bossHeadCentreOffsetY,
    Texture2D fillSmall,
    Texture2D leftSmall,
    Texture2D midSmall,
    Texture2D rightSmall,
    int fillDecoOffsetXSM,
    int bossHeadCentreOffsetXSmall,
    int bossHeadCentreOffsetYSmall
    
    For a total of 20 parameters. If you are defining multiple NPCs with "RegisterCustomHealthBarMulti", replace the int NPCID with an int[], eg.
    Code:
    new int[] { NPCID.BrainofCthulhu, NPCID.Creeper }
    So how does this work in practice? Say we want to make a health bar for a flying snake (because hey why not), giving it a custom health bar. The textures we have made prior are being stored as: UI/CustomBar*.png
    Then it becomes a simple matter of inserting or 20 parameters:
    Code:
    public override void Load()
    {
      Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
      if (yabhb != null)
      {
        yabhb.Call("RegisterCustomHealthBar",
          NPCID.FlyingSnake, // This is the enemy we want to track health for
          false, // ForceSmall left as false
          "Murder Dragoram Snake", // We can set a custom display name too
          // The default bar textures
          GetTexture("UI/CustomBarFill"),
          GetTexture("UI/CustomBarLeft"),
          GetTexture("UI/CustomBarMiddle"),
          GetTexture("UI/CustomBarRight"),
          // Since I based the textures off the default, there is no
          // need to change any of the offsets.
          null, null, null, null, null,
          // Small textures. Note you don't have to add small textures,
          //or any textures at all - just leave these as null to use default
          GetTexture("UI/CustomBarFillSmall"),
          GetTexture("UI/CustomBarLeftSmall"),
          GetTexture("UI/CustomBarMiddleSmall"),
          GetTexture("UI/CustomBarRightSmall"),
          // Same deal with offsets
          null, null, null
          );
      }
    }
    
    [​IMG]
    ⁽ᶦᵍⁿᵒʳᵉ ᵗʰᵉ ᶠᵃᶜᵗ ᵗʰᵃᵗ ᴵ ᵃᶜᶜᶦᵈᵉⁿᵗˡʸ ʳᵉᵖˡᵃᶜᵉᵈ ᵃˡˡ ʷʰᶦᵗᵉˢ ʷᶦᵗʰ ᵗʳᵃⁿˢᵖᵃʳᵉⁿᶜʸ⁾


    METHOD 4 (Advanced)
    If you want as much control over the health bar as possible without resorting to just importing this mod, the mod Call "RegisterCustomMethodHealthBar" and "RegisterCustomMethodHealthBarMulti" provide the most options, as most textures and settings are replaced with Func<> calls, allowing for things like expert mode only graphics. Again, use null to indicate where to let base code run instead.
    Code:
    string "RegisterCustomHealthBar",
    int NPCID, // this one cannot be null
    bool? ForceSmall,
    Func<NPC, string> getBossDisplayNameNPC,
    Func<Texture2D> fill,
    Func<Texture2D> left,
    Func<Texture2D> mid,
    Func<Texture2D> right,
    int midBarOffsetX,
    int midBarOffsetY,
    int fillDecoOffsetX,
    int bossHeadCentreOffsetX,
    int bossHeadCentreOffsetY,
    Func<Texture2D> fillSmall,
    Func<Texture2D> leftSmall,
    Func<Texture2D> midSmall,
    Func<Texture2D> rightSmall,
    int fillDecoOffsetXSM,
    int bossHeadCentreOffsetXSmall,
    int bossHeadCentreOffsetYSmall,
    Func<NPC, int, int, Color> getHealthColour
    
    For a total of 21 parameters. The last argument is the addition of a colour function to let you define how the bar's colour changes based on life and lifeMax. An example of how this is used in this mod itself is with the DD2 crystal, where no textures need changing, but the health bar colour behaviour does:
    Code:
    public override void Load()
    {
        Func<NPC, int, int, Color> customColour = CustomHealthBarColour;
        Call("RegisterCustomMethodHealthBar", NPCID.DD2EterniaCrystal,
        true, null, null, null, null, null,
        null, null, null, null, null,
        null, null, null, null,
        null, null, null,
        customColour
      );
    }
    
    private Color CustomHealthBarColour(NPC npc, int life, int lifeMax)
    {
        float percent = (float)life / lifeMax;
        float R = 1f, G = 1f;
        if (percent > 0.5f)
        {
            R = 1f - (percent - 0.5f) * 2;
        }
        else
        {
            G = 1f + ((percent - 0.5f) * 2f);
        }
        return new Color(R * 0.75f, G, R);
    }
    
    And, like the previous method, the same rules apply with an int[]{int,int...} in place of a single int when using "RegisterCustomMethodHealthBarMulti".


    Custom Health Bar Texture Rules
    The following defines a set of rules as to what you can do and where with custom textured healthbars. For simplicity's sake just use the one's available from github as a template so you won't have to mess with offset values.
    [​IMG]

    . . .

    [​IMG]
    [​IMG]
    [​IMG]

    [​IMG]
    [​IMG]


    [​IMG]

    Download
    via GitHub
    or
    via Mod Browser


    (tModLoader 0.9 version)

    Flashkirby99 - I am making this mod.
    Several previous modders - The original idea and previous implementations
    [​IMG]
    github repo
     
    Last edited: Aug 19, 2017
  2. Flashkirby99

    Flashkirby99 Skeletron

    Suggestions from @RexodinoLP from discord for posterity:
    . . .​
    well, I have 3 ways for it to appear
    1: fading in/out
    2: slides from below the screen, healthbar fills up
    3: like invasions
    . . .​
    and maybe, uh. a way to make it either be on the top of the screen or bottom
    . . .​
    maybe, hmmm
    make the bars smaller
    everytime theres a new one
    . . .​
    Final suggestion for now:
    Special healthbars for some bosses
    some Vanilla bosses have special healthbars, and maybe some modded boss support
    for example
    Moon Lord has a luminite healthbar
    WoF a fleshy one
     
    Mechantera and Lunatic Lobbyist like this.
  3. Jofairden

    Jofairden Terrarian

    Damn this should be in vanilla tbh, looks so good.
     
    Flashkirby99 likes this.
  4. Dan Yami

    Dan Yami Skeletron Prime

    Dont forget the modded boss support healthbars X3
     
  5. Masae

    Masae Skeletron Prime

    I would love something like this, specifically to have an easy way of seeing the exact HP progress at a glance instead of trying to read it while dodging the boss in question.

    Watching this.
     
    Maniac of Doom and Jofairden like this.
  6. EchoDuck

    EchoDuck Skeletron

    Amazing mod again, you're great!
     
  7. Keks

    Keks Terrarian

    It does not work for me...I have it installed, and reloaded my mods, but when I spawned a boss, there is just no healthbar
     
  8. Keks

    Keks Terrarian

    Can someone pls help me?
     
  9. Jofairden

    Jofairden Terrarian

    Have you made sure the mod is actually enabled?
     
  10. Keks

    Keks Terrarian

    Yes
     
  11. Flashkirby99

    Flashkirby99 Skeletron

    For me to help you as much as possible (not all may be relevant but you never know):
    1. Mod List
    2. Screenshot (even if it's not working, it helps)
    3. Which Boss is being spawned (or any of them)
    4. Singleplayer? Multiplayer?
     
  12. Keks

    Keks Terrarian

    Imma post it tomorrow, cuz I have to go to bed
     
  13. Keks

    Keks Terrarian

    3. Eye of Cthulhu
    4. Singleplayer
     

    Attached Files:

    • mod1.PNG
      mod1.PNG
      File size:
      87.2 KB
      Views:
      1,123
    • mod2.PNG
      mod2.PNG
      File size:
      54.2 KB
      Views:
      855
    • mod3.PNG
      mod3.PNG
      File size:
      43.8 KB
      Views:
      800
  14. Flashkirby99

    Flashkirby99 Skeletron

    ... That's "Boss Health Bars", not "Yet Another Boss Health Bar". Also it's not by me, so I'm not sure I can help you there.
     
  15. Sapharan

    Sapharan Plantera

    I have a suggestion(s):
    -skyrim like bar decrease (from sides to middle)
    -Layered health bars for bosses that have multiple phases
    -Smaller health bars for bosses that have parts (like skeletron and it's hands)
    -Special features for certain bars (BoC you have to kill its minions first, so a number of icons representing his minions above hp bar)
     
    Last edited: Mar 3, 2017
    Flashkirby99 likes this.
  16. Jeffy

    Jeffy Skeletron Prime

    What mods does this currently support?
     
  17. Flashkirby99

    Flashkirby99 Skeletron

    I may work on this more in the future... but I also need to update Dust and Sound, fix bugs in Expeditions and add hardmode content to WeaponOut. Plus other life things, so idk.
    -That shouldn't be too hard
    -That'd be super useful to have but it'd need to be coded per boss, so beyond vanilla... shrug
    -Same as previous
    -Same as previous

    If the mod has a boss that has a health, it probably supports it. Less simple if the boss does wacky things with it's health and hitbox (like how Brain of Cthulu can't be hurt until the creepers are defeated, or the moonlord having it's core health as a separate entity).
     
  18. Sapharan

    Sapharan Plantera

    Yeah i'm aware of that but.. If you could add these as toggable option for example called "Special Features" and make an inside api to allow people creatinge multiple bars in their mods and/or adding minion counter then it could be totaly doable.
     
    Flashkirby99 likes this.
  19. CirnouliK

    CirnouliK Skeletron Prime

    I'd personally like a download on the page for this myself. This looks essential!
     
    Flashkirby99 likes this.
  20. Xenomus

    Xenomus Spazmatism

    this mod is so simple, but yet so effective and gives a really huge rpg feel:) looking forward to see something like this in terraria ow