Hi there, I'm currently trying to find a way to either replace (or delete) all settlers that spawn beyond the initial one (Collective Rule, starting in a later era, captured, being gifted one etc.) or prevent founding more than the capital for my custom civilization. I managed to find an example snippet of Lua (posted below) that works to some extent - when you try to move with a settler it'll replace them with a worker instead - however the problem is that you can softlock the game if you move your last remaining settler as it will replace that too. Also if you could somehow get control of a settler enough tiles away from your capital you'd be able to found another city as long as you didn't move the unit.
Unfortunately I really don't understand Lua, and despite many hours of trawling around I just can't work out how to do this. Is there anyone who could help?
Unfortunately I really don't understand Lua, and despite many hours of trawling around I just can't work out how to do this. Is there anyone who could help?
Code:
function ReplaceSettler(iPlayer, iUnitID, iX, iY)
local pPlayer = Players[iPlayer];
if pPlayer:GetCivilizationType() == GameInfo.Civilizations.CIVILIZATION_PRIPRICH.ID then
local pUnit = pPlayer:GetUnitByID(iUnitID);
if (pUnit == nil or pUnit:IsDelayedDeath()) then
return false;
end
if pUnit:GetUnitType() == GameInfoTypes["UNIT_SETTLER"] then
newUnit = pPlayer:InitUnit(GameInfoTypes["UNIT_WORKER"], iX, iY);
newUnit:FinishMoves();
pUnit:Kill(true, -1);
end
end
end
GameEvents.UnitSetXY.Add(ReplaceSettler);