Could someone show me a Variant of the code. I am trying my best to get what you're saying but you guys are a lot more knowledgable than I.
Some of this is confusing me lol. Thanks for all the help and info though! :D
I didn't know looping that way was inefficient. That's good to know but I'm curious as to how much of a slow down it produces. In some cases looping through the map might be your only option.
Well, looping through tons of units when you don't need to do it obviously is less efficient than not doing it :D. In this specific case, it won't be a big deal, increasing an integer variable a maximum of thousand times is NOTHING, even if it is done a lot of times per second (which potentially happens for a map with huge spawn rates).
However, even when using your check for all units on the map, you don't even need to loop through all units, you can just count all units in a unit group consisting of all units on the map.
@ Pretend:
Do you know, what a variable is and how to use it? If yes, create a new global variable of type Integer, call it for example UnitsOnMap, set it to the initial amount of units on the map (by setting it to Count Unit in Unit Group ( Units in (Entire Map)) or by counting the actual units).
Then, add 2 new triggers, first one with the event Any Unit enters map and add an If-Then-Else to the actions: If UnitsOnMap is < 1000, then increment UnitsOnMap by 1, else remove (not kill!) the triggering unit, possibly display an error message.
The other trigger uses the event Any Unit Dies and decrements the variable by 1.
This is sort of the dirt-and-cheap method and requires you to never remove a unit without killing it, except for the first trigger I described.
A more advanced and more clean way would be, to actually disable the spawning of the units, instead of removing them after they already spawned. How you realize this depends on the specifics of your map. Do all your units spawn via trigger? In this case, it is easy, just add a condition to all of your possible triggered spawns, which checks for the units on the map. Can units be spawned via data? In this case, you can use validators and requirements to check for the units on the map, or use arbitrary validators you can set via trigger and add those to all of your spawn effects, behaviors and abilities.
I only want there to be a total of like 1000 units on the map at any given time.
I've seen plenty of threads about limiting unit count for players, but I want this to be for the map, not for the player.
@Trieva: Go
You can then increment some integer variable(s).
I believe this method should be faster. Selecting units on the whole map and looping them is rather inefficient.
Have 2 conditions, when unit created, check if unit matches condition, then increment.
Have another trigger that checks when a unit dies.
This way, no looping is required.
Supply limit. it works for player 0 and 15 too... (of course its not the best solution for all the maps, but the most easiest)
Could someone show me a Variant of the code. I am trying my best to get what you're saying but you guys are a lot more knowledgable than I. Some of this is confusing me lol. Thanks for all the help and info though! :D
Well, looping through tons of units when you don't need to do it obviously is less efficient than not doing it :D. In this specific case, it won't be a big deal, increasing an integer variable a maximum of thousand times is NOTHING, even if it is done a lot of times per second (which potentially happens for a map with huge spawn rates).
However, even when using your check for all units on the map, you don't even need to loop through all units, you can just count all units in a unit group consisting of all units on the map.
@ Pretend:
Do you know, what a variable is and how to use it? If yes, create a new global variable of type Integer, call it for example UnitsOnMap, set it to the initial amount of units on the map (by setting it to Count Unit in Unit Group ( Units in (Entire Map)) or by counting the actual units).
Then, add 2 new triggers, first one with the event Any Unit enters map and add an If-Then-Else to the actions: If UnitsOnMap is < 1000, then increment UnitsOnMap by 1, else remove (not kill!) the triggering unit, possibly display an error message.
The other trigger uses the event Any Unit Dies and decrements the variable by 1.
This is sort of the dirt-and-cheap method and requires you to never remove a unit without killing it, except for the first trigger I described.
A more advanced and more clean way would be, to actually disable the spawning of the units, instead of removing them after they already spawned. How you realize this depends on the specifics of your map. Do all your units spawn via trigger? In this case, it is easy, just add a condition to all of your possible triggered spawns, which checks for the units on the map. Can units be spawned via data? In this case, you can use validators and requirements to check for the units on the map, or use arbitrary validators you can set via trigger and add those to all of your spawn effects, behaviors and abilities.
Does this help you in any way?
Actually it works perfectly. Thank you very, very much! :)