• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Vote for the theme of Hive's HD Modeling Contest #7! Click here to vote! - Please only vote if you plan on participating❗️

[General] Is there a way to crate a working attack priority?

Status
Not open for further replies.
Level 1
Joined
Jan 21, 2022
Messages
2
The Stats - Priority does nothing for attack. I've tried all sorts of attack and defend combinations. Siege does not attack fortified first. I've tried heroes and that doesn't work either. Then I spent about 4 hours messing with triggers and made some progress.

The goal is to have my Sniper towers prioritize attacking Sniper units. but no matter what I do the sniper units are attacked last after all other units are dead. (which doesn't even make sense, they should be attacked in order or at least by whos closest. This is just because the game hates me, I'm sure of it)

The trigger I created puts a created sniper tower into a variable and a created sniper into a variable. It then has one variable attack the other variable. This would work if there wasn't multiple towers and snipers
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,590
Sounds like you made a really simple trigger when it's a bit more complicated than that.

Here's an idea that could work:
Step 1) When a Sniper Tower attacks a unit, check to see if the attacked unit is a Sniper-type. This could be done in many different ways. You can give the Sniper-units a classification (limited), or you can give them a unique hidden ability which you can then check, or you can use Hashtables/Indexing. I prefer the Ability method since it has no limitations and is easy and effective.

Step 2) If the attacked unit isn't a Sniper-type, create a new temporary Unit Group that contains all of the units within Attack Range of the attacking Sniper Tower. Then filter through this Unit Group, removing unwanted units. Now you're left with a Unit Group that contains only living enemy Sniper-types within Attack Range of the Tower.

Step 3) Lastly, Order your Sniper Tower to attack a Random unit from the Unit Group and Destroy the temporary Unit Group since we're done using it. Now your Sniper Tower should be attacking a Sniper-type unit (if one was found). Optionally, you can add in a GetClosestUnit function to find the closest of the Sniper-type units and attack them instead of one at random. Another option would be to make the Sniper Tower target the lowest life enemy. These optional functions would add some more complexity to the trigger and make it less efficient but would also be closer to real AI.

A trigger example written from memory (no editor atm):
  • Events
  • Unit - A unit is attacked
  • Conditions
  • Level of Sniper Classification for (Attacked unit) Equal to 0
  • Actions
  • // Look for nearby living enemy units with the Sniper Classification ability and attack one!
If a unit doesn't have an Ability then the Ability Level will be considered 0.

Don't forget to clean up the Point/Unit Group memory leaks! Memory Leaks
This isn't NECESSARY as the trigger will still function if you don't, but it's good practice.
 
Last edited:
Status
Not open for further replies.
Top