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

Limit Unit Training

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
If the limit would always be 1 then you can do this:
A unit starts training a unit.
Disable training of (trained unit type)

A unit finishes / cancels training a unit.
Enable training of (trained unit type)

If the limit is more then you have to save the value for each player for each unit-type.

I assume that you want to have 2 barrackses and when barracks 1 starts training, the other one cannot train the same unit (if the limit is 1)
 
If the limit would always be 1 then you can do this:
A unit starts training a unit.
Disable training of (trained unit type)

A unit finishes / cancels training a unit.
Enable training of (trained unit type)

If the limit is more then you have to save the value for each player for each unit-type.

I assume that you want to have 2 barrackses and when barracks 1 starts training, the other one cannot train the same unit (if the limit is 1)

No I want it to be per structure, not an overall tech limitation.
 
Level 25
Joined
May 11, 2007
Messages
4,651
Use the ability "Charge Gold and Lumber", change it into so it looks like an unit.
When casted, add a cancel ability, remove the "charge gold and lumber" ability from the barrack, create a custom training system with floating text and timers.

When the trained unit finishes, remove the cancel ability and add the charge gold and lumber ability again.
 
Use the ability "Charge Gold and Lumber", change it into so it looks like an unit.
When casted, add a cancel ability, remove the "charge gold and lumber" ability from the barrack, create a custom training system with floating text and timers.

When the trained unit finishes, remove the cancel ability and add the charge gold and lumber ability again.

I'd like to find a way to do it without relying on an external timer system. Is there no way to remove a unit from a particular buildings training list?
 
Level 25
Joined
May 11, 2007
Messages
4,651
Try using this?
  • Set MyUnit = (Picked unit)
  • Custom script: call IssueImmediateOrderById(udg_MyUnit, 851976)
(Replace the orderID with perhaps cancel or such if needed).

Or force the player to press escape if training more than one unit.
 
Level 3
Joined
Sep 9, 2009
Messages
658
If no Barracks are preplaced then you could have an integer variable start counting them when they enter the map. Then another counting the footmen entering the map.

Then with this
  • Unit - A unit Begins training a unit
check if FootmenCount = BarracksCount

If they're equal then order the building to cancel training.

If barracks are preplaced then at map initialization, count them using a unit group. Then destroy the group.

EDIT: Here's a test map.

EDIT: I misunderstood what you meant. You want one footman PER barracks right? As in once a specific barracks trains a footman, footman becomes unavailable?

If that's what you want then look at the second test map.
 

Attachments

  • TestMap.w3x
    17.2 KB · Views: 66
  • TestMap2.w3x
    17.1 KB · Views: 63
Last edited:
Level 3
Joined
Sep 9, 2009
Messages
658
The best way is to just make a copy of the barracks that can't train a footman.

Next make a copy of the Chaos ability and set the new type of transformed unit to the Footman-less barrack.

Then...

  • Barrack
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barracks
      • (Unit-type of (Trained unit)) Equal to Footman
    • Actions
      • Unit - Add Chaos to (Triggering unit)
And then that specific Bararck won't be able to train Footmen anymore.
 
The best way is to just make a copy of the barracks that can't train a footman.

Next make a copy of the Chaos ability and set the new type of transformed unit to the Footman-less barrack.

Then...

  • Barrack
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barracks
      • (Unit-type of (Trained unit)) Equal to Footman
    • Actions
      • Unit - Add Chaos to (Triggering unit)
And then that specific Bararck won't be able to train Footmen anymore.

It's not when the unit is complete it's as soon as it starts training that I need it removed from that single barracks.
 
Level 12
Joined
May 9, 2009
Messages
735
It's not when the unit is complete it's as soon as it starts training that I need it removed from that single barracks.

In that case I think it should look like this:
  • Trigger
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barracks
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(Footman))
        • Then - Actions
          • Unit - Add Chaos to (Triggering unit)
        • Else - Actions
          • Do nothing
 
Level 3
Joined
Sep 9, 2009
Messages
658
Unfortunately, that method doesn't work. It's possible it's because a unit can't transform in the middle of training a unit.

Here's the next best thing.

  • Barrack Order
    • Events
      • Unit - A unit Begins training a unit
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(footman))
    • Actions
      • Set FootmanCount = (FootmanCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • FootmanCount Greater than or equal to 1
        • Then - Actions
          • Custom script: call IssueImmediateOrderById(GetTriggerUnit(), 851976)
        • Else - Actions
and

  • Barrack
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barracks
      • (Unit-type of (Trained unit)) Equal to Footman
    • Actions
      • Unit - Add Chaos to (Triggering unit)
With this, it will increase an integer every time you train a unit. And increases it again every time you add to the training queue.

Then it checks if the integer is greater than one. If it is, it cancels the other queues. Such that only one Footman gets trained. After that the barracks is given the Chaos upgrade and the Footman is completely removed. You still need to set the integer to zero again so it can be recycled though.
 

Attachments

  • TestMap2.w3x
    17.5 KB · Views: 70
  • Like
Reactions: Kam
I did in the post above yours XD

Your test map seems to work perfectly. I'm not sure it was intended that each time you train a footman it resets the existing training but that is highly desirable for what I am using this for. It is also nice that it interrupts researches as well.

The idea is that when the unit, in this case a Footman, is done training the building is destroyed and some of the cost is refunded. I needed a way to have it use a timer that forced the player to really think about sacrificing the building and prevent denying an enemy player their kill.

I just could not figure out how to prevent multiple training.
 
Status
Not open for further replies.
Top