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

Best way to order an ai unit to cast an ability

Status
Not open for further replies.
Level 9
Joined
Dec 31, 2016
Messages
315
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
                • Else - Actions
              • Custom script: DestroyGroup(udg_UnitGroup2)
          • Custom script: RemoveLocation(udg_Point)
          • Custom script: DestroyGroup(udg_UnitGroup)
        • Else - Actions
 
isn't there a way to tap into the built in AI that does this pretty well? I think I saw a tutorial on that somewhere...
 
Status
Not open for further replies.
Top