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

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