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

Make A Unit only attack specific unit when come in range

Level 2
Joined
Jul 26, 2012
Messages
7
Hai , first of all english is not my native language so sorry if there's any bad grammar. My question is:
I make 1 unit that can attack anything, but when this unit come near any tower or building i want that unit only focus attacking them. if u play dota it was like their siege unit , only attack the tower when this siege unit is near the tower and if the tower destroyed the siege unit continue move and can attack anything again. Please help me, thank you.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,688
Hai , first of all english is not my native language so sorry if there's any bad grammar. My question is:
I make 1 unit that can attack anything, but when this unit come near any tower or building i want that unit only focus attacking them. if u play dota it was like their siege unit , only attack the tower when this siege unit is near the tower and if the tower destroyed the siege unit continue move and can attack anything again. Please help me, thank you.
I'm not sure if there's an easier way to do it but these triggers will work:
  • Siege Focus Structures
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Level of Siege Focus Structures (Siege System) for (Attacking unit)) Equal to 1
      • ((Attacked unit) is A structure) Equal to False
    • Actions
      • Set VariableSet Siege_Attacker = (Attacking unit)
      • Set VariableSet Siege_Point = (Position of Siege_Attacker)
      • Set VariableSet Siege_Group = (Units within (Default acquisition range of Siege_Attacker) of Siege_Point.)
      • Custom script: call RemoveLocation( udg_Siege_Point )
      • -------- --------
      • -------- Determine if we've found a structure to retarget to: --------
      • Set VariableSet Siege_Found_Target = False
      • Unit Group - Pick every unit in Siege_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet Siege_Target = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Siege_Found_Target Equal to False
              • (Siege_Target is A structure) Equal to True
              • (Siege_Target is alive) Equal to True
              • (Siege_Target belongs to an enemy of (Owner of Siege_Attacker).) Equal to True
            • Then - Actions
              • Set VariableSet Siege_Found_Target = True
            • Else - Actions
      • -------- --------
      • Custom script: call DestroyGroup( udg_Siege_Group )
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Siege_Found_Target Equal to True
        • Then - Actions
          • -------- It found a nearby structure to attack! --------
          • Trigger - Turn off Siege Focus Structures <gen>
          • Unit - Order Siege_Attacker to Attack Siege_Target
          • Trigger - Turn on Siege Focus Structures <gen>
        • Else - Actions
          • -------- No structure found! --------
          • Unit - Set level of Siege Focus Structures (Siege System) for Siege_Attacker to 2
          • Trigger - Run Siege Focus Remove Restriction <gen> (ignoring conditions)
  • Siege Focus Remove Restriction
    • Events
    • Conditions
    • Actions
      • -------- Note: --------
      • -------- This trigger prevents a Siege attacker from constantly trying to re-target when there are no nearby structures. --------
      • -------- --------
      • Custom script: local unit u = udg_Siege_Attacker
      • Wait 3.00 game-time seconds
      • Custom script: set udg_Siege_Attacker = u
      • Custom script: set u = null
      • Unit - Set level of Siege Focus Structures (Siege System) for Siege_Attacker to 1
1715442727862.png

This ability should be added to your Siege units that use this system:
siegeAbility.png
 

Attachments

  • Siege Focus Structures.w3m
    19.4 KB · Views: 0
Level 2
Joined
Jul 26, 2012
Messages
7
I'm not sure if there's an easier way to do it but these triggers will work:
  • Siege Focus Structures
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Level of Siege Focus Structures (Siege System) for (Attacking unit)) Equal to 1
      • ((Attacked unit) is A structure) Equal to False
    • Actions
      • Set VariableSet Siege_Attacker = (Attacking unit)
      • Set VariableSet Siege_Point = (Position of Siege_Attacker)
      • Set VariableSet Siege_Group = (Units within (Default acquisition range of Siege_Attacker) of Siege_Point.)
      • Custom script: call RemoveLocation( udg_Siege_Point )
      • -------- --------
      • -------- Determine if we've found a structure to retarget to: --------
      • Set VariableSet Siege_Found_Target = False
      • Unit Group - Pick every unit in Siege_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet Siege_Target = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Siege_Found_Target Equal to False
              • (Siege_Target is A structure) Equal to True
              • (Siege_Target is alive) Equal to True
              • (Siege_Target belongs to an enemy of (Owner of Siege_Attacker).) Equal to True
            • Then - Actions
              • Set VariableSet Siege_Found_Target = True
            • Else - Actions
      • -------- --------
      • Custom script: call DestroyGroup( udg_Siege_Group )
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Siege_Found_Target Equal to True
        • Then - Actions
          • -------- It found a nearby structure to attack! --------
          • Trigger - Turn off Siege Focus Structures <gen>
          • Unit - Order Siege_Attacker to Attack Siege_Target
          • Trigger - Turn on Siege Focus Structures <gen>
        • Else - Actions
          • -------- No structure found! --------
          • Unit - Set level of Siege Focus Structures (Siege System) for Siege_Attacker to 2
          • Trigger - Run Siege Focus Remove Restriction <gen> (ignoring conditions)
  • Siege Focus Remove Restriction
    • Events
    • Conditions
    • Actions
      • -------- Note: --------
      • -------- This trigger prevents a Siege attacker from constantly trying to re-target when there are no nearby structures. --------
      • -------- --------
      • Custom script: local unit u = udg_Siege_Attacker
      • Wait 3.00 game-time seconds
      • Custom script: set udg_Siege_Attacker = u
      • Custom script: set u = null
      • Unit - Set level of Siege Focus Structures (Siege System) for Siege_Attacker to 1
View attachment 472639
This ability should be added to your Siege units that use this system:
View attachment 472641
big thank you for your help, i'll try this trigger.
but how about the "move along" i mean when he not find any structure or the structure was destroyed he will continue move to the targeted position
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,688
No problem.

If you want a unit to attack towards a position you use the Attack-Move order:
  • Actions
    • Set Variable TempPoint = (Some position)
    • Unit - Order (Some unit) to Attack-Move to TempPoint
But I imagine this order will break that previous order:
  • Unit - Order Siege_Attacker to Attack Siege_Target
In which case, you simply need to re-issue the order again when it can't find a Siege_Target:
  • -------- No structure found! --------
  • Set Variable TempPoint = (Some position)
  • Unit - Order Siege_Attacker to Attack-Move to TempPoint
 
Last edited:
Top