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

Units "searching" for enemies

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
Iam just curious as it could be really usefull for my map: Is there a way to make spawning units more or less "consciously" look for enemies? So when they find enemies they somewhat coordinated start to move to that location? Or is it just possible to let units randomly attack move around the map?

Is it maybe even possible to just turn on the standard meele-ai to achieve this? (if the unit is ai controlled)

Would be glad, if someone has an idea and, if it's possible, maybe show me a way :)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,515
To randomly attack around the map you can periodically order your desired units to attack-move to a random point in the map.
  • Periodically Attack Example
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile.) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To (Random point in (Playable map area))
And here's a basic system.

Note that a better system would require more information in regards to how your map works.

How it works: The system periodically orders the Computer's units to Attack-Move to random points in the map in hopes that they bump into an enemy. When they do find an enemy (which is done by checking if they're attacked/attacking) a Point is set at that position and ALL of the Computer's units are ordered to attack towards it. During this "Coordinated Attack" I run/reset a 4.00 second Timer whenever a Computer unit is attacked/attacks. If this Timer manages to expire then that means that no Computer unit has attacked/been attacked in the last 4 seconds, which means that the Coordinated Attack is most likely finished and we can return the units back to their normal "Randomly search the map" behavior.
  • Add to Attack Group
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
      • (Owner of (Triggering unit)) Equal to AttackComputer
      • ((Triggering unit) is A structure) Equal to False
    • Actions
      • Unit Group - Add (Triggering unit) to AttackGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CoordinatedAttackIsOn Equal to True
        • Then - Actions
          • Unit - Order (Triggering unit) to Attack-Move To AttackPoint
        • Else - Actions
  • Remove from Attack Group
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in AttackGroup.) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from AttackGroup.
  • Periodically Attack Random Point
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • CoordinatedAttackIsOn Equal to False
    • Actions
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
            • Then - Actions
              • Set VariableSet RandomPoint = (Random point in (Playable map area))
              • Unit - Order (Picked unit) to Attack-Move To RandomPoint
              • Custom script: call RemoveLocation (udg_RandomPoint)
            • Else - Actions
  • Start Coordinated Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to False
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Trigger - Turn off Periodically Attack Random Point <gen>
      • Set VariableSet CoordinatedAttackIsOn = True
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To AttackPoint
  • Check If Attack Is Finished
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Custom script: call RemoveLocation (udg_AttackPoint)
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Countdown Timer - Start AttackCheckTimer as a One-shot timer that will expire in 4.00 seconds
  • Attack Is Finished
    • Events
      • Time - AttackCheckTimer expires
    • Conditions
    • Actions
      • Set VariableSet CoordinatedAttackIsOn = False
      • Trigger - Turn on Periodically Attack Random Point <gen>
      • Custom script: call RemoveLocation (udg_AttackPoint)
I attached an example map.
 

Attachments

  • Attack System 1.w3m
    19.9 KB · Views: 21
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
To randomly attack around the map you can periodically order your desired units to attack-move to a random point in the map.
  • Periodically Attack Example
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile.) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To (Random point in (Playable map area))
And here's a basic system.

Note that a better system would require more information in regards to how your map works.

How it works: The system periodically orders the Computer's units to Attack-Move to random points in the map in hopes that they bump into an enemy. When they do find an enemy (which is done by checking if they're attacked/attacking) a Point is set at that position and ALL of the Computer's units are ordered to attack towards it. During this "Coordinated Attack" I run/reset a 4.00 second Timer whenever a Computer unit is attacked/attacks. If this Timer manages to expire then that means that no Computer unit has attacked/been attacked in the last 4 seconds, which means that the Coordinated Attack is most likely finished and we can return the units back to their normal "Randomly search the map" behavior.
  • Add to Attack Group
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
      • (Owner of (Triggering unit)) Equal to AttackComputer
      • ((Triggering unit) is A structure) Equal to False
    • Actions
      • Unit Group - Add (Triggering unit) to AttackGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CoordinatedAttackIsOn Equal to True
        • Then - Actions
          • Unit - Order (Triggering unit) to Attack-Move To AttackPoint
        • Else - Actions
  • Remove from Attack Group
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in AttackGroup.) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from AttackGroup.
  • Periodically Attack Random Point
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • CoordinatedAttackIsOn Equal to False
    • Actions
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
            • Then - Actions
              • Set VariableSet RandomPoint = (Random point in (Playable map area))
              • Unit - Order (Picked unit) to Attack-Move To RandomPoint
              • Custom script: call RemoveLocation (udg_RandomPoint)
            • Else - Actions
  • Start Coordinated Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to False
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Trigger - Turn off Periodically Attack Random Point <gen>
      • Set VariableSet CoordinatedAttackIsOn = True
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To AttackPoint
  • Check If Attack Is Finished
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Custom script: call RemoveLocation (udg_AttackPoint)
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Countdown Timer - Start AttackCheckTimer as a One-shot timer that will expire in 4.00 seconds
  • Attack Is Finished
    • Events
      • Time - AttackCheckTimer expires
    • Conditions
    • Actions
      • Set VariableSet CoordinatedAttackIsOn = False
      • Trigger - Turn on Periodically Attack Random Point <gen>
      • Custom script: call RemoveLocation (udg_AttackPoint)
I attached an example map.


Wow awesome, that's really all I could've hoped for! Thanks Uncle. I remade the trigger in my map and really understood the workings behind it and the variables! Really well explained. Take my +rep :)
 
Level 7
Joined
May 30, 2018
Messages
290
To randomly attack around the map you can periodically order your desired units to attack-move to a random point in the map.
  • Periodically Attack Example
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile.) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To (Random point in (Playable map area))
And here's a basic system.

Note that a better system would require more information in regards to how your map works.

How it works: The system periodically orders the Computer's units to Attack-Move to random points in the map in hopes that they bump into an enemy. When they do find an enemy (which is done by checking if they're attacked/attacking) a Point is set at that position and ALL of the Computer's units are ordered to attack towards it. During this "Coordinated Attack" I run/reset a 4.00 second Timer whenever a Computer unit is attacked/attacks. If this Timer manages to expire then that means that no Computer unit has attacked/been attacked in the last 4 seconds, which means that the Coordinated Attack is most likely finished and we can return the units back to their normal "Randomly search the map" behavior.
  • Add to Attack Group
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
      • (Owner of (Triggering unit)) Equal to AttackComputer
      • ((Triggering unit) is A structure) Equal to False
    • Actions
      • Unit Group - Add (Triggering unit) to AttackGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CoordinatedAttackIsOn Equal to True
        • Then - Actions
          • Unit - Order (Triggering unit) to Attack-Move To AttackPoint
        • Else - Actions
  • Remove from Attack Group
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in AttackGroup.) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from AttackGroup.
  • Periodically Attack Random Point
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • CoordinatedAttackIsOn Equal to False
    • Actions
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
            • Then - Actions
              • Set VariableSet RandomPoint = (Random point in (Playable map area))
              • Unit - Order (Picked unit) to Attack-Move To RandomPoint
              • Custom script: call RemoveLocation (udg_RandomPoint)
            • Else - Actions
  • Start Coordinated Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to False
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Trigger - Turn off Periodically Attack Random Point <gen>
      • Set VariableSet CoordinatedAttackIsOn = True
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Unit Group - Pick every unit in AttackGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To AttackPoint
  • Check If Attack Is Finished
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • CoordinatedAttackIsOn Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Attacked unit)) Equal to AttackComputer
          • (Owner of (Attacking unit)) Equal to AttackComputer
    • Actions
      • Custom script: call RemoveLocation (udg_AttackPoint)
      • Set VariableSet AttackPoint = (Position of (Attacked unit))
      • Countdown Timer - Start AttackCheckTimer as a One-shot timer that will expire in 4.00 seconds
  • Attack Is Finished
    • Events
      • Time - AttackCheckTimer expires
    • Conditions
    • Actions
      • Set VariableSet CoordinatedAttackIsOn = False
      • Trigger - Turn on Periodically Attack Random Point <gen>
      • Custom script: call RemoveLocation (udg_AttackPoint)
I attached an example map.


Hey @Uncle,

I know it has been a while, but I wondered if this system is transferable to 6 AI's , not just one?

More Information: There are 6 Players, who can build structures. These produce units, that are AI controlled. Every player has his respective AI to take controll over their units. Now I need these AI controlled units to roam the map and "look for enemies" similar to the trigger you already posted.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,515
I think this will work. I haven't tested it too thoroughly though.

Basically the same system but this time with Arrays for everything. I use the Player Number of the AI to differentiate between the variables, so AttackPoint[19] is where Player 1's units will Attack, since Player 19 is the AI for Player 1.
 

Attachments

  • Attack System 2.w3m
    26.2 KB · Views: 29
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
I think this will work. I haven't tested it too thoroughly though.

Basically the same system but this time with Arrays for everything. I use the Player Number of the AI to differentiate between the variables, so AttackPoint[19] is where Player 1's units will Attack, since Player 19 is the AI for Player 1.

Works perfect! Amazing job...as always! Thanks a lot! +rep!!!
 
Level 7
Joined
May 30, 2018
Messages
290
I think this will work. I haven't tested it too thoroughly though.

Basically the same system but this time with Arrays for everything. I use the Player Number of the AI to differentiate between the variables, so AttackPoint[19] is where Player 1's units will Attack, since Player 19 is the AI for Player 1.

Hey Uncle, it's me again :p

A weird, lets call it "bug" appeared within the system you created and I don't know if it's fixable, but Iam gonna ask anyways to see if you maybe have an idea. :)

Your system works properly and does what it's supposed to do, but: Sometimes after the units finished an attack they start to run back to where they spawned and wait there for the next attack to occure instead of continuing to roam the map randomly again. It seems like they get confused after the coordinated attack is done and just return to their spawn until another attack is detected. If it is possible I'd like them to not return to the spawn after the coordinated attack is finished. Maybe you have an idea whats the issue here. :)
 
Level 7
Joined
May 30, 2018
Messages
290
Yeah, that's just the AI telling them to return to where they came from. After 4.00 seconds (or however long you set the Timer) they should go back to randomly scouring the map.

There's actually the problem, after the 4 seconds are over, they keep moving back to their spawn and only after they reached their spawn, they start to move randomly again. So they dont start moving randomly after the 4 seconds, but after they moved back to their spawn first. I left the timer on 4 seconds, but seems like that order gets overwritten by first going back to their spawn. :thinking:
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,515
Not happening for me when I test the map, weird.

Edit: Now I see it, after a while they stopped randomly patrolling and ran to the center of the map.

There is an issue with Warcraft 3 that after a certain number of units are created for a player their units will begin to stand still and ignore orders. That's definitely happening once there's too many footman on the map. It usually starts happening around 100 units.
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
Not happening for me when I test the map, weird.

Edit: Now I see it, after a while they stopped randomly patrolling and ran to the center of the map.

There is an issue with Warcraft 3 that after a certain number of units are created for a player their units will begin to stand still and ignore orders. That's definitely happening once there's too many footman on the map. It usually starts happening around 100 units.


Alright, thank you. Guess it's a problem I created on my end, since it's easy to get a lot of units pretty fast on my map. Tryna restrict this then! Thanks anyways :)!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,515
Alright, found the issue. That's part of the unit's AI, it's called their "Guard Position", units are told to return to it once there's nothing going on.

Luckily, you can turn it off with this Action:
  • AI - Ignore (Triggering unit)'s guard position
I edited the map and added this in. I also changed the Periodic Attack Interval to every 5.00 seconds instead of every 1.00 second, feel free to change it back if it's too long.
 

Attachments

  • Attack System 3.w3m
    26 KB · Views: 17
Level 7
Joined
May 30, 2018
Messages
290
Alright, found the issue. That's part of the unit's AI, it's called their "Guard Position", units are told to return to it once there's nothing going on.

Luckily, you can turn it off with this Action:
  • AI - Ignore (Triggering unit)'s guard position
I edited the map and added this in. I also changed the Periodic Attack Interval to every 5.00 seconds instead of every 1.00 second, feel free to change it back if it's too long.

Thanks :) Appreciated!
 
Status
Not open for further replies.
Top