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

Cancelling Units

Status
Not open for further replies.
Level 6
Joined
May 15, 2009
Messages
191
Hello Fellow Hive Workshoppers

I'm having a few troubles with a small system that I'm making. What it is supposed to do it, limit a combination of two units to 6 in total.

In other Words, instead of "Limit training of 'Unit X' for Player 1 Red to 6" I wanted to make "Limit training of 'Unit X/Unit Y' for Player 1 Red to '|X|+|Y|=6'
Hope that was clear enough, I'm not good at explaining.

Anyway, I got to the point where I could make both unit types unavailable after a total of 6 had been produced (and they were made available Again, if one of the two unit types died). The problem is getting the contructing unit to cancel ALL production, once the limit is reached.

The problem lies in the ability to cheat the system, if you queue up enough units (say, 7 or more) before the first 6 units are trained, you can go past the limit easily.
Is there a way to stop all production of a (2) unit types?

Triggers are below, in two parts.
Setting availiability:
  • Check up Positive
    • Events
      • Game - EliteTotal_r becomes Less than 6.00
    • Conditions
    • Actions
      • Player - Make Footman Available for training/construction by Player 1 (Red)
      • Player - Make Rifleman Available for training/construction by Player 1 (Red)
  • Check up Negative
    • Events
      • Game - EliteTotal_r becomes Equal to 6.00
    • Conditions
    • Actions
      • Player - Make Footman Unavailable for training/construction by Player 1 (Red)
      • Player - Make Rifleman Unavailable for training/construction by Player 1 (Red)
And setting the proper integers
  • Elite Unit Dies
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Rifleman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • Set EliteDruid_r = (EliteDruid_r - 1.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Rifleman
        • Then - Actions
          • Set EliteSentinel_r = (EliteSentinel_r - 1.00)
        • Else - Actions
      • Set EliteTotal_r = (EliteDruid_r + EliteSentinel_r)
  • Elite Unit is Trained Trigger
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes training a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Trained unit)) Equal to Footman
          • (Unit-type of (Trained unit)) Equal to Rifleman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Footman
        • Then - Actions
          • Set EliteDruid_r = (EliteDruid_r + 1.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Rifleman
        • Then - Actions
          • Set EliteSentinel_r = (EliteSentinel_r + 1.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (EliteDruid_r + EliteSentinel_r) Equal to 6.00
        • Then - Actions
          • Game - Display to (All players) the text: debug - not avail
          • Custom script: call IssueImmediateOrderById( GetTriggerUnit(), 851976 )
          • Game - Display to (All players) the text: Halted Training
        • Else - Actions
          • Game - Display to (All players) the text: debug - is avail
          • Game - Display to (All players) the text: Trained
      • Set EliteTotal_r = (EliteDruid_r + EliteSentinel_r)

Thank you for your time.

-Battlehound/Woodenplank
 
Level 7
Joined
Mar 6, 2006
Messages
282
You need a line of JASS. This will order a building to press Cancel, which will remove a unit from the queue.

  • Custom script: call IssueImmediateOrderById( GetTriggerUnit(), 851976 )
I put GetTriggerUnit() because I'm not sure what you'd need there yet, post again if you have a question.

Edit:

Actually I don't think you can force something to cancel in succession, like if you wanted to cancel 3 queued units, I'm not sure that it would register 3 cancels at the same time. You'd need to check that the cancel order was successful, else wait and try again.

Nvm, it works perfectly when called in succession.
 
Last edited:
You can't stop the production only for a specific unit type... You would have to stop them all.
So what you're saying is, I just need to pop in a few more of those scripts? I already have 1 of them in the end

Yes try it with using a loop
  • For each (Integer A) from 1 to 7, do (Actions)
    • Loop - Actions
      • Custom script: call IssueImmediateOrderById( GetTriggerUnit(), 851976 )
Also in your trigger you already check
  • Conditions
    • Or - Any (Conditions) are true
      • (Unit-type of (Triggering unit)) Equal to Footman
      • (Unit-type of (Triggering unit)) Equal to Rifleman
So if it's no footman, no need to check anymore if it's a rifleman.

And with doing this earilier ...
  • Set EliteTotal_r = (EliteDruid_r + EliteSentinel_r)
no arithmetic would be need in real comparrison.
 
Level 6
Joined
May 15, 2009
Messages
191
The units simply don't get properly cancelled for some reason, even when I did the "loop".

Trigger has been updated to
  • Elite Unit is Trained Trigger
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes training a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Trained unit)) Equal to Footman
          • (Unit-type of (Trained unit)) Equal to Rifleman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Footman
        • Then - Actions
          • Set EliteDruid_r = (EliteDruid_r + 1.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Rifleman
        • Then - Actions
          • Set EliteSentinel_r = (EliteSentinel_r + 1.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (EliteDruid_r + EliteSentinel_r) Equal to 6.00
        • Then - Actions
          • Game - Display to (All players) the text: debug - not avail
          • For each (Integer A) from 1 to 8, do (Actions)
            • Loop - Actions
              • Custom script: call IssueImmediateOrderById( GetTriggerUnit(), 851976 )
          • Game - Display to (All players) the text: Halted Training
        • Else - Actions
          • Game - Display to (All players) the text: debug - is avail
          • Game - Display to (All players) the text: Trained
      • Set EliteTotal_r = (EliteDruid_r + EliteSentinel_r)
 
Level 6
Joined
May 15, 2009
Messages
191
Yes, it is owned by player 1 red, everything besides the cancelling Works fine.
Also, I don't see why the extra conditions would prevent the units from getting properly cancelled, and I'm honestly more concerned about making it Work, than optimizing the trigger right now.

Map attached, thank you Guys for your time btw.
 

Attachments

  • System Two Elites.w3x
    22.6 KB · Views: 44
Level 6
Joined
May 15, 2009
Messages
191
@IceManBo
Thx alot man, it Works perfectly now, cancelling everything and all. Help was much appreciated, and +rep


To OP:
You can do it with just 1 trigger line...

Basically in object editor you make a dummy unit(that you'll never use ingame).
To the dummy unit you add dependency equivalents that you want to add up(unit A and unit B)
Then limit training of that dummy.

Hadn't thought of that. I see your point, but what are dependency equivalents?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
@IceManBo
Thx alot man, it Works perfectly now, cancelling everything and all. Help was much appreciated, and +rep




Hadn't thought of that. I see your point, but what are dependency equivalents?

In object editor each unit can have a list of units that are considered the same type.
I believe the field is called "Techtree - Dependency Equivalents"
Basically whenever the unit type itself is counted, then so are dependency equivalents.
The result is that you can group units into type through this.

It's very easy and yet, powerful.

Related link
 
Status
Not open for further replies.
Top