• 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.

Limited Unit Supply (Local)

Status
Not open for further replies.
Level 24
Joined
Oct 12, 2008
Messages
1,783
Im trying to make a mechanic where a production building has a limited supply of units it can train.
(eg. A population 5 Barracks can train 5 units and then no more)

  • This is local to each building, so the usual 'limit training of unit X for player Y' doesnt work
  • Training mechanic is used, as I want units to have a construction time. A solution is to use mercenary mechanic, but I'd like to avoid that if possible.
 
Level 30
Joined
Aug 29, 2012
Messages
1,386
You could make it like buildings have a maximum mana of 5 and every time they train an unit, substract 1, and if it reaches 0, making them unable to do anything (maybe with a Pause unit or something)
The benefit would be that players can see easily how many units they are still allowed in each building
 
Level 30
Joined
Feb 18, 2014
Messages
3,623
You could also try this:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A structure) Equal to True)) and do (Actions)
        • Loop - Actions
          • Set BuildingIndex = (BuildingIndex + 1)
          • Unit - Set the custom value of (Picked unit) to BuildingIndex
          • Set MaxTrain[BuildingIndex] = 5
  • Untitled Trigger 002
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Unit - Set the custom value of (Trained unit) to (Custom value of (Triggering unit))
      • -------- --------
      • Set MaxTrain[(Custom value of (Triggering unit))] = (MaxTrain[(Custom value of (Triggering unit))] - 1)
      • -------- --------
      • Game - Display to (All players) the text: (String(MaxTrain[(Custom value of (Triggering unit))]))
  • Untitled Trigger 003
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • MaxTrain[(Custom value of (Triggering unit))] Equal to 0
    • Actions
      • Custom script: call IssueImmediateOrderById(GetTriggerUnit(),851976)
      • Game - Display to (All players) the text: Max Supply !
  • Untitled Trigger 004
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Custom value of (Triggering unit)) Greater than 0
    • Actions
      • Set MaxTrain[(Custom value of (Triggering unit))] = (MaxTrain[(Custom value of (Triggering unit))] + 1)
      • Game - Display to (All players) the text: (String(MaxTrain[(Custom value of (Triggering unit))]))
I found out that removing a unit from a marketplace only works on Sold units and not Trained unit so you can only display a message when the limit is reached.
 

Attachments

  • Training Limit.w3x
    18.9 KB · Views: 11

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
I would do what Warseeker suggested but with a Unit Indexer so that you aren't limiting yourself to using a single Custom Value per unit.

It would be mostly the same except that you store the Building to your Trained units so that they'll have a reference to it later on:
  • Set BuildingLink[Custom value of (Trained unit)] = (Triggering unit)
Then you increase MaxTrain[Custom value of BuildingLink] in response to the trained units dying:
  • Set CV = Custom value of BuildingLink[Custom value of (Dying unit)]
  • Set MaxTrain[CV] = (MaxTrain[CV] + 1)
 
Last edited:
Level 24
Joined
Oct 12, 2008
Messages
1,783
Sorry for the slow reply.
Firstly, thnks everyone for the suggestions.

However, I need to be more clear in that the problem isn't about counting down everytime a unit is trained. Im trying to find a way to locally disable the training UI for a production building (if it is possible).

~Apology if it wasnt clear.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
Sorry for the slow reply.
Firstly, thnks everyone for the suggestions.

However, I need to be more clear in that the problem isn't about counting down everytime a unit is trained. Im trying to find a way to locally disable the training UI for a production building (if it is possible).

~Apology if it wasnt clear.
You can hide UI elements on more recent versions but that'll probably be purely visual and making it local to individual units will probably be difficult if not impossible. What exactly is Training UI though, do you mean the 1 to 7 training icons that represent queued up units being trained? Or do you mean the Unit icons on the command card? I assume you mean the command card since that would actually prevent the units from being trained.

There is no Action to limit training for a specific building. Unfortunately we can only do it per player:
  • Actions
    • Player - Limit training of Footman to 0 for Player 1 (Red)
    • Player - Limit training of Knight to 0 for Player 1 (Red)
    • Player - Limit training of Rifleman to 0 for Player 1 (Red)
So I think you'll have to do what Chaosium said.
 
Last edited:
Status
Not open for further replies.
Top