• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Detect specific unit-type training

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
104
Hi! Is there any method to detect what exactly unit-type of the unit was just added (or canceled) in the training queue? I want to do something like this:

  • Unit Starts Training
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Player number of (Owner of (Triggering unit))) Less than 9
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Upgrade |cff00ffffLightning towers|r
        • Then - Actions
          • -------- Do some stuff --------
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Upgrade |cffff0000Cannon towers|r
        • Then - Actions
          • -------- Do some stuff --------
        • Else - Actions
But it seems that
  • (Unit-type of (Trained unit)) Equal to
function doesn't fit my goal. Is there any tricky way to get around this obstacle, for example, using a custom script or something?
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
hmmm... as you have seen the event "A unit Begins training a unit" applies to when that unit becomes first in the queue and actively starts it's training (with the loading bar etc). I don't know of any simple way to access the queue itself, but to find out when a unit is added to the queue you just need to detect the order given to the building.

you can use this to find out what the specific training order string is:
  • order detector
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (String((Issued order)))
so in your trigger you would use this event (A unit Is issued an order with no target), and filter for specific order strings.

for a deeper dive into hacking the queue: Unit-type Queue detection
 
1644266681274.png
 
he is looking for a way to access the queued units, not just the one being actively trained.
yes you right, actually more of addition to what you already said it can be used for detecting at least newly added units instead

1644273407824.png


because in first post wrong check was used, but @Helheim seems got it fixed.

I also think cancel can't be properly detected. Cancel by button works to fetch cancel order id, but cancel by clicking on icon doesnt run events imo.
 
Level 25
Joined
Sep 26, 2009
Messages
2,387
The event
  • Unit - A unit Cancels training a unit
is fired when you click the 'Cancel' button and also when you click on unit directly in the queue. In both cases it reports which unit-type has been cancelled, but you don't get position in the queue.

So if you just need to know which unit-types are in the queue, then the solution from posts above should be enough to make it work. But if you need to know the order of unit-types in the queue, then I don't think there is any way to know it.
As an example, you can see in game that the queue in Barracks consists of 3 footmen in the first three positions, then 2 riflemen and last two positions are taken by footmen as well. You can detect that training of a 'footman' unit-type has been cancelled, but you don't know which of the 5 footmen in the queue it was.
 
Level 7
Joined
Jun 1, 2009
Messages
104
So if you just need to know which unit-types are in the queue
Yup, and I don't even need to check the whole queue, just a unit-type that is currently trained is fine. The problem was I had no idea that
  • (Trained unit-type) Equal to
and
  • (Unit-type of (Trained unit)) Equal to
were quite different functions, even if it not so obvious.
 
Status
Not open for further replies.
Top