• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] How to limit training?

Status
Not open for further replies.
Level 28
Joined
Sep 26, 2009
Messages
2,520
This is relatively easy. Let's say you want to limit number of units to 6 for Footman and Rifleman. In this case, it doesn't matter how many Riflemen or Footmen there are, the important thing is that the sum of Footmen and Riflemen can not exceed 6.

Make two integer variables that represent amount of slots left for training each unit type. I'll call those variables FootmanAmount and RiflemanAmount.
Both variables start with value 6.
Limit the number of units available for training for those unit-types to 6.
The value changes amount when:
a) Unit begins training a unit and the Trained Unit-Type is Rifleman or Footman.
b) Unit cancels training a unit and the Trained Unit-Type is Rifleman or Footman.
c) Unit dies and the unit-type of Triggering Unit is Rifleman or Footman.

Case a)
When Trained Unit-Type == Footman, then decrease the value in RiflemanAmount by 1. Then update unit limitation to values in variables. When Trained Unit-Type == Rifleman, decrease value in FootmanAmount by 1 and update unit limitation.

Case b) and c)
Increase both values of FootmanAmount and RiflemanAmount to [max(6, value +1)] where value is the name of the variable you want to increase. Then update unit limitation.
 
Level 13
Joined
Mar 13, 2013
Messages
299
i tried something like that, but it didn't work.

more generally, this trigger:
  • begin
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Peasant
    • Actions
      • Game - Display to (All players) the text: you are here
does not display the text 'you are here' when you attempt to train a peasant..
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
Read the notes when choosing some stuff in triggers. For Trained Unit there is a note that it's an answer to "Unit finishes training a unit" event which you do not use.

There's different option instead of Unit-type of *something* choose "Event Response - Trained Unit Type".

  • (Trained unit-type) Equal to Footman
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
That won't help, as the amount (= value saved in variable) won't be updated.

This can be quite annoying and I have actually not good idea how to solve it apart from catching when unit begins training a unit and save the triggering unit into hashtable with how many units it trains (has in queue).
This also lead me to an ugly discovery that the begins training a unit event fires only when the building really starts training the unit, not when you queue it. This will lead to inconsistency unless limiting number of available unit-types removes units over the limit from training queue.
:/
 
Level 13
Joined
Mar 13, 2013
Messages
299
That won't help, as the amount (= value saved in variable) won't be updated.

This can be quite annoying and I have actually not good idea how to solve it apart from catching when unit begins training a unit and save the triggering unit into hashtable with how many units it trains (has in queue).
This also lead me to an ugly discovery that the begins training a unit event fires only when the building really starts training the unit, not when you queue it. This will lead to inconsistency unless limiting number of available unit-types removes units over the limit from training queue.
:/
awesome. someone who feels my pain :-D

However, the queue thing can me addressed by, instead of doing the 'begins training' trigger using the 'is issued an order with no target' trigger.
i.e.
  • deny
  • Events
    • Unit - A unit Is issued an order with no target
  • Conditions
    • (Issued order) Equal to (Order(yourunittype))
  • Actions
    • Wait 0.00 seconds
Adding to that, I should probably mention that I know nothing about hash tables..
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
hashtables are like variables with the difference that they use 2 indexes instead of one and that the index (key) can be string or integer number.
The other advantage is that the integer number is not limited to 8192 (or 8191) like variables are so you can use unit's handle id (a unique identification number for each unit currently in game) as one of the keys.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
yes I mean array. The number of slots really is 8192, but maximum index can be only 8191 since arrays start from index 0.
You can try saving anything into an array with index 8192 and it will return null or default value instead of the saved one. If you save it as 8191 or less, it returns saved value.
 
Level 2
Joined
Apr 7, 2008
Messages
19
Hello. I don't know if you're still looking for a solution, but I think I should link this here regardless as I think it pertains heavily to your situation.

http://www.wc3c.net/showthread.php?p=983871 <-- this thread details the usage of using Dependency Equivalents to achieve an effect similar (if not the same) as what you desire, if I understand correctly.
 
Status
Not open for further replies.
Top