Tomatekh
Emperor
- Joined
- Aug 6, 2012
- Messages
- 1,434
So I wrote this bit of code which is supposed to check if you're friends or higher with a city-state. If so, every x turns, initunit a unit in any city owned by a friendly city-state.
The code does work except it will only spawn one unit and in the first friendly city-state of the list regardless of if you are friendly with multiple city states. Any advice as to how to get it to spawn a unit for every friendly city-state?
Spoiler :
Code:
function TupiCSAllies(iPlayer, iCurrentTurn)
local pPlayer = Players[iPlayer];
for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 2 do
local tPlayer = Players[i];
if (tPlayer:GetMinorCivFriendshipLevelWithMajor(pPlayer:GetID()) >= 1) then
for cityindex = tPlayer:GetNumCities() - 1, 1 do
local tCity = tPlayer:GetCityByID(cityindex);
--Test Unit
local TestUnit = "UNIT_WARRIOR"
pUnit = pPlayer:InitUnit(GameInfoTypes[TestUnit], tCity:GetX(), tCity:GetY())
pUnit:JumpToNearestValidPlot()
end
end
end
end
function TupiGameSpeed(iPlayer, iCurrentTurn)
local speed = Game.GetGameSpeedType();
if speed == GameInfo.GameSpeeds['GAMESPEED_QUICK'].ID then
if ( iCurrentTurn % 6 ) == 0 then
TupiCSAllies(iPlayer, iCurrentTurn)
end
elseif speed == GameInfo.GameSpeeds['GAMESPEED_STANDARD'].ID then
if ( iCurrentTurn % 10 ) == 0 then
TupiCSAllies(iPlayer, iCurrentTurn)
end
elseif speed == GameInfo.GameSpeeds['GAMESPEED_EPIC'].ID then
if ( iCurrentTurn % 15 ) == 0 then
TupiCSAllies(iPlayer, iCurrentTurn)
end
elseif speed == GameInfo.GameSpeeds['GAMESPEED_MARATHON'].ID then
if ( iCurrentTurn % 30 ) == 0 then
TupiCSAllies(iPlayer, iCurrentTurn)
end
end
end
function TupiCityStateScript(iPlayer)
local iCurrentTurn = Game.GetGameTurn()
if (Players[iPlayer]:IsAlive()) then
--Test to fire with a civ, change to check for a trait later
if (Players[iPlayer]:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AZTEC"]) then
TupiGameSpeed(iPlayer, iCurrentTurn)
end
end
end
GameEvents.PlayerDoTurn.Add(TupiCityStateScript)