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

Summon auto-follow and attack

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
I tried to make a trigger, in which the summoned unit follows the summoner and attacks nearby enemies.

This is what I came up with (I know the Points are leaking , I will fix this when I got the trigger to work)

  • Untitled Trigger 001
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Summoned unit)) Equal to Wolf Pub
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set VariableSet Summon_Location = (Position of (Summoning unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Summon_Location and (Position of (Summoned unit))) Greater than or equal to 300.00
            • Then - Actions
              • Unit - Order (Summoned unit) to Follow (Summoning unit)
            • Else - Actions
              • Unit - Order (Summoned unit) to Attack-Move To (Summon_Location offset by (150.00, 150.00))
          • Custom script: call RemoveLocation(udg_Summon_Location)
Currently the summoned unit moves once after spawning and then stops. Does anyone can tell me where Iam off?

Cheers.
 
Last edited:
Level 19
Joined
Feb 27, 2019
Messages
580
Using a loop wont do anything. It will still instantly do the same action 10 times.

My guess is the distance is never over 300, so the unit attack moves to a location.

You could do some kind of periodic trigger that checks for nearby valid targets and orders the summoned unit to attack them unless it already has the order attack. If it exceeds a certain range then follow the caster again. So in essence basically the trigger you have but with on a periodic timer
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
Using a loop wont do anything. It will still instantly do the same action 10 times.

My guess is the distance is never over 300, so the unit attack moves to a location.

You could do some kind of periodic trigger that checks for nearby valid targets and orders the summoned unit to attack them unless it already has the order attack. If it exceeds a certain range then follow the caster again. So in essence basically the trigger you have but with on a periodic timer

How can I add a periodic timer to this trigger ? o-o sorry I have no clue
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,509
Event:
Every 1 second of game time

Actions:
Set Hero_Loc = Position of Hero
Set Summon_Loc = Position of Summon
If distance between Hero_Loc and Summon_Loc greater than or equal to 300 then
Order Summon to Follow Hero
Else
Order Summon to Attack-Move to Hero_Loc

Note that 300 is a pretty short "leash" range.
 
Level 7
Joined
May 30, 2018
Messages
290
Event:
Every 1 second of game time

Actions:
Set Hero_Loc = Position of Hero
Set Summon_Loc = Position of Summon
If distance between Hero_Loc and Summon_Loc greater than or equal to 300 then
Order Summon to Follow Hero
Else
Order Summon to Attack-Move to Hero_Loc

Note that 300 is a pretty short "leash" range.

Thanks for the help but Iam not quite sure how to connect both of the triggers :/

  • Untitled Trigger 001
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Summoned unit)) Equal to Wolf Pub
    • Actions
      • Trigger - Add Untitled Trigger 002 <gen> to the trigger queue (Checking conditions)
  • Untitled Trigger 002
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Summon_Location = (Position of (Summoned unit))
      • Set VariableSet Hero_Loc = (Position of (Summoning unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between Hero_Loc and Summon_Location) Greater than or equal to 300.00
        • Then - Actions
          • Unit - Order (Summoned unit) to Follow (Summoning unit)
        • Else - Actions
          • Unit - Order (Summoned unit) to Attack-Move To Hero_Loc
      • Custom script: call RemoveLocation(udg_Summon_Location)
this doesnt seem to work :S halp pls
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,509
Variables are what you use to connect triggers.

There's many ways of doing this, the easiest being something like this:
  • Summon pet
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
    • Actions
      • Set VariableSet Hero = (Summoning unit)
      • Set VariableSet Summon = (Summoned unit)
      • Trigger - Turn on Pet Loop <gen>
Pet Loop is off by default -> The Initially On checkbox is unchecked (located above the trigger next to Enabled).
  • Pet Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Hero_Loc = (Position of Hero)
      • Set VariableSet Summon_Loc = (Position of Summon)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Summon is alive) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Hero_Loc and Summon_Loc) Greater than or equal to 300.00
            • Then - Actions
              • Unit - Order Summon to Follow Hero
            • Else - Actions
              • Unit - Order Summon to Attack-Move To Hero_Loc
        • Else - Actions
          • Trigger - Turn off (This trigger)
      • Custom script: call RemoveLocation (udg_Hero_Loc)
      • Custom script: call RemoveLocation (udg_Summon_Loc)
An important thing to note is that this setup is not MUI. That means that this will only work for 1 Hero and 1 Pet at a time.

The solution to this can be one of many, and some of these solutions are easier than others, but it really all depends on how your map works.

So how does your map work?
How many Hero's can have Pets in your map? Can a Player have more than 1 Pet/Hero at a time?
 

Attachments

  • Pet Example 1.w3m
    16.9 KB · Views: 51
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
Thanks for your help :)

To the MUI issue, there is currently only one other hero with a feral spirit based ability (without any triggers involved) I don't know how far this interferes. And every player has 1 Hero. The max amount of pets per hero should be 1. Would be awesome if you could give me a hint on turning this trigger MUI! So that if different players play the hero simultaneously it still works.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,509
You want to add all of your Pet unit-types to the Conditions in this trigger. This way the trigger only runs for Pets and not just any summoned unit.
  • Summon Pet
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Summoned unit)) Equal to Spirit Wolf (Level 1)
          • (Unit-type of (Summoned unit)) Equal to Dire Wolf (Level 2)
          • (Unit-type of (Summoned unit)) Equal to Shadow Wolf (Level 3)
    • Actions
      • -------- Keep track of the Pet for the summoning Player --------
      • Set VariableSet Pets[(Player number of (Owner of (Summoned unit)))] = (Summoned unit)
      • -------- --------
      • -------- This Unit Group contains all of the Heroes that have Pets --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Summoning unit) is in Pet_Hero_Group.) Equal to False
        • Then - Actions
          • Unit Group - Add (Summoning unit) to Pet_Hero_Group
        • Else - Actions
      • -------- --------
      • -------- Turn on Pet Loop (If it's not already on) --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Pet Loop <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Pet Loop <gen>
        • Else - Actions
Again, this trigger is Initially OFF.
  • Pet Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Pet_Hero_Group and do (Actions)
        • Loop - Actions
          • -------- Picked unit = Hero --------
          • Set VariableSet Pet = Pets[(Player number of (Owner of (Picked unit)))]
          • Set VariableSet Pet_Loc[0] = (Position of (Picked unit))
          • Set VariableSet Pet_Loc[1] = (Position of Pet)
          • -------- --------
          • -------- Check if the Pet/Hero are still alive and then compare their Distances --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • (Pet is alive) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Pet_Loc[0] and Pet_Loc[1]) Greater than or equal to 300.00
                • Then - Actions
                  • Unit - Order Pet to Follow (Picked unit)
                • Else - Actions
                  • Unit - Order Pet to Attack-Move To Pet_Loc[0]
            • Else - Actions
              • -------- This happens if either the Pet or Hero is dead --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Pet is alive) Equal to True
                • Then - Actions
                  • Unit - Kill Pet
                • Else - Actions
              • Unit Group - Remove (Picked unit) from Pet_Hero_Group.
              • -------- --------
              • -------- If this Unit Group is empty then that means there are no Hero/Pets at the moment and we can temporarily turn this off --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in Pet_Hero_Group) Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
          • -------- --------
          • -------- Clean up memory leaks --------
          • Custom script: call RemoveLocation (udg_Pet_Loc[0])
          • Custom script: call RemoveLocation (udg_Pet_Loc[1])
So this isn't actually MUI, it's MPI, meaning each Player can have up to 1 Pet/Hero pair at a time. MPI is easier to do than MUI since we can just plug the Player's Number into the Array Index.

How it works:
I use a Unit Group to contain all of the Pet-owning Heroes and I use a Unit Array to keep track of the Pets.

After summoning a Pet, I turn on Pet Loop which is a trigger that runs every 1.00 second. In Pet Loop I loop through the Unit Group, checking the status of the Heroes and their Pets. If a Hero is dead then I remove the Hero from the Unit Group and kill off it's Pet. If a Pet is dead then I remove the Hero from the Unit Group as well. I then check if the Unit Group is empty, and if it is, I turn off Pet Loop. The reason why I'm turning Pet Loop on/off is to help with performance. After all, there's no reason to have it on if there aren't any Pets alive on the map.

However, if both the Hero and Pet are alive, I execute what is basically your original Distance trigger and order the Pet to Attack/Follow depending on the Distance between the two units.

Note that it could be tweaked so that the Pet isn't killed if the Hero dies, but that was just the easiest way for me to do it.
 

Attachments

  • Pet Example 2.w3m
    18.9 KB · Views: 47
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
You want to add all of your Pet unit-types to the Conditions in this trigger. This way the trigger only runs for Pets and not just any summoned unit.
  • Summon Pet
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Summoned unit)) Equal to Spirit Wolf (Level 1)
          • (Unit-type of (Summoned unit)) Equal to Dire Wolf (Level 2)
          • (Unit-type of (Summoned unit)) Equal to Shadow Wolf (Level 3)
    • Actions
      • -------- Keep track of the Pet for the summoning Player --------
      • Set VariableSet Pets[(Player number of (Owner of (Summoned unit)))] = (Summoned unit)
      • -------- --------
      • -------- This Unit Group contains all of the Heroes that have Pets --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Summoning unit) is in Pet_Hero_Group.) Equal to False
        • Then - Actions
          • Unit Group - Add (Summoning unit) to Pet_Hero_Group
        • Else - Actions
      • -------- --------
      • -------- Turn on Pet Loop (If it's not already on) --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Pet Loop <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Pet Loop <gen>
        • Else - Actions
Again, this trigger is Initially OFF.
  • Pet Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Pet_Hero_Group and do (Actions)
        • Loop - Actions
          • -------- Picked unit = Hero --------
          • Set VariableSet Pet = Pets[(Player number of (Owner of (Picked unit)))]
          • Set VariableSet Pet_Loc[0] = (Position of (Picked unit))
          • Set VariableSet Pet_Loc[1] = (Position of Pet)
          • -------- --------
          • -------- Check if the Pet/Hero are still alive and then compare their Distances --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • (Pet is alive) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Pet_Loc[0] and Pet_Loc[1]) Greater than or equal to 300.00
                • Then - Actions
                  • Unit - Order Pet to Follow (Picked unit)
                • Else - Actions
                  • Unit - Order Pet to Attack-Move To Pet_Loc[0]
            • Else - Actions
              • -------- This happens if either the Pet or Hero is dead --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Pet is alive) Equal to True
                • Then - Actions
                  • Unit - Kill Pet
                • Else - Actions
              • Unit Group - Remove (Picked unit) from Pet_Hero_Group.
              • -------- --------
              • -------- If this Unit Group is empty then that means there are no Hero/Pets at the moment and we can temporarily turn this off --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in Pet_Hero_Group) Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
          • -------- --------
          • -------- Clean up memory leaks --------
          • Custom script: call RemoveLocation (udg_Pet_Loc[0])
          • Custom script: call RemoveLocation (udg_Pet_Loc[1])
So this isn't actually MUI, it's MPI, meaning each Player can have up to 1 Pet/Hero pair at a time. MPI is easier to do than MUI since we can just plug the Player's Number into the Array Index.

How it works:
I use a Unit Group to contain all of the Pet-owning Heroes and I use a Unit Array to keep track of the Pets.

After summoning a Pet, I turn on Pet Loop which is a trigger that runs every 1.00 second. In Pet Loop I loop through the Unit Group, checking the status of the Heroes and their Pets. If a Hero is dead then I remove the Hero from the Unit Group and kill off it's Pet. If a Pet is dead then I remove the Hero from the Unit Group as well. I then check if the Unit Group is empty, and if it is, I turn off Pet Loop. The reason why I'm turning Pet Loop on/off is to help with performance. There's no reason to have Pet Loop on if there aren't any Pets alive on the map.

However, if both the Hero and Pet are alive, I execute what is basically your original Distance trigger and order the Pet to Attack/Follow depending on the Distance between the two units.

Note that it could be tweaked so that the Pet isn't killed if the Hero dies, but that was just the easiest way for me to do it.

Thanks, awesome Ill have a look at it :)!
 
Status
Not open for further replies.
Top