Craig_Sutter
Deity
The following code is supposed to determine if a city converts to a religion, and if a majority of a city states cities have that religion, convert all of them...
I am using pPlayer:HasOthersReligionInMostCities(eReligion)... I have also tried pPlayer:HasReligionInMostCities(eReligion).
I think they may not do what I think they do... if not, I need to figure out a way to determine when the majority of a civilization's cities have converted to a certain religion.
The following code is what I am using... I'm not great at lua, but I want the conversion to happen only once per civilization. I hope I have gotten that right.
Anyhow, no errors show up in the following code in my logs... however, the function does not kick in when 2 or 3 of a minor civ have converted to Catholicisim (which is what I wish to occur).
Anyone know if the above functions are the ones I need to do the job, or is there an error in my coding that is giving me a null value?
Thanks.
I am using pPlayer:HasOthersReligionInMostCities(eReligion)... I have also tried pPlayer:HasReligionInMostCities(eReligion).
I think they may not do what I think they do... if not, I need to figure out a way to determine when the majority of a civilization's cities have converted to a certain religion.
The following code is what I am using... I'm not great at lua, but I want the conversion to happen only once per civilization. I hope I have gotten that right.
Anyhow, no errors show up in the following code in my logs... however, the function does not kick in when 2 or 3 of a minor civ have converted to Catholicisim (which is what I wish to occur).
Anyone know if the above functions are the ones I need to do the job, or is there an error in my coding that is giving me a null value?
Thanks.
Code:
-- converts minor civilization to Catholicism is enough cities are Catholic
local modData = Modding.OpenSaveData()
local modSussexCatholicKey = "SussexCatholic"
local haveSussexCatholic = (modData.GetValue(modSussexCatholicKey) == 1)
function MinorConvert(iPlayer, eReligion, iX, iY)
if eReligion == GameInfoTypes["RELIGION_CHRISTIANITY"] then
local pPlayer = Players[iPlayer];
local civType = pPlayer:GetMinorCivType();
if civType == GameInfo.MinorCivilizations["CIVILIZATION_SUSSEX"].ID then
if (pPlayer:HasOthersReligionInMostCities(eReligion)) then
if (civType == GameInfo.MinorCivilizations["CIVILIZATION_SUSSEX"].ID) then
if (haveSussexCatholic == false) then
for pCity in pPlayer:Cities() do
-- City exists?
if pCity ~= nil then
pCity:ConvertPercentFollowers(1, -1, 75);
print(pCity:GetName(), "...is getting Catholic followers...");
return pCity
end
end
haveSussexCatholic = true
modData.SetValue(modSussexCatholicKey, 1)
end
end
end
end
end
end
GameEvents.CityConvertsReligion.Add (MinorConvert);