[Solved] How to check if building is training a specific unit?

Level 30
Joined
Aug 29, 2012
Messages
1,382
You could have two triggers like this

  • Training Start
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Trained unit-type) Equal to Sorceress
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 1

  • Training End
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Trained unit-type) Equal to Sorceress
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 0
Then you can easily check for X building's custom value to see what they're doing. If you're using CV for something else, I'd use a dummy ability like claws of attack and check whether they have this ability or not
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You could have two triggers like this

  • Training Start
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Trained unit-type) Equal to Sorceress
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 1

  • Training End
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Trained unit-type) Equal to Sorceress
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 0
Then you can easily check for X building's custom value to see what they're doing. If you're using CV for something else, I'd use a dummy ability like claws of attack and check whether they have this ability or not
I would use a Unit Indexer, it's this but objectively better. Infinite custom values as opposed to one at a time per unit.
 
Level 28
Joined
Dec 3, 2020
Messages
969
Thanks guys!
I honestly only need this for the AI, and the AI only has 1 unit in the queue from my observations.
I want to make some experimentations with the AI using a plethora of different methods to improve the gameplay experience of the player.

It is incredible how many options and alternatives exist to do one specific task.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
It will not fail. The 'Unit - A unit Begins training a unit' fires when building starts training a unit, not when unit has been added to train queue
My mistake, then, but it will still fail upon cancelling the unit mid-training because the cancel event is not used. Generally, “is a sorceress in the queue” is a different question than “is a sorceress being trained right specifically now,” and I assumed the first was desired. What do you actually want to check, raypack?

Yes, I am aware a CPU is never going to cancel their training queue so that wont matter.
 
Level 28
Joined
Dec 3, 2020
Messages
969
My mistake, then, but it will still fail upon cancelling the unit mid-training because the cancel event is not used. Generally, “is a sorceress in the queue” is a different question than “is a sorceress being trained right specifically now,” and I assumed the first was desired. What do you actually want to check, raypack?

Yes, I am aware a CPU is never going to cancel their training queue so that wont matter.
Well, I need the "is a sorceress being trained right specifically now" since it is for the AI.
But if it's a solution that answers both questions, then even better.
 
Top