# [General]Unit Limiter

Status
Not open for further replies.

#### iamdl

Level 7
How to make a unit limiter?
eg. The max limit for the footman is only 3 when the numbers of footman reach the limit the older footman dies.
Thx.

#### deathismyfriend

Level 29
Make a real variable called GameTime.
Make a periodic trigger that runs every 0.03 and increase the GameTime variable by the amount it runs at.

Store the max number of those units in a hashtable based on the unit type id.
Store each unit into a hashtable based on their unit type and integer number of units for player.
Store each units GameTime in the hashtable.
Increase an integer that keeps track of how many units that players has of that unit type.

When a new unit is created check to see if the amount if units is more than max.
If it is more than max then load the units stored and check for the GameTime that they were created. After finding lowest GameTime value remove that unit. Then store the new unit in that position.

As units die you would need to remove them to clean the leaks. Then move the last units indexer (the integer value above) to the one that was removed.
So that the newest unit always stays as the last index and you do not have to loop through empty indexes when looking for units to remove.

#### inusenshi

Level 2
Hello, well I'm not an expert, so I tried to do something simple.

• Footman
• Events
• Unit - A unit enters (Playable map area)
• Conditions
• (Unit-type of (Entering unit)) Igual a Soldado raso
• Actions
• Set Footman_array = (Footman_array + 1)
• Set Footman_id[Footman_array] = (Last created unit)
• Unit - Remove Footman_id[(Footman_array - 3)] from the game
When a Footman enters in Playable Area this trigger gives it an "id". Then when a 4th Footman enters in the game this "system" will remove the older Footman.
There's only a problem, this won't work if there're more than 8000 Footman (I can't remember the exact number).

I attached an example for you (Write "foot" to create a footman). You must change the "-3" For the limit of unit of the type that you want.

I'm really Sorry for my English it's not very good.

EDIT: Use "Entering Unit" instead "Last Created Unit"

#### Attachments

• Footman.w3x
16.9 KB · Views: 45
Last edited:

#### Erkki2

Level 10
You can also set training limit, which will prevent training a unit, instead of killing it. This is not exactly what you're asking for, but it might be useful depending on your application.
• Player - Limit training of Footman to 3 for Player 1 (Red)

#### deathismyfriend

Level 29
@ inusenshi
Please post all the triggers. Also never use entering unit. Use triggering unit instead.
Entering unit is slower than just using triggering unit.

#### iamdl

Level 7
You can also set training limit, which will prevent training a unit, instead of killing it. This is not exactly what you're asking for, but it might be useful depending on your application.
• Player - Limit training of Footman to 3 for Player 1 (Red)

Im not going to train them.... just i want is to make a limit on footman... ex. I cast thunder clap then after the effect 1 footman will create at front of me when i cast the skill 3 times the older footman will die....

#### deathismyfriend

Level 29
Im not going to train them.... just i want is to make a limit on footman... ex. I cast thunder clap then after the effect 1 footman will create at front of me when i cast the skill 3 times the older footman will die....

As i said above would work the best then.

Status
Not open for further replies.

[Trigger] Unit limiter
Replies
1
Views
1K
Replies
3
Views
3K
Replies
3
Views
694
Replies
15
Views
2K
Replies
2
Views
566