| 11-20-2003, 09:54 PM | #1 |
I'm having trouble cancelling training with triggers. In my map, I want to have a unit requirement for training certain units. How I want it to work is that at building X you can train unit Y, but for each unit Y you require one unit Z. If there is no unit Z within range of the building, any attempts to train unit Y are immediately cancelled. If there is one or several units Z within range of building X, then one unit Z is removed from the game and training of unit Y commences. I intend to use this trigger for a bunch of things in my map, so i want to get it as close to perfect as possible. Right now, I have it set up very close to what I want with the following trigger: E:Unit - A unit Begins training a unit C:(Unit-type of (Triggering unit)) Equal to Building X ((Trained unit-type) is A ground unit) Equal to (Unit Y is A ground unit) A:Unit Group - Add all units of (Units within 500.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Unit Z)) to UnitGroupA If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (UnitGroupA is empty) Equal to False Then - Actions Unit - Remove (Random unit from UnitGroupA) from the game Else - Actions Custom script: call IssueImmediateOrderById(GetTriggerUnit(), 851976) I don't know any JASS, but I found that that command in another thread that didn't quite address my problem. The problem arises when I have one unit Z and queue up two units Y and something else, in this case upgrade Q. Production finishes on the first unit X, but then instead of cancelling the second unit X, it cancels the other item in the queue, upgrade Q, and allows production of another unit Y to commence. obviously this is a problem. I don't know JASS, but does that function 851976 cancel the LAST thing in the queue? In that case, is there a function to cancel the first item in the queue? That should work. As an entirely alternative method to this, I should be able to simply cancel the command as it's issued if the conditions aren't met. However, can I have an ordercode for training a specific unit? Then I can just do an order comparison of the issued order and that ordercode. The trigger would probably be a bit cleaner this way. Any help at all for this poor newbie is appreciated. thanks in advance. |
| 11-21-2003, 07:28 AM | #2 |
Detect when a unit is starting to be trained, then force the training player to "Force UI Key '512'". |
| 11-21-2003, 02:24 PM | #3 |
That number is an order id (since cancel does not have an order string). It does the same as when a player presses ESC, which means it cancels the unit added last. I checked, there is no order id connected with cancelling units at other places in the queue (at least they cannot be caught so if there is one I don't know). Cancelling units by clicking on them in the queue cannot even be caught by trigger. So the way you should go is catching the train order and do the stuff there. The easiest way to recognize train orders and the unit type to train is that their order id is the 4-letter-code of the unit. That means catch an order with no target and then compare the order id to the 4-letter-code of your specific unit. |
| 11-21-2003, 02:26 PM | #4 |
Always remember the "convert order to unit type" trigger call |
