• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[General] Limit of units trained per building

Status
Not open for further replies.
Level 2
Joined
Jul 20, 2013
Messages
9
What i want: I was trying to create an autotraining system for buildings, something simmilar to Castle Fight, but with one important condition: Every building can have only limited ammount of alive units at a time. I.e. Barracks#1 trains units until the established limit of units (let's say it is 3) is reached, than it stops; meanwhile Barracks#2 and Forge#1 do the same thing. But when one of the trained units dies, a building that trained dying unit automatically trains a replacement until the limit is reached again. Hope it makes sense :grin:

What is done: I setted up autotraining with 3 simple triggers:
  • Barracks Initialization
    • Events
      • Time - Elapsed game time is 0.20 seconds
    • Conditions
    • Actions
      • Set NumberOfBuilding = (NumberOfBuilding + 1)
      • Set BarrackType[NumberOfBuilding] = |cFF8A4500Basic Barracks|r Lvl 1
      • Set UnitType[NumberOfBuilding] = Militia Lvl 1
      • -------- - --------
      • Set NumberOfBuilding = (NumberOfBuilding + 1)
      • Set BarrackType[NumberOfBuilding] = |cFF8A4500Basic Barracks|r Lvl 2
      • Set UnitType[NumberOfBuilding] = Militia Lvl 2
      • -------- - --------
      • Set NumberOfBuilding = (NumberOfBuilding + 1)
      • Set BarrackType[NumberOfBuilding] = |cFF8A4500Basic Barracks|r Lvl 3
      • Set UnitType[NumberOfBuilding] = Militia Lvl 3
      • -------- - --------
  • Train First
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit group - Add (Triggering unit) to Barracks
      • For each (Integer loop) from 1 to NumberOfBuilding, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Condition
              • (Unit-type of (Constructed structure)) Equal to BarrackType[loop]
            • Then - Actions
              • Unit - Order (Constructed structure) to train/upgrade to a UnitType[loop]
            • Else - Actions
  • Train Loop
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Triggering unit)) less than 3
        • Then - Actions
          • Unit - Order (Triggering unit) to train/upgrade to a (Unit-type of (Trained unit))
        • Else - Actions
          • Custom script: call IssueImmediateOrderById( GetTriggerUnit(), 851976 )
Probably could be done even easier but at least it works as planned. As you can see, in the last trigger i tried to stop training when the limit of 3 units is reached. Now im only left with the last part, and that's where i hit a wall.

The problem: my continuous attempts to make it work failed. I would imagine hashtables are the way to go but since my trigger skills are mediocre and my hashtable/game cache knowledge is close to non-existent, I gave up after several hours of trial and error. I was trying to save training unit (building) and trained unit to hashtable and then load them whenever i need but it seems like i don't know know how to save/load units properly. My abomination of a trigger with a hashtable forced my buildings to train units in weird and unpredictable patterns, it was even funny. Unfortunately I deleted all my non-working triggers in a moment of despair so i don't have them to show you and make you laugh :grin:

One more thing: I'm planning to use the same unit limit for all of my buildings, but if it is possible to set different cap for each building type without major changes to trigger structure - let me know how.
Anyway, I hope someone will bother to reply :)
P.S. Sorry for occasional misspells, typos and grammar errors, my English is work in progress ;)
 
Level 2
Joined
Jul 20, 2013
Messages
9
This is going to blow your mind.
  • Player - Limit training of Footman to 3 for (Owner of (Triggering unit))
Basically this would save a lot of your effort unless I'm missing something.
Uh... Well, maybe I've explained it poorly. This would just limit the ammount of footman you can own as a player. What i actually want is to have as many footmans as you can afford, but each barrack can "maintain" only 3 footmans at a time, AND whenewer one of those footmans "owned" by the barrack dies, it automatically trains a new one. I hope it is clear now :con:
 
Level 11
Joined
Jul 4, 2016
Messages
627
You can probably do this rather nice and easily using a integer array variable, and unit reference variables and unit indexer.
 
Level 2
Joined
Jul 20, 2013
Messages
9
You can probably do this rather nice and easily using a integer array variable, and unit reference variables and unit indexer.
Well, im gonna admit that I dont know much about this, but are you sure it is possible with variables only? Basically i want each unit to "remember" the building he was trained in. How do I do this, implying that i want to have more than one building of the same type working that way?
 
Level 2
Joined
Jul 20, 2013
Messages
9
You can try this out. The Unit Indexer is there to reference the building it came out of.
Works as intended! I was actually going in a similar direction with it but now I realize that I didn't set the indexing on initialization properly. Thank you for your time and effort, +rep and inmap credit well earned!
 
Last edited:
Status
Not open for further replies.
Top