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

Unit limit per structure... how???

Status
Not open for further replies.
Level 7
Joined
Feb 14, 2008
Messages
289
I am making a map that revolves around making a barracks, then developing it down its techtree. choosing magic barrracks, ranged, melee.

for the sake of example lets say i make a basic barracks, evolve to "melee barracks" (footmen). and then evolve against to "mass melee". which would allow 6 footmen to be made TOTAL for that one barracks.

then i make another one and make it melee barracks so it supports 4 footmen. i know how to limit units, but i dont know how to limit depending on the structures u build. the barracks make units automatically (build type, not spawn). but how do i allow only 10 footmen for these two different kinds of barracks? and what if i get 2 "mass melee barracks" to support 16?

plz explain with triggers. if possible. if you need to go ahead and explain with script.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
Well firstly you need to build the system so that is can handle getting the maximum for each type.

To do this simply count how many of each baracks there are, multiply them by the number of units for each baracks and finnaly add where need be.

Finally you then update the maximum number trainable (the player action / native that limates building of a unit).

This method will let you build the correct number of units however 1 baracks may build as many as the limate lets you or none at all but that I think is hardly a problem.
 
Level 12
Joined
Mar 16, 2006
Messages
992
A unit is trained, specific_unit_count++. A unit dies and is unit, specific_unit_count--. If ,

Then have a governing script where, after you specific_unit_count is >= max_trainable*buildings_built, it disabled the ability to build that specific unit. Then have a ceiling script where if any of those units died when you had max specific_unit_count, it would enable the skill and disable the govern.

Hope you understood this. It gave me an idea.
 
Level 13
Joined
Nov 4, 2006
Messages
1,239
couldn't you just make a variable unitgroup for each barrack?
like when barrack completes construction of unit, add unit to unitgroup1,
if number of units in unitproup1 becomes greater then 10(or whatever) remove last added unit from the game, you might need another trigger to count the units in the groups, but it should work like this
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
How many times must I say it. . .

There is already a native / trigger action that limates the training of a unit to a certain number. It is by far the best and least buggy way (as well as least demanding way) to do this.

Simply update the maximum number trainable with one call of that native / running of that action with the maximum number that can easilly be calculated. All counting of the units and disabling building them when the limate is reached is done for you automatically.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
I dont think you need variables

Unit Starts training

If count units structures in map x A lesser than or equal to Unit Type of training(I mean currently trained) units in map

Cancel training
Send a message to that player


Edit: Or make Dummy Requirement Unit named "Limit reached for this unit"
add-remove it with triggers
 
Last edited:
Level 13
Joined
Nov 4, 2006
Messages
1,239
ahhh, now i got what you meant Dr Super Good,
you dont need any variables then, just make different units for every barrack (same name, damadge, etc, just another editorsuffix so you can differ them)
then go to triggers:
event: choose any(eg map initalization, or time elapsed is 1 sec)
condition: not needed but maybe you got some?
action: --> player --> limit training of unit-type to 6(or whatever) for player1(you can ofc also chose other players, or do more actions for more players)
 
Status
Not open for further replies.
Top