Craig_Sutter
Deity
I've created the following code meant to spawn units at a specific game year. I have found simply doing Game.GetGameTurnYear() == 501 does not work always so I am using a range of years to cover instances where 1 turn is 3 years. Even if the previously mentioned game year worked, if there are more than one turn in a year, the function fires each turn.
I am not familiar with using a count to fire of Lua functions. I suspect I need to set a count so that if count<= one, the function will fire, and if not, it well end.
I do not know how to do this.
I also foresee a problem if the script does not remember the count and a game is saved, the script will not remember the count and fire as if it were the first go.
The latter problem is a minor one, however, and I'm willing to trade simplicity for probability it does not matter a whole lot if such happens.
Can anyone give me a hint about how to go about limiting the number of times my units will spawn within the given range of years?
BTW, the reason I am using year rather than turn is that I want to use the lua for all game speeds.
Any help would be appreciated.
Regards. Craig
I am not familiar with using a count to fire of Lua functions. I suspect I need to set a count so that if count<= one, the function will fire, and if not, it well end.
I do not know how to do this.
I also foresee a problem if the script does not remember the count and a game is saved, the script will not remember the count and fire as if it were the first go.
The latter problem is a minor one, however, and I'm willing to trade simplicity for probability it does not matter a whole lot if such happens.
Can anyone give me a hint about how to go about limiting the number of times my units will spawn within the given range of years?
BTW, the reason I am using year rather than turn is that I want to use the lua for all game speeds.
Code:
function SpawnAngles()
if Game.GetGameTurnYear() >= 501 and Game.GetGameTurnYear() <= 503 then
-- Set up Angles Player
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local pAngles = Players[iPlayer]
if (GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID == pAngles:GetMinorCivType()) then
Angles = pAngles
-- Enumerate cities
for cityIndex = 0, Angles:GetNumCities() - 1, 1 do
local pCity = Angles:GetCityByID(cityIndex);
local pPlot = pCity:GetCityIndexPlot();
local Spawnunit;
local iSpawnX = pPlot:GetX();
local iSpawnY = pPlot:GetY();
Spawnunit = Angles:InitUnit(GameInfoTypes["UNIT_SEAXMAN"], iSpawnX, iSpawnY, UNITAI_ATTACK, DIRECTION_NORTHWEST );
end
end
end
end
end
Events.ActivePlayerTurnEnd.Add(SpawnAngles)
Any help would be appreciated.
Regards. Craig