Writing if(city captured) in LUA

ChrisEdgeworth

Chieftain
Joined
Sep 22, 2014
Messages
3
I'm working on a mod that alters the revolt time of annexed cities, and I was curious what the relevant statements would be to write [if (city annexed) and civ = new civ, then revolt time = 50%]. I'm kinda a Lua scrub but I can figure out the structure pretty well its just the specific phrases I have no clue on. Thanks for any help!
 
That will be pretty easy to do as there is an event that fires when a city is captured and resistance time can be manipulated by city:ChangeResistanceTurns(int).

I have some code that makes it so captured city states have no resistance if the attacker has the Patronage Policy. It is very similar to what you're trying to do:
Code:
function NoResistanceCityStates(hexPos, playerID, cityID, newPlayerID)
	local oldPlayer = Players[playerID];
	local newPlayer = Players[newPlayerID];
	local policyID = GameInfoTypes["POLICY_PATRONAGE"];
	local plot = Map.GetPlot(ToGridFromHex(hexPos.x, hexPos.y));
	local city = plot:GetPlotCity();
	
	-- Only continue if player has policy and the city was controlled by a city-state
	if(newPlayer:HasPolicy(policyID) and not newPlayer:IsPolicyBlocked(policyID) and oldPlayer:IsMinorCiv()) then
		-- Remove any resistance
		city:ChangeResistanceTurns(-city:GetResistanceTurns());
	end
end
Events.SerialEventCityCaptured.Add(NoResistanceCityStates);
 
Back
Top Bottom