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

[Trigger] Combining at XHP do Action(s) triggers

Status
Not open for further replies.
Level 4
Joined
Dec 31, 2014
Messages
68
Hello all,
Again I'm trying to cut down on the amount of triggers in my map to help the memory.
I have multiple triggers for Separate Units that when their Life reaches a certain amount (or lower) they are ordered to move to a specific region , then to destroy it's own trigger.

For example
  • Enemy1 800hp
    • Events
      • Unit - Enemy1 0566 <gen>'s life becomes Less than or equal to 800.00
    • Conditions
    • Actions
      • Set miscpoint = (Center of Region1 <gen>)
      • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
      • Custom script: call RemoveLocation(udg_miscpoint)
      • Custom script: call DestroyTrigger(GetTriggeringTrigger())
But then to simulate 'AI' at a different Life Value, I have another trigger set up the same way, this time to move to a different region

  • Enemy1 500hp
    • Events
      • Unit - Enemy1 0566 <gen>'s life becomes Less than or equal to 500.00
    • Conditions
    • Actions
      • Set miscpoint = (Center of Region2 <gen>)
      • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
      • Custom script: call RemoveLocation(udg_miscpoint)
      • Custom script: call DestroyTrigger(GetTriggeringTrigger())

Is there a way I can combine both of these triggers into 1? I have quite a few of these unit triggers and I don't think it's doing my memory any favors.
Below is what I have tried but it doesn't work as the game doesn't know to stop one of its IF/THEN/ELSE actions (and I don't know how to tell it to).
  • Enemy1 Fake AI
    • Events
      • Unit - Enemy1 0566 <gen> Takes damage
    • Conditions
    • Actions
      • -------- Enemy1 800hp --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of Enemy1 0566 <gen>) Less than or equal to 800.00
        • Then - Actions
          • Set miscpoint = (Center of Region1 <gen>)
          • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
          • Custom script: call RemoveLocation(udg_miscpoint)
        • Else - Actions
      • -------- Enemy1 500hp --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of Enemy1 0566 <gen>) Less than or equal to 500.00
        • Then - Actions
          • Set miscpoint = (Center of Region2 <gen>)
          • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
          • Custom script: call RemoveLocation(udg_miscpoint)
        • Else - Actions
If it is easier to suggest how I can modify what I have tried please do, also please include trigger examples (I want to keep it simple and to not have to make actual AI)

Thanks
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
Nest one ITE into another. Order those ITEs by priority - thus the one that checks if hp <= 500.00 will be checked sooner than the one for 800.00 hp - that way you remove undesired behaviour.

Look below:
Code:
Your current trigger structure:
If
   hp < 800
Then
   actions
Else
   nothing

If
   hp < 500
Then
   actions
Else
   nothing

Code:
Nested ITEs:
If
   hp < 500
Then
   actions
Else
   If
      hp < 800
   Then
      actions
   Else
      nothing
 
Level 4
Joined
Dec 31, 2014
Messages
68
Hi Nichilus, thanks for your reply.

I managed to get what you suggested to work so thank you for that but there is a bit of a problem. Whenever the unit gets hit it keeps turning and trying to move to where it was ordered to go in the trigger. What I end up with is when my player unit attacks the enemy unit it continuously rotates/moves towards its region and prevents it from attacking unless it hasn't been hit.

This specific unit is an attacking unit where I wanted that at a certain HP it is ordered to go to 1 region only once then at a lower HP it moves to another region only once, but basically auto-attacks at where it last left off. That is why I originally could only think to do it as single triggers.

Possibly there is another 'event' I could use instead of 'A Unit Takes Damage' which can solve this?
 
Level 4
Joined
Dec 31, 2014
Messages
68
I think I have found a 'hack' way of doing what I wanted but it requires some tinkering and it isn't as perfect as I would like;

  • Enemy1 AI
    • Events
      • Unit - Enemy1 0566 <gen> Takes damage
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of Enemy1 0566 <gen>) Less than 500.00
          • (Life of Enemy1 0566 <gen>) Greater than 420.00
        • Then - Actions
          • Set miscpoint = (Center of EnemyAI2 <gen>)
          • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
          • Custom script: call RemoveLocation(udg_miscpoint)
          • Custom script: call DestroyTrigger(GetTriggeringTrigger())
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of Enemy1 0566 <gen>) Less than 800.00
              • (Life of Enemy1 0566 <gen>) Greater than 720.00
            • Then - Actions
              • Set miscpoint = (Center of Enemy1AI1 <gen>)
              • Unit - Order Enemy1 0566 <gen> to Move To miscpoint
              • Custom script: call RemoveLocation(udg_miscpoint)
            • Else - Actions
Is there not a better way of doing this? I ask because as the above does work, in some instances the enemy may be hit inbetween the 800-720 mark and so for that period the enemy just spins around like a lunatic, but in other instances you could damage the enemy more than that the HP Range and so the enemy just stays in place or possibly doesn't move to the next region.
 
Level 4
Joined
Dec 31, 2014
Messages
68
Hey Empirean, What do you mean sorry?
Put that particular enemy into an Unit Group and check it's HP? I don't really follow.
Can you give me an example of what you're suggesting?
 
Level 13
Joined
Jun 20, 2014
Messages
479
its rough but here it goes

First event, map init or whatever it is
Event
- Map Init
Condition
-
Action
- Unit Group - add Enemy to UnitGroup

then theres another trigger
Event
- periodic 0.03
Condition
-
Action
- Pick every unit in UnitGroup and do actions
- set PickedUnit = picked unit
- if life of (PickedUnit) < 800
- then
- your actions
- else
- if life of (PickedUnit) < 500
- then
- your actions
- so on
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
I managed to get what you suggested to work so thank you for that but there is a bit of a problem. Whenever the unit gets hit it keeps turning and trying to move to where it was ordered to go in the trigger. What I end up with is when my player unit attacks the enemy unit it continuously rotates/moves towards its region and prevents it from attacking unless it hasn't been hit.
You need to keep track of what you ordered your unit to do. If your trigger is supposed to order unit to do some action only once per HP treshold, then you could use an integer as a counter.
Something like this:
Code:
var X = 0 //initialization value

Events
   Enemy takes damage
Conditions
   ---
Actions
   If (Conditions)
      X == 1
      Hp < 500
   Then (Actions)
      Order enemy to do something
      X = X + 1
   Else (Actions)
      If (Conditions)
         X == 0
         Hp < 800
      Then (Actions)
         Order enemy to do something
         X = X + 1
      Else (Actions)
What happens here is the following:
Value of X is 0. Now unit takes damage, but it doesn't get below 800 hp, so nothing happens. After some time, an attack brings that unit below 800 hp - the value of X is still equal to 0, so the actions of that ITE fire and order your unit to do something and also increase the value of X by 1. The next time your unit takes damage it is below 800 hp, however the value of X is no longer equal to 0, so nothing happens. Last, after you get unit below 500 hp, both conditions pass (X == 1 and hp < 500) so the action fires and value of X is increased once again.
 
Level 4
Joined
Dec 31, 2014
Messages
68
Cool, thank you both for your suggestions. Both worked but I decided to go with what Nichilus suggested, I wasn't keen on having a periodic event as I have had memory leak issues doing things like that, bit of Paranoia also I think heh. Anyway thanks again, Rep for both of you.
 
Status
Not open for further replies.
Top