• 🏆 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!

Making Hero Lose HP Over Time by Item

Status
Not open for further replies.
Level 1
Joined
Feb 15, 2020
Messages
2
Hello all,

I have just started using the Reforged Warcraft editor and am loving it so far. I have some basic coding
skills and level design skills but am very new to it. I'm trying to make an item that has a big damage increase buff, but halves the heroes max HP when they have said item.
* Im using a variable to track if the player has said item, if they have item, I make them lose health *

1. I can't find a "set percentage of hp" function. At the moment I am making the hero lose a set integer of HP. However I want it to be 50% so I can balance it for heroes with different HP stats.

2. I can't get the hero to go back to its standard health when the item is dropped.


Any and all help is much appreciated :)
 

Attachments

  • Losing HP Snippet.PNG
    Losing HP Snippet.PNG
    11.8 KB · Views: 31
Level 39
Joined
Feb 27, 2007
Messages
5,013
  • Welcome! When you need to refer to a trigger on this forum, please post it this way instead of using an image (it's simpler too!): How To Post Your Trigger
  • You may also find these links helpful for your mapmaking needs (though they are not relevant to the question you have posted here, I find myself linking them multiple times a day so here you go now you have them preemptively):
  • There is no way to set a percentage of HP, you can only set the number directly. This has a few implications:
    • You need to know exactly how much you took away when you want to add it back later; this will have to be stored in a variable somewhere.
    • If the unit changes its hp for any reason (levels up, picks up an item that adds hp, allocates stat points to strength, gains an ability that affects strength or max hp, etc.), the health it has after this event will not be correct since the 50% modifier has not been applied to that newly gained health.
    • I believe increasing max hp will not also give that amount to the unit as current hp, so you'll have to heal it after you increase it back (or don't if you don't want it to auto-heal)
    • When the unit picks up the item, should its current hp stay the same % or the same #? (In the latter case it would still be capped at the new max, obviously)
    • If there are multiple such hp-%-affecting effects a unit can have in your map, this process will become recursive and you'll have to decide when to stop that recursion loop to prevent a threadcrash.

  • These issues are a bit of a pain to work around, but it can definitely be done. You can manually track all of those events to know when hp changes... or you can take the lazy route and just periodically check max hp of the unit to see if it's different from the last time you checked. Then update its max hp accordingly. By storing the percentage hp remaining for the unit you remove the need to have a variable that tracks how much hp you've stolen from it.
  • Events
    • Unit - A unit acquires an item
  • Conditions
    • (Item-type of (Item being manipulated)) equal to Wiseys Blade
  • Actions
    • Set W_Unit = (Triggering Unit)
    • Set W_LastMax = (Max HP of W_Unit) //this is a real variable, not integer, because health is actually a real number; the function to change the max only accepts integer input for some reason)
    • Set W_HPPctRemainig = 0.50 //what % health should the unit have after acquiring this item. If you wanted to reduce hp by 80% this number should be 0.20
    • Unit - Set Max HP of W_Unit to Integer(W_LastMax x W_HPPctRemaining)
    • Set W_LastMax = (Max HP of W_Unit)
    • -------- this is where you would set current hp depending on how you want it to work --------
    • Trigger - Turn on (PERIODIC TRIGGER BELOW)
  • Events
    • Unit - A unit loses an item
  • Conditions
    • (Item-type of (Item being manipulated)) equal to Wiseys Blade
  • Actions
    • Unit - Set Max HP of W_Unit to Integer(W_LastMax / W_HPPctRemaining) //this is division now instead of multiplication, to undo what we did before
    • Trigger - Turn off (PERIODIC TRIGGER BELOW)
  • Events
    • Time - Every 0.20 seconds of game-time
  • Conditions
  • Actions
    • Set W_NewMax = (Max HP of W_Unit)
    • Set W_DiffMax = (W_NewMax - W_LastMax)
    • Unit - Set Max HP of W_Unit to Integer(W_LastMax + (W_DiffMax x W_HPPctRemaining)) //because a unit could lose max HP for any of the reasons stated above, too, we must be ready to go in either direction (increase or decrease); this line does this (think about it)
    • Set W_LastMax = (Max HP of W_Unit)
    • -------- this is where you would set current hp depending on how you want it to work --------
 
Status
Not open for further replies.
Top