Gaining a Bonus from Converting Cities to your Religion

octo

Chieftain
Joined
Jul 3, 2013
Messages
40
Location
philadelphia
So I've run into a bit of an issue for this mod that I'm updating and was hoping somebody might have a workaround. The code currently provides a bonus to Faith when one of my cities adopts a Religion I've founded, but it doesn't seem to work when opposing cities are converted, and I'm trying to figure out how to make that happen.

Spoiler :
Code:
function FaithFromConversions(ownerID, religionID, iX, iY)
	local player = Players[ownerID]
	if (player:IsAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_DESERET"]) then
		local religionID = player:GetReligionCreatedByPlayer();
		local city = Map.GetPlot(iX, iY):GetPlotCity()
		if (city:GetReligiousMajority() == religionID) then
			local numDeseretLand = player:GetNumPlots();
				player:SetFaith(player:GetFaith() + numDeseretLand)
		end
	end		  
end	
GameEvents.CityConvertsReligion.Add(FaithFromConversions)

-- End of Main Code --

print("DeseretUA loaded correctly")


Is there something that I'm missing about this? I can't seem to figure out how to make the effect happen when converting foreign cities.
 
Code:
if ......... player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_DESERET"] then
In and of itself limits the rest of the code to the player who is CIVILIZATION_DESERET.
 
So, just to be clear... What does that mean? This is one of the first things that I've totally coded on my own and I'm basically not sure where to go from here. From what I understand I have to make it attributed to all civilizations and not just my own, but I'm not sure how in terms of syntax.
 
OK, what you're doing now is only checking the religion of the city's owner to see whether to apply the effect. You'll need to loop through all of the players at that point.

Replace the player variable declaration in the first line of the function (realize you don't really care who owns the city) with:
Code:
for i = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
   local player = Players[i]
...and don't forget a corresponding "end" before the end of the function.

EDIT: It'll work either way, but you could spare some processor cycles by putting the city variable declaration before the for loop. Never mind, it shouldn't matter since we'll only have one Deseret civ. (It's past my bedtime...)
 
Back
Top Bottom