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

[General] Unit Limiter

Status
Not open for further replies.
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.
 
Level 2
Joined
Jul 6, 2013
Messages
6
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. :grin:

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

Attachments

  • Footman.w3x
    16.9 KB · Views: 45
Last edited:
Level 10
Joined
Jun 6, 2007
Messages
392
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)
 
Level 7
Joined
Mar 6, 2014
Messages
203
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....
 
Status
Not open for further replies.
Top