Detecting Heretics in a city

Uighur_Caesar

Comandante en Jefe
Joined
Mar 14, 2015
Messages
1,227
Location
Florida
I'm trying to make a UB that cost 1 gold for every heretic in the city and if no heretics are present it yields +2 faith. I'm not really sure if there's an easy way to detect heretics so I've tried this:

Code:
local SaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]

function Heretics(playerID)
local player = Players[playerID]
if (player:IsEverAlive() and player:GetCivilizationType() ~= SaudiID) then
local heretics = player:GetReligionCreatedByPlayer()
end
return Heretics
end

function ShariaHeretics(playerID, cityID)
local player = Players[playerID]
	if (player:IsAlive() and player:GetCivilizationType() == SaudiID) then
		local city = player:GetCityByID(cityID)		
		for city in player:Cities() do
		if city:IsHasBuilding(sharia) then
		local numHeretics = city:GetNumFollowers(heretics)
		local hereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
		city:SetNumRealBuilding(hereticCost, numHeretics)
		end
		end
		end
		end
GameEvents.PlayerDoTurn.Add(ShariaHeretics)

The Lua Log doesn't give me any errors but the dummies that subtract 1 gold aren't created. Are there any better ways of doing this or are there just mistakes with this code?
 
I'm trying to make a UB that cost 1 gold for every heretic in the city and if no heretics are present it yields +2 faith. I'm not really sure if there's an easy way to detect heretics so I've tried this:

Code:
local SaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]

function Heretics(playerID)
local player = Players[playerID]
if (player:IsEverAlive() and player:GetCivilizationType() ~= SaudiID) then
local heretics = player:GetReligionCreatedByPlayer()
end
return Heretics
end

function ShariaHeretics(playerID, cityID)
local player = Players[playerID]
	if (player:IsAlive() and player:GetCivilizationType() == SaudiID) then
		local city = player:GetCityByID(cityID)		
		for city in player:Cities() do
		if city:IsHasBuilding(sharia) then
		local numHeretics = city:GetNumFollowers(heretics)
		local hereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
		city:SetNumRealBuilding(hereticCost, numHeretics)
		end
		end
		end
		end
GameEvents.PlayerDoTurn.Add(ShariaHeretics)

The Lua Log doesn't give me any errors but the dummies that subtract 1 gold aren't created. Are there any better ways of doing this or are there just mistakes with this code?
Code:
local SaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]

function Heretics(playerID)
	local player = Players[playerID]
	if (player:IsEverAlive() and player:GetCivilizationType() ~= SaudiID) then
		local heretics = player:GetReligionCreatedByPlayer()
	end
	return Heretics
end

function ShariaHeretics(playerID, cityID)
	local player = Players[playerID]
	if (player:IsAlive() and player:GetCivilizationType() == SaudiID) then
		local city = player:GetCityByID(cityID)		
		for city in player:Cities() do
			if city:IsHasBuilding(sharia) then
				local numHeretics = city:GetNumFollowers(heretics)
				local hereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
				city:SetNumRealBuilding(hereticCost, numHeretics)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(ShariaHeretics)
  1. lua is case sensitive. heretics does not equal Heretics
  2. #1 Doesn't matter anyway because the entire function Heretics(playerID) is just dangling unused code not referenced or used anywhere
  3. GameEvents.PlayerDoTurn only sends one argument to any function added to it as a listener, so function ShariaHeretics(playerID, cityID) cannot make use of cityID. There is no 'there' there for it to access.
  4. if city:IsHasBuilding(sharia) then
    • sharia is not previously defined so is 'nil', and asking the game if a city has a building that is defined as 'nil' will never be evaluated as 'true'
  5. This also will be evaluated as a 'nil' variable because it has not been defined before: local numHeretics = city:GetNumFollowers(heretics)
    • Even though you have a thing defined as 'heretics' elsewhere in the code, this means nothing because of (a) the rules of localization, and (b) you have never told the game to run the function Heretics(playerID)
  6. function Heretics(playerID) has problems in that it never sorts for whether the player in question actually has founded a religion or not, or if they've only founded a pantheon.
    • player:GetReligionCreatedByPlayer() returns the following info:

      Integer Value Given Player Founded Religion
      -1 NO_RELIGION
      0 RELIGION_PANTHEON
      1 RELIGION_BUDDHISM
      2 RELIGION_CHRISTIANITY
      3 RELIGION_CONFUCIANISM
      4 RELIGION_HINDUISM
      5 RELIGION_ISLAM
      6 RELIGION_JUDAISM
      7 RELIGION_SHINTO
      8 RELIGION_SIKHISM
      9 RELIGION_TAOISM
      10 RELIGION_TENGRIISM
      11 RELIGION_ZOROASTRIANISM
      edit -> actually these values are incomplete because it was taken direct from the modwiki which has not been updated to BNW​
  7. playerID as you are using it will be the integer value assigned as a Player ID# at the start of the game for the player whose turn is currently being processed. So, in sequence, it will be the human player, than all other major player's still in the game, then city-states, then barbarians. So it cannot tell you anything about players other than the one currently being processed.

Having said all that it's starting to get a little late here for me but I'll try to remember to look at it again in the morning to suggest how I would go about fixing the problems, assuming no one else chimes in in the interim.
 
It seems to me that the following is needed:
  1. To define the civilization for which this code should run:
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    • Note that I have added the letter 'i' to signal that the data the variable iSaudiID is going to hold will be in a numerical (integer) form. This is not strictly necessary and many modders do not concern themselves with this convention, but I do find it easier to identify what sort of data a variable is holding when the convention is followed.
    • I have also eliminated the use of 'local' since in this particular case defining the variable as local is not really doing much for you. You want the variable and its data to be available to all functions that may be in the file, and not local to any one function that may be in the file. Placing the definition of the variable outside of any function will automatically make it available to all functions contained within the file, regardless really of whether this occurs at the top of the file or elsewhere, but it is generaly better to place it at the top where it is more visible and more obvious that this variable will be 'global' in the sense of available to all functions within the file.
  2. Define the special "Sharia" building:
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    • Note the slightly different form I have used for stating the reference to the GameInfoTypes. These two methods are equivalent to each other:
      Code:
      iSharia = GameInfoTypes.BUILDING_SOMETHING
      iSharia = GameInfoTypes["BUILDING_SOMETHING"]
    • Since I don't know the actual XML-name of the iSharia building as you are using it, I am using BUILDING_SOMETHING as a stand-in that you will need to change in your code
  3. Define the dummy building that adds the cost for heretics in the city:
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    • I have moved this outside of the function ShariaHeretics(playerID) because you are going to be repeatedly accessing this information from the database, which costs processing time, and each of us should do our best within our capabilities to reduce the amount of 'processing-time' overhead our individual mods create. This also applies to why I prefer to define such things as the Civilization and the Sharia building at this same point in the code. The game only has to scan through the XML/SQL database one time per player game session instead or on every turn or for every city a player has every turn.
  4. Define the function name that will run from the PlayerDoTurn Game Event, and defined the variable to be used within that function for the player ID# that is passed into the function from the PlayerDoTurn Game Event.
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
  5. Define the player object as a variable local to ShariaHeretics(playerID)
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
  6. Create a 'master-level' conditional check under which the rest of the code within ShariaHeretics(playerID) will reside.
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    • Only if the player currently being processed for the PlayerDoTurn Game Event is CIVILIZATION_UC_SAUDI will any of the rest of the code even try run.
    • From what DarkScythe has demonstrated to me, players that have been eliminated from the game no longer are executed for any PlayerDoTurn Game Event so it won't be necessary to do anything but check whether the player is the correct civilization.
  7. Check whether the player has founded a major religion yet, and only proceed if the player has founded a major religion
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    • I'm going to start wrapping in spoilers otherwise this post will get too unwieldy to look through
  8. Initiate a loop through all the player's cities:
    Spoiler :
    Code:
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    			for pCity in pPlayer:Cities() do
  9. For each of the player's cities, check for whether the city has the 'iSharia' building:
    Spoiler :
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    			for pCity in pPlayer:Cities() do
    				if pCity:IsHasBuilding(iSharia) then
    • If there's no iSharia building in the city there is no reason to process anything else for that individial city.
  10. Create a local variable specific for the individual city currently being processed. The local variable will hold the number of 'heretics' in the city. 'heretics' being defined as followers of a major religion different from the one founded by the player. The number of heretics will be recieved from running a function called GetNumberHeretics which as yet has not been defined in the code, but will be. GetNumberHeretics will be written so that is 'sends back' to the line where it is 'called' the data we need on the number of heretics within an individual city.
    Spoiler :
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    			for pCity in pPlayer:Cities() do
    				if pCity:IsHasBuilding(iSharia) then
    					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
  11. Set the number of dummy buildings (BUILDING_UC_HERETIC_COST) in the city equal to the number of heretics found in the city from the previous line of code.
    Spoiler :
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    			for pCity in pPlayer:Cities() do
    				if pCity:IsHasBuilding(iSharia) then
    					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
    					pCity:SetNumRealBuilding(iHereticCost, iNumHeretics)
  12. 'end' all the open ifs and fors, and 'hook-up' ShariaHeretics(playerID) to the PlayerDoTurn Game Event.
    Spoiler :
    Code:
    iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
    iSharia = GameInfoTypes.BUILDING_SOMETHING
    iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]
    
    function ShariaHeretics(playerID)
    	local pPlayer = Players[playerID]
    	if pPlayer:GetCivilizationType() == iSaudiID then
    		if pPlayer:GetReligionCreatedByPlayer() > 0 then
    			for pCity in pPlayer:Cities() do
    				if pCity:IsHasBuilding(iSharia) then
    					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
    					pCity:SetNumRealBuilding(iHereticCost, iNumHeretics)
    				end
    			end
    		end
    	end
    end
    GameEvents.PlayerDoTurn.Add(ShariaHeretics)
  13. Now it is necessarry to define the function GetNumberHeretics that was referenced, or 'called', earlier. So the first line defines the function and the variable arguments that must be passed to GetNumberHeretics in order for it to function properly:
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    • note that these arguments and their names 'match-up' to those used in the line
      Code:
      local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
    • It is not 100% necessary for the names to match, but it easier to understand and follow the code when they do
    • The important thing is that each argument which is defined as needed by a sub-function (such as GetNumberHeretics(pCity, pPlayer) ) is filled with a type of data that is needed for the function to run correctly.
  14. Define a local to be used exclusively within GetNumberHeretics that will be called iNumHeretics
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    • Even though there is a similarly-named variable in ShariaHeretics(playerID) these are two different variables, each one specific to its local 'setting'
    • This iNumHeretics is only active within function GetNumberHeretics(pCity, pPlayer) and will be discarded each time the function reaches its end
    • iNumHeretics will be used to store the sum total of 'heretics' found within the city for which GetNumberHeretics(pCity, pPlayer) is currently processing, and at the end of the function, this sum total will be sent back to the line
      Code:
      local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
  15. Grab the religion ID# of the religion founded by the player, and stick into a local variable where it is handy to use later. Remember that the only way the code can ever get to this point is if the player has founded a major religion.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
  16. Start a loop looking through the data within the <Religions> XML table. Each row within that table will be processed. If a subscriber to the mod is also running one of Tomateck's 9000-extra-religions mods, the code will take the data from that mod into account when making this loop through the table.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
  17. If the ID# assigned to the row currently being inspected is not the same ID# as what was placed into variable iPlayersReligion, and the ID# assigned to the row currently being inspected is greater than '0' (ie, not the row where RELIGION_PANTHEON is defined within the the <Religions> XML table), then process information for that row within the <Religions> XML table as it relates to followers of the religion that may be within the city.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
  18. If the number of followers within the city for the row within the <Religions> XML table is greater than zero (0), proceed to the next line.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
    			if pCity:GetNumFollowers(row.ID) > 0 then
  19. Add the number of followers in the city for the religion that matches up with the current row being inspected from table <Religions>. This is added to the pre-existing number of heretics already found within the city following any of the other religions that are not the one founded by the player.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
    			if pCity:GetNumFollowers(row.ID) > 0 then
    				iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
  20. add 'end' commands to terminate the open 'if' and 'for' lines
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
    			if pCity:GetNumFollowers(row.ID) > 0 then
    				iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
    			end
    		end
    	end
  21. 'return' (send back to wherever GetNumberHeretics(pCity, pPlayer) was called) the total number of heretics found within the city. This line also terminates any further execution of GetNumberHeretics(pCity, pPlayer), so if we had any needed code below this line, that would never get executed.
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
    			if pCity:GetNumFollowers(row.ID) > 0 then
    				iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
    			end
    		end
    	end
    	return iNumHeretics
  22. 'end' the code for function GetNumberHeretics(pCity, pPlayer). Even though actual execution is terminated by the 'return' command on the previous line, lua requires the 'end' command here to know where the end of the function GetNumberHeretics(pCity, pPlayer) is located. Otherwise lua would think anything contained within the same file, and located below the line function GetNumberHeretics(pCity, pPlayer) was still part of GetNumberHeretics(pCity, pPlayer).
    Spoiler :
    Code:
    function GetNumberHeretics(pCity, pPlayer)
    	local iNumHeretics = 0
    	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
    	for row in GameInfo.Religions() do
    		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
    			if pCity:GetNumFollowers(row.ID) > 0 then
    				iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
    			end
    		end
    	end
    	return iNumHeretics
    end
  23. Add a confirmation line that will print into the lua.log and into the Live Tuner a message that the file loaded completely and without syntax errors.
    Code:
    print("Sharia Heretics Detection loaded to the end of the file")
The code as discussed:
Spoiler :
Code:
[CODE]iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
iSharia = GameInfoTypes.BUILDING_SOMETHING
iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]

function ShariaHeretics(playerID)
	local pPlayer = Players[playerID]
	if pPlayer:GetCivilizationType() == iSaudiID then
		if pPlayer:GetReligionCreatedByPlayer() > 0 then
			for pCity in pPlayer:Cities() do
				if pCity:IsHasBuilding(iSharia) then
					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
					pCity:SetNumRealBuilding(iHereticCost, iNumHeretics)
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(ShariaHeretics)

function GetNumberHeretics(pCity, pPlayer)
	local iNumHeretics = 0
	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
	for row in GameInfo.Religions() do
		if (row.ID ~= iPlayersReligion) and (row.ID > 0) then
			if pCity:GetNumFollowers(row.ID) > 0 then
				iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
			end
		end
	end
	return iNumHeretics
end

print("Sharia Heretics Detection loaded to the end of the file")
[/code]

Note that I have not tested this since I don't have the rest of the mod it fits into, but I don't believe I've made any errors.

The file where this is placed should be set-up in ModBuddy as an InGameUIAddin.

If you get errors or whatever related to this code in the lua.log, zip up the version of the mod that is in your ~/MODS/ folder and I'll take a look at it
 
By Helix you're thorough! You can also directly query the database like so:

Code:
for row in GameInfo.Religions("ID > '0' AND ID <> '" .. iPlayersReligion .. "'") do

which is a bit faster and certainly saves on space.

If this effect were to be applicable empire-wide, instead of city-based, it would be cleaner - if not easier - to use my Dynamic Top Panel to subtract gold equal to the num of Heretics than to use a dummy building. In any case, if you want to add Piety support, I've made some adjustments to the code (also added a :IsAlive() check so that the code doesn't fire if the Sauds are dead):

Code:
iSaudiID = GameInfoTypes["CIVILIZATION_UC_SAUDI"]
iSharia = GameInfoTypes.BUILDING_SOMETHING
iHereticCost = GameInfoTypes["BUILDING_UC_HERETIC_COST"]

-- JFD_IsUsingPiety
function JFD_IsUsingPiety()
	local pietyModID = "eea66053-7579-481a-bb8d-2f3959b59974"
	local isUsingPiety = false
	for _, mod in pairs(Modding.GetActivatedMods()) do
	  if (mod.ID == pietyModID) then
	    isUsingPiety = true
	    break
	  end
	end
	return isUsingPiety
end
local isUsingPiety = JFD_IsUsingPiety()
if isUsingPiety then
   include("JFD_PietyUtils.lua")
end

function ShariaHeretics(playerID)
	local pPlayer = Players[playerID]
	if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iSaudiID then
		local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
                if isUsingPiety then
                      iPlayersReligion = JFD_GetStateReligion(iPlayer)
                end
                if iPlayersReligion > 0 then
			for pCity in pPlayer:Cities() do
				if pCity:IsHasBuilding(iSharia) then
					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
					pCity:SetNumRealBuilding(iHereticCost, iNumHeretics)
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(ShariaHeretics)

function GetNumberHeretics(pCity, pPlayer)
	local iNumHeretics = 0
	local iPlayersReligion = pPlayer:GetReligionCreatedByPlayer()
        if isUsingPiety then
             iPlayersReligion =JFD_GetStateReligion(iPlayer)
        end
       for row in GameInfo.Religions("ID > '0' AND ID <> '" .. iPlayersReligion .. "'") do
		if pCity:GetNumFollowers(row.ID) > 0 then
			iNumHeretics = iNumHeretics + pCity:GetNumFollowers(row.ID)
		end
	end
	return iNumHeretics
end

print("Sharia Heretics Detection loaded to the end of the file")
 
Thanks for the help guys! The heretic cost is working fine. Unfortunately the second part of the building is not. If there are no heretics in the city it's supposed to give you 2 faith. I've written this and the dummy building is not being added:

Code:
iUnity = GameInfoTypes["BUILDING_UC_RELIGIOUS_UNITY"]

function ShariaUnity(playerID)
	local pPlayer = Players[playerID]
	if pPlayer:GetCivilizationType() == iSaudiID then
		if pPlayer:GetReligionCreatedByPlayer() > 0 then
			for pCity in pPlayer:Cities() do
				if pCity:IsHasBuilding(iSharia) then
					local iNumHeretics = GetNumberHeretics(pCity, pPlayer)
				    [B]if iNumHeretics = 0 then[/B]
					pCity:SetNumRealBuilding(iUnity)
					end
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(ShariaUnity)

The Lua log is giving me this syntax error on the line in bold: Lua/Functions.lua:47: 'then' expected near '=' even though there's a "then" there.
 
Top Bottom