What is the best (logic) way to order a unit to cast it'S ability? I mean the condition for it. For now I just have them cast it whenever they attack. But is there a better way? Can I put more logic into it?
It depends on the case and the type of ability, but my personal favorite method is with periodic timers that check for potential targets in a radius around the unit and make it cast the spell if there's a unit that meets the requirements. You can do a check every time it attacks as well, but if it's a unit targeting spell then the unit will lock up in most cases, since the attack event happens at the same time you order it to target a unit. Instant cast spells work fine if you overwrite the attack with a new order.
Below is a trigger I use to make priests cast Inner Fire on friendly units (I deleted a few things so it's easier to understand in this context). The trigger picks a random priest, filters units in an area around it, and orders the priest to cast it if there are any valid targets. It also checks for stronger units to target first.
Priest Inner Fire
Events
Time - Every 0.55 seconds of game time
Conditions
(Number of units in Priests) Greater than 0
Actions
Set VariableSet Unit = (Random unit from Priests)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Current order of Unit) Not equal to (Order(dispel))
Then - Actions
Set VariableSet Point = (Position of Unit)
Set VariableSet UnitGroup = (Units within 500.00 of Point matching ((((Matching unit) belongs to an enemy of (Owner of Unit).) Equal to False) and ((((Matching unit) has buff Inner Fire) Equal to False) and ((Level of (Matching unit)) Greater than 3))).)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in UnitGroup) Greater than 0
Then - Actions
Set VariableSet Unit2 = (Random unit from UnitGroup)
Unit - Order Unit to Human Priest - Inner Fire Unit2
Else - Actions
Set VariableSet UnitGroup2 = (Units within 500.00 of Point matching ((((Matching unit) belongs to an enemy of (Owner of Unit).) Equal to False) and (((Matching unit) has buff Inner Fire) Equal to False)).)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in UnitGroup2) Greater than 0
Then - Actions
Set VariableSet Unit2 = (Random unit from UnitGroup2)
Unit - Order Unit to Human Priest - Inner Fire Unit2
Base Abilities for Custom Spells used by AI Casters For getting the AI to cast custom spells, appropriate base spells must be used. Many users will argue that all custom spells should be based off of Channel-Special. While this is recommended for human users, the AI will never cast spells based...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.