Civilization Trait Help

Gunnaka

Chieftain
Joined
Oct 18, 2012
Messages
20
I already posted this on the main board, but this seems like a more suitable place.

Is there anybody that can help me make a Civ trait that will convert a city to your religion when you conquer it?
 
That would be pretty simple to implement. The rough pseudo-code would look something like:

Code:
function convertCityOnCapture(oldPlayerID, capital, iX, iY, newPlayerID, conquest1, conquest2)
player = Players[newPlayerID];
  // Make sure the conquer has the trait and has founded a religion
  if(player == Civ with trait && player:GetReligionCreatedByPlayer() >= 1) then
    // get the city object
    city = Map.GetPlot(iX, iY).GetPlotCity();
    city:AdoptReligionFully(player.GetReligionCreatedByPlayer());
  end
end

GameEvents.CityCaptureComplete.add(convertCityOnCapture)
 
Alright, thank you for the help.

What would I have to do with this to make it able to be implemented into my mod? Sorry for the basic questions, I have no past experience.
 
Don't worry about asking newbie questions, we all had to learn this stuff once. For lua files there are two ways to put them in your mod.

1) In your mod properties go to the "content" tab. Add a new row where TYPE is InGameUIAddin and FILENAME is the name path and name of your lua file (NAME and DESCRIPTION can be whatever).

2) The other approach is for when you're replacing existing lua files (which isn't what you're doing here). You have to set VFS to true and name the file to the same as the file it is replacing.
 
Okay and what would I have to do to the code you gave me to make it a working feature? Obviously I'd have to specify the Civilization the trait is for, but what else?
 
Code:
function convertCityOnCapture(oldPlayerID, capital, iX, iY, newPlayerID, conquest1, conquest2)
[COLOR="Red"]local[/COLOR] player = Players[newPlayerID];
  // Make sure the conquer has the trait and has founded a religion
  if([COLOR="Red"]player == Civ with trait &&[/COLOR] player:GetReligionCreatedByPlayer() >= 1) then
    // get the city object
    [COLOR="Red"]local[/COLOR] city = Map.GetPlot(iX, iY).GetPlotCity();
    city:AdoptReligionFully(player.GetReligionCreatedByPlayer());
  end
end

GameEvents.CityCaptureComplete.[COLOR="Red"]a[/COLOR]dd(convertCityOnCapture)

The red parts need to be changed. The second one needs to be "Add" not "add". The first part needs to be changed to:

if(player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AUSTRIA"] and player:GetReligionCreatedByPlayer() >= 1) then

I haven't tested the code so it may not work.
---------
Edit: This post originally contained two errors. (the "local" was missing for the player and city variable)
 
Hmm, I finally got around to testing it, and it doesn't seem to work as it is. Do you have any idea where there could be problems in it?
 
1) Is the Lua file added as an InGameUIAddin correctly (see reference in Tuts and Ref sub-forum)
2) Enable logging and check the lua.log file for errors (see reference in Tuts and Ref sub-forum)
3) If you still can't figure it out, zip the mod from the MODS sub-dir and attach it - as it is impossible for us to work-out what the error(s) are without the actual mod
 
There doesn't seem to be any errors in how it's added in. Does anybody know if the code itself should work as it is was written a few posts up, with the changes he said added.
 
Did you change the GameInfoTypes["CIVILIZATION_AUSTRIA"] part to whatever civilization you're playing as?

You can add a print line to the code to help you see what is going on. Try putting:

print("In the convertCityOnCapture code");

as the first line of the convertCityOnCapture function (just above the: player = Players[newPlayerID];) line.
 
Top Bottom