SetUnitCount not working [Solved]
Posted: Sat Nov 01, 2014 4:14 am
Hi everyone.
I'm attempting to have my defending team's unit count reduced to 10 units on the map, toward the end of the battle. However the SetUnitCount code does not seem to be working and there are still over 50 units on the defending team after the code runs. Here is the function it runs from. You'll find the SetUnitCount bit about halfway down:
EDIT: SOLVED
My idea of what SetUnitCount does behind the scenes was wrong this whole time. I thought it would check the map to see how many units are alive and if that number was more than the new unit count setting then it would stop spawning AI until the number of alive units dropped to below the newly set count. However, the game doesn't seem to care how many are already alive, it just keeps turning out new units. When I tested my various "solutions" this is what was happening. The game just kept replacing the units my team was killing at a rate roughly equivalent to that at which we were destroying them.
So... my solution (and I'm sure this is one of many different possible solutions to this) is this:
Essentially as soon as I set my new unit limit I stop the AI on team 2 from spawning for 35 seconds and then let them spawn again. Eventually I'll probably implement a more sophisticated solution such as tracking how many units are running around and preventing AI spawning until that number = 15. For now this works fine and seems pretty balanced.
TL;DR: Marth was right, see below
I'm attempting to have my defending team's unit count reduced to 10 units on the map, toward the end of the battle. However the SetUnitCount code does not seem to be working and there are still over 50 units on the defending team after the code runs. Here is the function it runs from. You'll find the SetUnitCount bit about halfway down:
Hidden/Spoiler:
My idea of what SetUnitCount does behind the scenes was wrong this whole time. I thought it would check the map to see how many units are alive and if that number was more than the new unit count setting then it would stop spawning AI until the number of alive units dropped to below the newly set count. However, the game doesn't seem to care how many are already alive, it just keeps turning out new units. When I tested my various "solutions" this is what was happening. The game just kept replacing the units my team was killing at a rate roughly equivalent to that at which we were destroying them.
So... my solution (and I'm sure this is one of many different possible solutions to this) is this:
Hidden/Spoiler:
TL;DR: Marth was right, see below