• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

How to check if an object is still being attacked?

Status
Not open for further replies.
Well, I have a trigger with an Event: Unit - A unit is attacked, and a couple of conditions, then it will order some units (npc) to move to the attacked unit and attack the attacker (like protect it with their own lives).

That's not the problem, what I want is to check if the attacked unit (specifically, it's just one unit) is still attacked.

If so, those npc units (the guards) will stay there and attack any enemies.
If not, those npc units (the guards) will return to their previous positions (their positions before they protected the unit).

~Thanks in advance!
~supertoinkz
 
By the way, there is another solution too. Although I know you dislike hashtables, it will work out.
  • Zero
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hashtable = (Last created hashtable)
  • One
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Key attack) is stored as a Handle of (Key (Attacking unit)) in Hashtable) Equal to False
        • Then - Actions
          • Hashtable - Save Handle Of(Attacked unit) as (Key attack) of (Key (Attacking unit)) in Hashtable
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Attacked unit) Not equal to (Load (Key attack) of (Key (Attacking unit)) in Hashtable)
            • Then - Actions
              • Hashtable - Clear all child hashtables of child (Key (Attacking unit)) in Hashtable
              • Game - Display to (All players) the text: Another target.
            • Else - Actions
And the test map, in case you don't know a lot of hashtables: View attachment Switch Target Detector.w3x

So, this trigger will check when your attacker will switch a target. When he initially attacks a target, that target is stored to them, and, when he attacks another target, it will detect it. Upon detection (the Game - Display text action), you can stop your units too.
 
Status
Not open for further replies.
Top