• 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.

[Solved] How to check if unit is not attacking and casting/channeling a spell?

Status
Not open for further replies.
Level 26
Joined
Dec 3, 2020
Messages
815
So exactly as the thread title says...
How can I check in a condition if a unit is either not attacking enemies and if he's not casting/channeling a spell (need to check both but specifically for the channel)?

Or the opposite, how can I check if the unit is attacking enemies and channeling a spell?

I basically want to order the unit to attack move to the position of a building if it is idle (not moving, not attacking, not casting or channeling any spells).
 
Last edited:

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,377
You can try something like this, I believe "stand down" should work in most cases to detect an "idle" unit:
  • Auto Hold
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set TempUnitG = (Units in (Playable map area) matching ...
      • Unit Group - Pick every unit in TempUnitG and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
            • Then - Actions
              • Unit - Order (Picked unit) to ...
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempUnitG)
Otherwise, you can use a Hashtable or Unit Indexer to track the state of your units. Here's a basic Unit Indexer implementation:
  • Events
    • Unit - A unit is attacked
  • Conditions
  • Actions
    • Set Variable Unit_Is_Attacking[(Custom value of (Attacking unit))] = True
  • Events
    • Unit - A unit is issued an order...
  • Conditions
  • Actions
    • Set Variable Unit_Is_Attacking[(Custom value of (Ordered unit))] = False
  • Events
    • Unit - A unit Begins channeling an ability
  • Conditions
  • Actions
    • Set Variable Unit_Is_Casting[(Custom value of (Casting unit))] = True
  • Events
    • Unit - A unit Stops casting an ability
  • Conditions
  • Actions
    • Set Variable Unit_Is_Casting[(Custom value of (Casting unit))] = False
Then reference these booleans when issuing your order:
  • Set Variable Unit = (some unit)
  • Set Variable CV = (Custom value of Unit)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Unit_Is_Attacking[CV] = False
      • Unit_Is_Casting[CV] = False
    • Then - Actions
      • Unit - Order Unit to ...
    • Else - Actions
 
Level 26
Joined
Dec 3, 2020
Messages
815
Thank you so much Uncle! It worked!!! And it works the way I wanted it to work...
So I had already made a JASS script for this purpose so I wouldn't have to use triggers and it was working... just not as intended.
When there were like more than 300 units (total) the AI would act weird, plus when heroes got attacked the AI would react weird too, trying to defend the hero as usual but only move the units a little bit towards the enemy and then just basically "Hold Position" them (idk why).

My script was a simple loop that suicided units into the enemy player every 0.1 seconds.

But enough about this! Again, thank you so much Uncle, a life saver! Now the AI behaves the way I want it to behave!!!

Now I wouldn't mind if you could check out my other thread :D
(About AI not constructing units; it's "JASS" related but if it can be done with triggers then I'd appreciate it).

PS: would this attack move trigger work for units without any attacks???
 
Last edited:
Status
Not open for further replies.
Top