# How to make AI prioritize?

#### Karzama

Level 13
Hi

I'm making an AI system which is rather basic but I am trying to make them prioritize weak units, buildings and heroes. Here is my attempt:

• AI Threat Detection
• Events
• Conditions
• Actions
• Set AIMoveAllyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an ally of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
• Unit Group - Pick every unit in AIMoveAllyGroup and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Owner of TempUnit) Not equal to Neutral Passive
• Then - Actions
• Set TempUnit = (Picked unit)
• Set AIMoveAllyHP = (AIMoveAllyHP + (Life of TempUnit))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A Hero) Equal to True
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + (4 + (Hero level of TempUnit)))
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 12)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 20)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 30)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to False
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + (Level of TempUnit))
• Else - Actions
• Else - Actions
• Set AIMoveAllyAverage = (AIMoveAllyHP x (Real(AIMoveAllyLevel)))
• Set AIMoveEnemyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an enemy of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
• Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• Set AIMoveEnemyHP = (AIMoveEnemyHP + (Life of TempUnit))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Owner of TempUnit) Not equal to Neutral Passive
• Then - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A Hero) Equal to True
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (4 + (Hero level of TempUnit)))
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 12)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 20)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 30)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to False
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (Level of TempUnit))
• Else - Actions
• Else - Actions
• Set AIMoveEnemyAverage = (AIMoveEnemyHP x (Real(AIMoveEnemyLevel)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• AIMoveAllyAverage Less than (AIMoveEnemyAverage x 0.65)
• Then - Actions
• Unit - Order AIHeroUnit to Move To AIMovePoint
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to False
• (TempUnit is A Hero) Equal to False
• (Percentage life of TempUnit) Less than 15.00
• Then - Actions
• Unit - Order AIHeroUnit to Move To AIMovePoint
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A Hero) Equal to True
• (Percentage life of TempUnit) Less than 40.00
• Then - Actions
• Unit - Order AIHeroUnit to Move To AIMovePoint
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to True
• (Percentage life of TempUnit) Less than 20.00
• Then - Actions
• Unit - Order AIHeroUnit to Move To AIMovePoint
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• Unit Group - Remove AIHeroUnit from AIMoveGroup
• Unit Group - Remove AIHeroUnit from AIMoveGroup
• Set AIMoveAllyHP = 0.00
• Set AIMoveAllyLevel = 0
• Set AIMoveEnemyHP = 0.00
• Set AIMoveEnemyLevel = 0
However this doesn't seem to work so I was wondering if anyone knew how to make them prioritize attacking heroes first, then weak buildings and finally weak units?

#### Nichilus

Level 21
I'm not really sure what you are trying to do with that trigger (dunno what Tidal Guardian is - if it's a building, hero or normal unit, etc.)

What I do see is that "Pick every unit within X of TempPoint" action, however I do not see you setting TempPoint anywhere, nor do I see you setting up AITempPlayer, AIMoveAllyHp, etc.
In the first "Pick every unit in group", you have an If/Then/Else there, which checks if "owner of TempUnit =/= Neutral Passive" and if that is correct, you set TempUnit = picked unit. That will obviously be always true if the TempUnit variable is nulled, as "Owner of NoUnit =/= Neutral Passive" will most likely return true.

Also, at the end you set value of AI..Hp to 0; if you do not change that value anywhere else, then it will always move to the "Else" block, because the calculation will always be
AIMoveEnemyAverage = (AIMoveEnemyHP x (Real(AIMoveEnemyLevel))) => Average = 0 x "some number", which will return 0... same for the AllyAverage.

You could use debug messages, to see where your trigger stops, what values it gets, etc.

#### Karzama

Level 13
Oh yer my bad. TempPoint, AITempPlayer and AIHeroUnit are all set in a previous trigger which then runs this trigger. Within this trigger AIHeroUnit (their hero) will be added (or not added/removed) from AIMoveGroup then the other trigger will check if they are in the group or not. If they are not then the other one continues and it goes to items and things like that. Setting the AI-HP and to 0 at the end of the trigger was put there so that it was reset for the other computer players.

Anyway I have changed it quite a bit now just working on the prioritization of it.

• AI Threat Detection
• Events
• Conditions
• Actions
• Set AIMoveAllyHP = 0.00
• Set AIMoveAllyLevel = 0
• Set AIMoveEnemyHP = 0.00
• Set AIMoveEnemyLevel = 0
• Set AIMoveAllyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an ally of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
• Unit Group - Pick every unit in AIMoveAllyGroup and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Owner of TempUnit) Not equal to Neutral Passive
• Then - Actions
• Set TempUnit = (Picked unit)
• Set AIMoveAllyHP = (AIMoveAllyHP + (Life of TempUnit))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A Hero) Equal to True
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + (4 + (Hero level of TempUnit)))
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 12)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 20)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + 30)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to False
• Then - Actions
• Set AIMoveAllyLevel = (AIMoveAllyLevel + (Level of TempUnit))
• Else - Actions
• Else - Actions
• Set AIMoveAllyAverage = (AIMoveAllyHP x (Real(AIMoveAllyLevel)))
• Set AIMoveEnemyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an enemy of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
• Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• Set AIMoveEnemyHP = (AIMoveEnemyHP + (Life of TempUnit))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Owner of TempUnit) Not equal to Neutral Passive
• Then - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A Hero) Equal to True
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (4 + (Hero level of TempUnit)))
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 12)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 20)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 30)
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (TempUnit is A structure) Equal to False
• Then - Actions
• Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (Level of TempUnit))
• Else - Actions
• Else - Actions
• Set AIMoveEnemyAverage = (AIMoveEnemyHP x (Real(AIMoveEnemyLevel)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• AIMoveAllyAverage Less than (AIMoveEnemyAverage x 0.65)
• Then - Actions
• Unit - Order AIHeroUnit to Move To AIMovePoint
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• Unit Group - Remove AIHeroUnit from AIMoveGroup
• Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is in AIMoveEnemyGroup) Equal to True) and (((Matching unit) is A structure) Equal to True))) and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Percentage life of TempUnit) Less than 20.00
• (AIHeroUnit is in AIMoveGroup) Equal to False
• Then - Actions
• Unit - Order AIHeroUnit to Attack TempUnit
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is in AIMoveEnemyGroup) Equal to True) and ((((Matching unit) is A structure) Equal to False) and (((Matching unit) is A Hero) Equal to False)))) and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Percentage life of TempUnit) Less than 10.00
• (AIHeroUnit is in AIMoveGroup) Equal to False
• Then - Actions
• Unit - Order AIHeroUnit to Attack TempUnit
• Unit Group - Add AIHeroUnit to AIMoveGroup
• Else - Actions
• Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is in AIMoveEnemyGroup) Equal to True) and (((Matching unit) is A Hero) Equal to True))) and do (Actions)
• Loop - Actions
• Set TempUnit = (Picked unit)
• Unit - Order AIHeroUnit to Attack TempUnit
• Unit Group - Add AIHeroUnit to AIMoveGroup
This works so far but I can't seem to work out a way that I can make them attack weaker/closer targets. (By this I mean if there are heroes around then they will target the weakest one and if there are weak units they will target the closest one, which would be very useful for melee heroes.)

P.S. Tidal Guardians are towers (3 different levels for different areas in base.)

Replies
5
Views
825
Replies
11
Views
708
Replies
7
Views
450
Replies
8
Views
538
Replies
4
Views
116