• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Decrease a unit's percent MAX HP via item

Status
Not open for further replies.
Level 4
Joined
Mar 9, 2023
Messages
37
Hi! I'm very inexperienced writing vJass scripts and poor at setting up elaborate triggers. It doesn't help that I'm aloof today, and I want to push out a patch for my players. Can I ask for your help?

I need to create a GUI or vJass script which effectively halves a hero's MAX HP while it is in effect. It will be attached to an item, so while the hero holds the item its max values are lowered by an amount of percent. So if the solution were to create a permanent effect, I would need to create a trigger which removes the effect if the item is removed.

The following thread was the closest I found, and I realise I can repurpose the trigger created by Meticulous, but right now I can't fully understand the solution. Please lend me your wisdom!
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,700
Hello, I recommend looking at threads made in the last 3-4 years, as pretty much everything else is really dated. That's assuming that you're on patch 1.31+ when most big changes occurred (current patch is 1.35).

Anyway, if your unit can increase it's Max HP while the item is equipped then understand that this is no simple task. Max HP could come from gaining Strength from a level up, acquiring another Item that increases Strength/HP, and custom abilities/triggers.

You will need to account for all of these things in order to maintain this effect properly. Also, if your unit can acquire multiple of these Items then it gets even more complicated.

I can attach a map that shows how to handle this if you'd like but I can't guarantee that it will take into consideration every single edge case. Also, you can't open the map unless you're on the latest patch like me.
 
Level 4
Joined
Mar 9, 2023
Messages
37
Hello, I recommend looking at threads made in the last 3-4 years, as pretty much everything else is really dated. That's assuming that you're on patch 1.31+ when most big changes occurred (current patch is 1.35).

Anyway, if your unit can increase it's Max HP while the item is equipped then understand that this is no simple task. Max HP could come from gaining Strength from a level up, acquiring another Item that increases Strength/HP, and custom abilities/triggers.

You will need to account for all of these things in order to maintain this effect properly. Also, if your unit can acquire multiple of these Items then it gets even more complicated.

I can attach a map that shows how to handle this if you'd like but I can't guarantee that it will take into consideration every single edge case. Also, you can't open the map unless you're on the latest patch like me.
As you've mentioned, I understand it is not as simply as decreasing a value. I'd still like to try!

I'm also on the latest. Any points of reference will help greatly, thanks!
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,700
I got it working for the most part but it'll require some configuration to work with the specifics of your map. Note that there's a very small amount of permanent life loss that occurs during the calculations that I tried to account for but gave up on because math is hard.

It also depends on a Unit Indexer to be present in your map if you wish for this to be MUI (work for multiple units at once). Oh, and no unit should ever have more than 1 of these HP halving items at a time.
 

Attachments

  • Max HP Item 1.w3m
    24.9 KB · Views: 3
Last edited:
Level 4
Joined
Mar 9, 2023
Messages
37
I got it working for the most part but it'll require some configuration to work with the specifics of your map. Note that there's a very small amount of permanent life loss that occurs during the calculations that I tried to account for but gave up on because math is hard.

It also depends on a Unit Indexer if you wish for this to be MUI. Oh, and no unit should ever have more than 1 of these HP halving items at a time.
Wow! This is incredible! Tried it out, ported it over, and it instantly worked like a charm! I could not make it myself, so I'm in awe at your skill. I am grateful for your time and effort to make this. Thank you!

I'll not forget to credit!
 
Level 40
Joined
Feb 27, 2007
Messages
5,091
@Uncle It's possible to do this without having to account for every possible source of HP manipulation in the map. You just need to store both the 'bonus' HP (in this case negative but still works) and the total HP you set the unit to, and then just periodically check those values. If the max hp is different than the last time you checked: remove the bonus, recalculate the bonus, and add the bonus back.
  • //On cast:
  • Set CR_BonusHP[CR_CV] = ((Max life of CR_Unit) x -0.50)
  • Set CR_MaxHP[CR_CV] = (Integer(((Max life of CR_Unit) + CR_BonusHP[CR_CV]))) //this is an integer now
  • Unit - Set Max HP of CR_Unit to CR_MaxHP[CR_CV]
  • //In periodic:
  • Set TempHP = (Max life of CR_Unit) //real
  • If (all conditions)...
    • If - Conditions
      • (Integer(TempHP)) not equal to CR_MaxHP[CR_CV]
      • Then - Actions
        • Set TempHP = (TempHP - BonusHP[CR_CV])
        • Set CR_BonusHP[CR_CV] = (TempHP x -0.50)
        • Set CR_MaxHP[CR_CV] = (Integer((TempHP + CR_BonusHP[CR_CV])))
        • Unit - Set Max HP of CR_Unit to CR_MaxHP[CR_CV]
The only complications with this are that it's still possible to lose 1 hp from rounding in specific circumstances, and if adding max HP heals the unit when it happens then that needs to be accounted for.
 
Status
Not open for further replies.
Top