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:
[code]
function LastStand()
if GetObjectTeam("cp6") == ATT and GetObjectTeam("cp7") == ATT then
--Tell the humans where to go next.
ShowMessageText("level.dda.objectives.laststand1",1)
ShowMessageText("level.dda.objectives.laststand2",2)
--Let's muck around with the spawn weights to produce a better final battle sequence.
SetProperty("cp6", "AISpawnWeight", "500") --FOR THE REPUBLIIIIIC
SetProperty("cp7", "AISpawnWeight", "500") --ALSO FOR THE REPUBLIIIICCCC
SetProperty("cp8", "AISpawnWeight", "750") --For the CIS...
--And it's actually pretty vital that they try and fight over this particular CP.
SetProperty("cp8", "Value_DEF_CIS", "2000")
SetProperty("cp8", "Value_ATK_Republic", "2000")
--We'll remove distractions.
SetProperty("cp1", "Value_DEF_Republic", "0")
SetProperty("cp2", "Value_DEF_Republic", "0")
SetProperty("cp3", "Value_DEF_Republic", "0") --etc
AICanCaptureCP("cp6", DEF, false)
AICanCaptureCP("cp7", DEF, false)
AICanCaptureCP("cp8", ATT, true)
--To avoid the Battle of Thermopylae...
DEF_ReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEF_ReinforcementCount + 100)
SetUnitCount(DEF, 10)
--And we start the countdown. After 4min Republic loses unless they cap the CP
StartTimer(endgame)
ShowTimer(endgame)
OnTimerElapse(
function(endgame)
if GetObjectTeam("cp8") == DEF and DEF_ReinforcementCount > 0 then
SetReinforcementCount(ATT, 0)
end
DestroyTimer(endgame)
end,
endgame
)
OnFinishCaptureName(
function (repvictory)
if GetObjectTeam("cp8") == ATT then
SetReinforcementCount(DEF, 0)
end
end,
"cp8"
)
else
ShowMessageText("level.dda.objectives.pushback1",1)
ShowMessageText("level.dda.objectives.pushback2",2)
end
end
[/code]
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
Last edited by jedimoose32 on Thu Nov 06, 2014 4:31 pm, edited 1 time in total.
Yes. Other units are still spawning. I've continued the battle for 5+ minutes after the switch should have happened and it is pretty clear that there are still 70 CIS units on the map (the number 70 is defined at team setup). I'm not sure what I've missed.
Edit: I tried setting up my CIS team as you see below, without the unit count parameters after the unit names, because I saw that that's how they were set up in kas2c_c.lua and I thought it may fix things. I tried removing the unit counts altogether but found there were too many snipers, so I re-added some of them, in small enough quantities that the ones that are defined should still equal less than 10:
Unfortunately this did not help. After the switch was supposed to happen I gave it a few minutes, killed at least 40 or 50 units, and then went over a small hill to see a stream of 25+ CIS units running toward me from their CP. I don't understand how this is not working.
There's a GetUnitCount(team) you could use to double check that the unit count is changing. FC uses SetUnitCount() for the 'Add Units to Team 1/2' commands.
I'd recommending using FC to kill all the AI units a couple times to make sure that the existing units aren't the problem.
The other thing to check is to see if SetUnitCount works to increase the unit count. Maybe decreasing doesn't work (but I thought it did).
Everything else works right? DEF's reinforcements change? DEF is defined? Nothing in the debug log?
DEF is defined. The reinforcements increase appropriately as well. The whole function works perfectly except for the SetUnitCount. I'll try the tests you suggested.
Edit: I re-read your comment about the FC command, and then I went and tried to use it, and the prompt says negative numbers are accepted. So my theory (untested as of this moment because I'm tired of testing for this evening) is that SetUnitCount does not "set" the unit count but instead increases it if a positive value is used and decreases it if a negative value is used.
Again, this is totally theoretical but it would explain why I was still seeing a truckload of SBDs heading my way... the command was adding 10 units to the CIS side instead of setting it to 10.
ff_AddCommand( "Add Units to Team 2", nil, function()
local temp = function( rate )
if not rate then return end
SetUnitCount(2, GetUnitCount(2) + rate)
end
ff_AskUser("Please enter the amount of units to add to team 1 (negative numbers allowed)", temp, ifs_fakeconsole )
end, nil)
It takes the existing number of units and combines that with whatever number the user typed.
This worked, however it sets the unit count to 10 when the game starts and I still can't change it later on. I even tried setting up a function with no conditions (just gets called right at the start of the round) that should immediately change the unit count but that does nothing.
Edit 5: Solved it! See first post for the solution.