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

Remove an ability after a Unit has (x)HP ?

Status
Not open for further replies.
Level 4
Joined
Aug 12, 2014
Messages
48
I have an ability based on Unholy Aura that is added to select units below 500 HP.

  • Add Fire Buff
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Frigate Class
          • (Unit-type of (Triggering unit)) Equal to Battleship Class
          • (Unit-type of (Triggering unit)) Equal to Pirate Fleet Class
          • (Unit-type of (Triggering unit)) Equal to Pirate Raider Class
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of (Triggering unit)) Less than or equal to 500.00
        • Then - Actions
          • Unit - Add On Fire to (Triggering unit)
        • Else - Actions
          • Do nothing
The problem I am having is removing it from any unit above 500 HP once it has been repaired. Anything I have tried (my knowledge is limited) has not worked. I am sorry for asking, I tried following a few guides and reverse engineering triggers I copied from other maps but I am not having any luck.


  • Remove Fire Buff
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Picked unit)) Equal to Frigate Class
          • (Unit-type of (Picked unit)) Equal to Battleship Class
          • (Unit-type of (Picked unit)) Equal to Pirate Raider Class
          • (Unit-type of (Picked unit)) Equal to Pirate Fleet Class
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of (Triggering unit)) Greater than or equal to 500.00
        • Then - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Unit - Remove On Fire from (Picked unit))
        • Else - Actions
          • Do nothing



  • Remove Fire Buff Copy
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set OnFire = (Units in (Playable map area) matching ((Life of (Picked unit)) Greater than or equal to 501.00))
      • Unit Group - Pick every unit in OnFire and do (Actions)
        • Loop - Actions
          • Set OnFire_Unit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to 501.00
            • Then - Actions
              • Unit - Remove On Fire from (Picked unit)
            • Else - Actions
              • Do nothing


So I tried with variables and setting up unit groups, but I have never made a trigger like this, so I really don't know what I am doing. I think I am still missing variables in this, but I don't know and really don't know what type of variables they should be.

Thanks for any help.
 
Level 5
Joined
Jan 17, 2014
Messages
131
Add the units to your group when you give them the ability and with periodic event check if units in the group are above 500 HP and if they are, remove them from the group + remove the ability from them.

Example:

  • Trigger 1
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to "Your unit type"
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of (Triggering unit)) Less than or equal to 500.00
        • Then - Actions
          • Unit - Add "Your Ability" to (Triggering unit)
          • Unit Group - Add (Triggering unit) to "Your Unit Group"
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Trigger 2 <gen> is on) Equal to False
            • Then - Actions
              • Trigger - Turn on Trigger 2 <gen>
            • Else - Actions
              • Do nothing
        • Else - Actions
          • Do nothing
  • Trigger 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in "Your Unit Group" and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than 500.00
            • Then - Actions
              • Unit - Remove "Your Ability" from (Picked unit)
              • Unit Group - Remove (Picked unit) from "Your Unit Group"
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ("Your Unit Group" is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
                  • Do nothing
            • Else - Actions
              • Do nothing
 
Level 4
Joined
Aug 12, 2014
Messages
48
Sweet, its working. In all honestly, I got it to work when you first answered but before you had posted the triggers. I did not have the additional conditions to turn the 2nd trigger on and off though which is a great addition. Thank you very much! :)
 
Last edited:
Level 5
Joined
Jan 17, 2014
Messages
131
Sweet, its working. In all honestly, I got it to work before you had posted the triggers. I did not have the additional conditions to turn the 2nd trigger on and off though which is a great addition. Thank you very much! :)

No problem, happy to help.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
You should do what ivofena wrote.
To your triggers. In trigger 1 (fail 1), you have a list of conditions in the OR block. For the OR block to proceed as true, at least 1 condition has to be true. Now the thing there is that you check if "(Picked unit) is equal to something". However (Picked unit) from what? Where did you pick that unit? The (Picked unit) is a unit which is picked via the "Unit Group - Pick every unit and do actions" action.
Then you have a condition in If/Then/Else "(Life of (Triggering unit)) Greater than or equal to 500.00", here you use (Triggering unit) however what (triggering unit) is there? Triggering unit is a unit which fired the respective trigger. Your trigger is fired by periodic event, not by a unit.
So in both cases, (Picked unit) and (Triggering unit) refer to no unit, which returns null, which in most cases return the condition as False.


Fail 2 trigger looks a lot better, however the error there is in this specific line:
  • Set OnFire = (Units in (Playable map area) matching ((Life of (Picked unit)) Greater than or equal to 501.00))
When making unit groups that match your specific condition, you have to refer to the units in question as to (Matching unit), not to (Picked unit), because those units are not yet picked. So the line should actually look like this:
  • Set OnFire = (Units in (Playable map area) matching ((Life of (Matching unit)) Greater than or equal to 501.00))
Notice that I simply replaced (Picked unit) for (Matching unit).
Again I will write it here: (Matching unit) is used only for condition when picking units into unit group. If you are applying some action on the units in unit group, you refer to them as (Picked unit). Example is below. Look where I used matching unit and where picked unit.
  • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Life of (Matching unit)) Greater than or equal to 501.00)) and do (Actions)
    • Loop - Actions
      • Unit - Remove On Fire from (Picked unit)
Apart from that, in both triggers do not use the "Do nothing" action, as it is not required to be there (you can leave empty space there), and the action itself does nothing but stress your PC a bit. Also, the second trigger does not need another If/Then/Else inside the unit group that checks if unit has more than 501 hp.

Last but not least, those trigger leak. Simply put, most things in WCIII take memory space when they are created, but they are never destroyed automatically, so you have to do it manually when you are done using it to free the memory they take, else they leak this memory. Check this thread: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
It's just a matter of using specific custom scripts on specific actions as written in the thread I posted above.
 
Level 4
Joined
Aug 12, 2014
Messages
48
@Nichilus:
Thanks for taking the time to shed some light on this. The triggers I posted above are random ones I copied here - in truth, I had another 4, or 5 triggers that I tried and marked as disabled before going back to the drawing board. I get most of the principles behind things and what you explained but as soon as I mess up and something doesn't work, I kinda lose it and start making a dozen, slightly altered triggers trying to troubleshoot the problem. As a last resort I come on here and ask if I feel I truly cant figure it out. (I think you learn less that way if others just give you the answer)

So in some cases I did do what you suggested (just didn't know WHY I was doing it) so again, thanks for the explanation! I really appreciate you and iyofena's help!

As for the leaks. I understand they WHY on that but haven't moved on to fixing the errors/leaks. I guess that's bad form and I should do it right the first time rather then going back and fixing it once the map is done.

At around 200+ triggers on my map is it now finally starting to bog down a little. Going to be a headache down the road but at least the basics of the map is almost done. I am excited to do my first project post here soon.
 
Last edited:
Status
Not open for further replies.
Top