[Lua] Changing Civilization and Leader Ingame

Is it possible to change civilization or leader ingame?

Well... depends on how you define civilization and leader. Let's take leader for example:

If you mean changing between leaders as defined by the xml files...then no.

But if "leader" is defined as the text and pictures shown to the human player (via UI) plus some Lua controlled AI behavior...then yes you can.

Same for civilization.
 
Well... depends on how you define civilization and leader. Let's take leader for example:

If you mean changing between leaders as defined by the xml files...then no.

But if "leader" is defined as the text and pictures shown to the human player (via UI) plus some Lua controlled AI behavior...then yes you can.

Same for civilization.

Thanks :)

That's unfortunate, hopefully we will get the DLL soon.

One other question, is it possible to raze certain cities automatically? For instance, if I wanted the cities of certain city-states to be razed automatically if conquered.
 
One other question, is it possible to raze certain cities automatically? For instance, if I wanted the cities of certain city-states to be razed automatically if conquered.

Yes, in Lua. Just make a city capture event trigger that razes the city automatically using the Player:Raze(cityID) function. Note, though, that the AI won't understand this process; it'll think that it's trying to capture the city intact and won't understand why the city just disappeared.
 
Yes, in Lua. Just make a city capture event trigger that razes the city automatically using the Player:Raze(cityID) function. Note, though, that the AI won't understand this process; it'll think that it's trying to capture the city intact and won't understand why the city just disappeared.

Do you know the name of the city capture event trigger?

I tried this:

Code:
function AcquireCity( pCity, bConquest, bTrade )
	local player = Players[pCity:getOwner()];

	if (bConquest) then
		if (player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_BATAVIANS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_GELEONTES"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_SAXONS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_TUPINIQUIM"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_UIGHURS"].ID) then
			pCity:kill();
		end
	end
end

GameEvents.PlayerAcquireCity.Add( AcquireCity )

But it didn't work. PlayerAcquireCity probably doesn't exist I suppose (I thought it might and tried it out that way).
 
Bookmark this page. There's no need to make guesses like that. Besides, there are only eight or nine GameEvents; nearly everything else is in the normal (serial) Event list, so it's HORRIBLY unlikely that a random guess at a GameEvent would turn out to work. And you really can't just make guesses for what the arguments of something would be. (Besides, no Event uses a structure like pCity as an argument. Ever. Arguments are integers like city ID or X and Y values.)

The best choice is the CityCaptureComplete GameEvent. You have to do a small amount of work to figure out which city it was, since that function's arguments only include its X and Y values, but that's hardly a difficult thing.
 
Do you know the name of the city capture event trigger?

I would use Events.SerialEventCityCaptured, which passes: hexPos, playerID, cityID, and newPlayerID.

You can see an example of it in action in CivsAlive.lua in the Mongol Scenario.
I'm not sure if this fires when the capture isn't observed by the player tho, unfortunately some SerialEvents don't.

Check out the 2k wiki for the list of Events: http://wiki.2kgames.com/civ5/index.php/Lua_Game_Events
and the newer GameEvents: http://wiki.2kgames.com/civ5/index.php/Lua_Game_Objects/GameEvents
there are also some newly added GameEvents that aren't on the wiki, you can find them listed in the patch notes, here (at the end of the article)

edit: oops, got beaten to it. Forgot about CityCaptureComplete, that's better than using a SerialEvent.
 
Thanks very much to both!

I tried this:

Code:
function RazeTribalSettlement(playerID, bCapital, iX, iY, newPlayerID)
	local player = Players[playerID]
	local city = Map.GetPlot(iX,iY):GetPlotCity();

	if (player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_BATAVIANS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_GELEONTES"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_SAXONS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_TUPINIQUIM"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_UIGHURS"].ID) then
		city:Kill();
	end
end
GameEvents.CityCaptureComplete.Add(RazeTribalSettlement)

And upon conquest of the city, something strange happened. The message with "Entering this city will cause WAR!" popped up, but with no choices being available. It couldn't be rid of.

Then I tried this (changes in red):

Code:
function RazeTribalSettlement(playerID, bCapital, iX, iY, newPlayerID)
	local player = Players[playerID]
	[COLOR="Red"]local newplayer = Players[newPlayerID][/COLOR]
	local city = Map.GetPlot(iX,iY):GetPlotCity();

	if (player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_BATAVIANS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_GELEONTES"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_SAXONS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_TUPINIQUIM"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_UIGHURS"].ID) then
		[COLOR="Red"]newplayer:Raze(city);[/COLOR]
	end
end
GameEvents.CityCaptureComplete.Add(RazeTribalSettlement)

But then, nothing happened upon city conquest.
 
But then, nothing happened upon city conquest.

GameEvents preempt the event they're tied to, unlike serial events that happen afterward. So ownership of the city probably hadn't passed to the new player yet, and you can't raze what you don't own. (Easy way to find out: once you have the city structure, have a print statement say who its owner is.) But you're on the right track; I can try a few things when I get home from work.
 
Ok, so I tried this:

Code:
function OnCityCaptured(hexPos, playerID, cityID, newPlayerID)
	local player = Players[playerID]
	local newplayer = Players[newPlayerID]
	local city = Map.GetPlot(ToGridFromHex(hexPos)):GetPlotCity();

	if (player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_BATAVIANS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_GELEONTES"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_SAXONS"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_TUPINIQUIM"].ID or player:GetMinorCivType() == GameInfo.MinorCivilizations["MINOR_CIV_UIGHURS"].ID) then
		city:Kill();
	end
end
GameEvents.SerialEventCityCaptured.Add(OnCityCaptured)

But nothing happens when I conquer the city in question. I also tried player:Raze(city) and newplayer:Raze(city) (although when I did I tried to get the city by it's ID rather than the method I'm using now), but neither worked as well.
 
Top Bottom