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

AI targeting system

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
Hello, i have a question about the computer AI from spawned units. Is there a way in the editor (without triggers) to change their order of attacks?

I'm creating a TD with fighting units and i have tank, dps etc. characters and i want the enemies to target the first unit in sight instead of running straight towards the unit dealing the most damage.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,641
I believe different Armor Types can dictate AI, like Fortified units will be ignored, but I could be wrong. Some other possible solutions would be to give the Tanks a hidden Permanent Immolation ability that deals 0 damage with the hopes that it draws attention, although I haven't tested to see if this works. Another idea would be to detect when a computer unit acquires a non-Tank target and then make a quick search for nearby units around that target and manually order it to Attack any Tank-type units found.

Anyway, there's a lot of similar threads regarding this topic. Have you looked into those yet?
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
I could test that out.

Yes i have been looking around but cant seem to find any answers
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,641
I'm having trouble recreating the scenario where Computer units ignore those in front and instead aim for the highest DPS unit. From my tests it seems to be that the Computer will always attack the first thing it comes into contact with. Are you running an AI script or using some kind of unique unit? I'm testing with Footman and Level 10 heroes that deal FAR more damage than the Footman and the Footman always get targeted first by the Computers.

Edit: I got it working as you described after running melee AI:
  • Melee Game - Run melee AI scripts (for computer players)
The simplest solution is something like this:
  • Computer Ignore Heroes Simple
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
          • ((Attacked unit) is A Hero) Equal to True
        • Then - Actions
          • Set VariableSet IgnorePoint = (Position of (Attacked unit))
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 1000.00 of IgnorePoint.) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to False
                  • ((Picked unit) is alive) Equal to True
                  • ((Picked unit) belongs to an enemy of Player 2 (Blue).) Equal to True
                • Then - Actions
                  • Unit - Order (Attacking unit) to Attack (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_IgnorePoint)
        • Else - Actions
It'd be more efficient with variables for the (Attacked unit), (Attacking unit), and (Picked unit) but it gets the job done. Player 2 is the Computer in this case.

Alternatively, I created a system that gives GUI users access to a Generic version of the A unit Acquires a target Event. Here's an example:
  • Computer Ignore Heroes
    • Events
      • Game - GAT_Event becomes Equal to 2.00
    • Conditions
    • Actions
      • -------- Variables available to use here: --------
      • -------- GAT_Source = The unit that acquired a target. --------
      • -------- GAT_Target = The unit that was targeted. --------
      • -------- You may also use the Event Responses --> (Triggering unit) and (Targeted unit) --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of GAT_Source) Equal to Player 2 (Blue)
          • (GAT_Target is A Hero) Equal to True
        • Then - Actions
          • Set VariableSet IgnorePoint = (Position of GAT_Target)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 1000.00 of IgnorePoint.) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PickedUnit is A Hero) Equal to False
                  • (PickedUnit is alive) Equal to True
                  • (PickedUnit belongs to an enemy of Player 2 (Blue).) Equal to True
                • Then - Actions
                  • Unit - Order GAT_Source to Attack PickedUnit
                • Else - Actions
          • Custom script: call RemoveLocation(udg_IgnorePoint)
        • Else - Actions
I can't promise that the system is free of issues or as good as it could be, but it seems to work well.

This might be better than using the A unit Is attacked Event because it happens MUCH less often.
 

Attachments

  • Attack First Target.w3m
    23.6 KB · Views: 0
  • GUI Acquire Targets.w3m
    24.5 KB · Views: 1
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
I'm having trouble recreating the scenario where Computer units ignore those in front and instead aim for the highest DPS unit. From my tests it seems to be that the Computer will always attack the first thing it comes into contact with. Are you running an AI script or using some kind of unique unit? I'm testing with Footman and Level 10 heroes that deal FAR more damage than the Footman and the Footman always get targeted first by the Computers.

Edit: I got it working as you described after running melee AI:
  • Melee Game - Run melee AI scripts (for computer players)
The simplest solution is something like this:
  • Computer Ignore Heroes Simple
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
          • ((Attacked unit) is A Hero) Equal to True
        • Then - Actions
          • Set VariableSet IgnorePoint = (Position of (Attacked unit))
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 1000.00 of IgnorePoint.) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to False
                  • ((Picked unit) is alive) Equal to True
                  • ((Picked unit) belongs to an enemy of Player 2 (Blue).) Equal to True
                • Then - Actions
                  • Unit - Order (Attacking unit) to Attack (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_IgnorePoint)
        • Else - Actions
It'd be more efficient with variables for the (Attacked unit), (Attacking unit), and (Picked unit) but it gets the job done. Player 2 is the Computer in this case.

Alternatively, I created a system that gives GUI users access to a Generic version of the A unit Acquires a target Event. Here's an example:
  • Computer Ignore Heroes
    • Events
      • Game - GAT_Event becomes Equal to 2.00
    • Conditions
    • Actions
      • -------- Variables available to use here: --------
      • -------- GAT_Source = The unit that acquired a target. --------
      • -------- GAT_Target = The unit that was targeted. --------
      • -------- You may also use the Event Responses --> (Triggering unit) and (Targeted unit) --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of GAT_Source) Equal to Player 2 (Blue)
          • (GAT_Target is A Hero) Equal to True
        • Then - Actions
          • Set VariableSet IgnorePoint = (Position of GAT_Target)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 1000.00 of IgnorePoint.) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PickedUnit is A Hero) Equal to False
                  • (PickedUnit is alive) Equal to True
                  • (PickedUnit belongs to an enemy of Player 2 (Blue).) Equal to True
                • Then - Actions
                  • Unit - Order GAT_Source to Attack PickedUnit
                • Else - Actions
          • Custom script: call RemoveLocation(udg_IgnorePoint)
        • Else - Actions
I can't promise that the system is free of issues or as good as it could be, but it seems to work well.

This might be better than using the A unit Is attacked Event because it happens MUCH less often.
Thank you very much! I'll check that out.

Also, could the collision size have a big impact on how the units interract with each other?
 
Status
Not open for further replies.
Top