Best way to double unhapiness from captured cities

frutiemax

Warlord
Joined
Jan 19, 2015
Messages
127
Hi, I've played quite some time at Civ V and I really like the mods people are making. I'm quite familiar to programming languages so it isn't a problem.

I'd like to know the best method to double unhapiness from occupied cities for a particuliar civilization. I thought about adding a building to the city when occupied but I think it requires lua scripting. I've found this particular event that might be useful:

http://modiki.civfanatics.com/index.php/GameEvents.CityCaptureComplete_(Civ5_API)

Now, how do I use this event in a lua script? Am I just copying the function definition in a lua script in my mod and adding the building from there?

Thanks for reading my message.
 
CityCaptureComplete is a Game Event, which means it will fire whenever its associated event (a city switching owners) occurs.

The Game Event itself returns a couple of parameters in a specific order.
What you would do then is to create a function which uses these parameters, and then does something you want.

After that, you would add your function into the game event hook via GameEvents.CityCaptureComplete.Add() so that the game will run your function alongside whatever else it normally has to run during that point.

For example, at the minimum, you can use the first 5 or 6 parameters (nothing says you need to use all of them, but you do need to account for them being given to you in a specific order) to create a new function:

Code:
function OnCityCaptured(iOldOwner, bIsCapital, iX, iY, iNewOwner)
	if bIsCapital then
	-- stuff here
	end
end
Then you'd insert it into the game via:
Code:
GameEvents.CityCaptureComplete.Add(OnCityCaptured)

Note that this event fires whenever a City changes owners -- so not necessarily only through war! It fires when cities are traded as well, I believe.
 
DarkScythe: Thanks for the quick response. For doubling unhapiness from population in occupied, should I create a dummy building that set the UnhappinessModifier to 200 and add it to the occupied city?
 
While you could do that, I don't believe it will work.

The reason is that, UnhappinessModifier is only used in the game for the Forbidden Palace, and so I believe Firaxis coded that column to only accept negative values.

I could be wrong though since I haven't tried it myself, so it's worth a test, but I believe altering unhappiness through that column won't work.
 
It's global to all unoccupied cities:
Code:
UnhappinessModifier
	Adjusts "Unhappiness" by a percentage. Only affects cities that are not "occupied". "Occupied" has nothing to do with whether or not
	a military unit is standing on the city-tile. "Occupied" means "conquered". Until you build a Courthouse in a conquered
	city, it will remain "occupied", and won't recieve the "UnhappinessModifier". The format to reduce unhappiness by 10% in
	non-conquered cities is:

			<UnhappinessModifier>-10</UnhappinessModifier>

	You need the "-" sign, otherwise you would make your building INCREASE unhappiness.
Taken from the text-only version of my guide. I've never actually tried it with a positive number, but it isn't what you want anyway. Though I should be more specific in my description and make it crystal clear that it affects all cities in the empire that do not have the occupied unhappiness slave-chain symbol.
 
Back
Top Bottom