The problem is as follows - I need a code that will restrict the number of a specific turrets available for build, and then unrestrict them again when they get killed.
Now the restricting i have, and it goes as follows:
- Code: Select all
OnStopBuild = function(self, sbrot1expd, order)
AAirUnit.OnStopBuild(self, sbrot1expd)
--restrict the total number of things we can build
local army = self:GetArmy()
List = GetArmyBrain(army):GetListOfUnits(categories.ALLUNITS, false, true)
for k, unit in List do
if (unit:GetUnitId() == 'sbrot1expd') then --my turret that I only need 2 of at any given time
table.insert(num_Mizura, unit); -- add unit to special unit list
if (table.getn(num_Mizura) >= 2) then
self:AddBuildRestriction( categories.sbrot1expd ) -- works like a charm
end
end
end
end,
Now comes the tricky part (for noob me, at least).
unrestricting the turret when it gets killed.
Now, I tried it like this
- Code: Select all
OnStartReclaim = function(self, target) -- the unit is gonna do a ton of reclaiming, that's why
AAirUnit.OnStartReclaim(self, target)
local army = self:GetArmy()
List = GetArmyBrain(army):GetListOfUnits(categories.sbrot1expd, false, true)
for k, unit in List do
if (table.getn(num_Mizura) <= 1) then
self:RemoveBuildRestriction( categories.sbrot1expd )
table.remove(num_Mizura, unit)
end
end
end,
but what I guess is happening is that the list gets filled more and more with every OnStopBuild, instead of having only 2 units in there, for my 2 turrets...and is not getting lesser when the turrets die.
So I figured - well it should then be in OnKilled script of the actual turret...tried to make that, but failed
- Code: Select all
OnKilled = function(self, instigator, damagetype, overkillRatio)
TStructureUnit.OnKilled(self, instigator, damagetype, overkillRatio)
local army = self:GetArmy()
List = GetArmyBrain(army):GetListOfUnits(categories.sbrot1expd, false, true)
for k, unit in List do
-- if (unit:GetUnitId() == 'sbrot1expd') then
table.remove(num_Mizura, 1); -- was table.remove(num_Mizura, unit), that's why I got the whole GetArmyBrain etc... but that gave me an error, asked for numerical value...what does the num value do here?
end
self:CreatTheEffectsDeath()
end,
So now...no idea how to pull that off. (Yes i have the local num_Mizura = {}; defined at start in both script files)
Any thoughts, or at least maybe point me in a direction of a mod/map that did this with another unitand i will be able to figure it out for myself...
Thanx.