Attempt to index a nil value

Rob (R8XFT)

Ancient Briton
Retired Moderator
Joined
Aug 11, 2002
Messages
10,871
Location
Leeds (UK)
Code:
local Decisions_SacrificeTheMightiest = {}
	Decisions_SacrificeTheMightiest.Name = "TXT_KEY_DECISIONS_MASSAGETAE_SACRIFICE_THE_MIGHTIEST"
	Decisions_SacrificeTheMightiest.Desc = "TXT_KEY_DECISIONS_MASSAGETAE_SACRIFICE_THE_MIGHTIEST_DESC"
	HookDecisionCivilizationIcon(Decisions_SacrificeTheMightiest, "CIVILIZATION_MASSAGETAE")
	Decisions_SacrificeTheMightiest.CanFunc = (
	function(pPlayer)
		if (pPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_MASSAGETAE"]) then return false, false end
			local era = load(pPlayer, "Decisions_SacrificeTheMightiest")
			local currentEra = pPlayer:GetCurrentEra()
			if era ~= nil then
				if era < currentEra then
					save(pPlayer, "Decisions_SacrificeTheMightiest", nil)
				else
					Decisions_SacrificeTheMightiest.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_MASSAGETAE_SACRIFICE_THE_MIGHTIEST_ENACTED")
					return false, false, true
				end
			end
			
			local unitLevel = 0
			local hasUnit = false
			[COLOR="Red"]local plot = pPlayer:GetCapitalCity():Plot()[/COLOR]
			for iVal = 0,(plot:GetNumUnits() - 1) do
				local unit = plot:GetUnit(iVal)
				if unit:GetUnitType() == GameInfoTypes["UNIT_GREAT_GENERAL"] then
					unitLevel = 5
					hasUnit = true
					break
				elseif unit and unit:GetUnitCombatType() == GameInfoTypes["UNITCOMBAT_MOUNTED"] then
					unitLevel = unit:GetLevel()
					if unitLevel > 5 then
						unitLevel = 5
					end
					hasUnit = true
					break
				end
			end

			local iFaith = pPlayer:GetFaithPerTurnFromCities() * unitLevel 
			local iCulture = pPlayer:GetJONSCulturePerTurnFromCities() * unitLevel
			Decisions_SacrificeTheMightiest.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_MASSAGETAE_SACRIFICE_THE_MIGHTIEST_DESC", iFaith, iCulture)

			if hasUnit == true then
				return true, true
			else
				return true, false
			end
	end
	)
	
	Decisions_SacrificeTheMightiest.DoFunc = (
	function(pPlayer)
		local unitLevel = 0
		local plot = pPlayer:GetCapitalCity():Plot()
		local killUnit
		for iVal = 0,(plot:GetNumUnits() - 1) do
			local unit = plot:GetUnit(iVal)
			if unit:GetUnitType() == GameInfoTypes["UNIT_GREAT_GENERAL"] then
				unitLevel = 5
				killUnit = unit
				break
			elseif unit and unit:GetUnitCombatType() == GameInfoTypes["UNITCOMBAT_MOUNTED"] then
				unitLevel = unit:GetLevel()
				if unitLevel > 5 then
					unitLevel = 5
				end
				killUnit = unit
				break
			end
			
		end

		local iFaith = pPlayer:GetFaithPerTurnFromCities() * unitLevel
		local iCulture = pPlayer:GetJONSCulturePerTurnFromCities() * unitLevel

		pPlayer:ChangeFaith(iFaith)
		pPlayer:ChangeJONSCulture(iCulture)

		for loopPlot in PlotAreaSweepIterator(plot, 1, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
			local otherUnit = loopPlot:GetUnit()
			if otherUnit then
				if unitLevel == 1 then
					otherUnit:ChangeExperience(5)
				elseif unitLevel == 2 then
					otherUnit:ChangeExperience(10)
				elseif unitLevel == 3 then
					otherUnit:ChangeExperience(15)
				elseif unitLevel == 4 then
					otherUnit:ChangeExperience(20)
				elseif unitLevel == 5 then
					otherUnit:ChangeExperience(25)
				end
			end
		end;
		killUnit:Kill(true)
		save(pPlayer, "Decisions_SacrificeTheMightiest", pPlayer:GetCurrentEra())
	end
	)
	
Decisions_AddCivilisationSpecific(GameInfoTypes["CIVILIZATION_MASSAGETAE"], "Decisions_SacrificeTheMightiest", Decisions_SacrificeTheMightiest)

The line I've highlighted in red is causing the error "attempt to index a nil value". I'm not sure how/why that is...could anyone please give me some assistance to resolve the issue?
 
Well pPlayer can't be nil (otherwise pPlayer:GetCivilizationType() higher up would have failed), so the player can't have a capital city (yet) , ie pPlayer:GetCapitalCity() is returning nil

Is it possible the code is triggering before a player founds their capital (eg if the initial settler wanders around for a bit first)
 
It was something I noticed when checking one of the other issues you know about and it was very early game. I'd built a capital city and had a roaming unit, but that was it. I would've thought that the code would've been initiated at the start of the game. I've not amended it from the original author's files actually, so it's probably okay as I don't think they've had any issues reported.

Thanks for the help.
 
On your first line where the function begins after you checked for civilization type do if pPlayer:GetCapitalCity() then
 
Thank-you!! I thought I could apply the same thing to another piece of lua with a similar issue, but it didn't work. It's the highlighted line that gets the message "Hyksos/Code/Functions.lua:42: attempt to index local 'capital' (a nil value)"

Any suggestions?

Code:
function CultureAndScienceFromResistance(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_TCM_HYKSOS"] then
		local resistance = 0
		for city in player:Cities() do
			resistance = math.ceil((city:GetResistanceTurns() * 0.8) + resistance)
		end
		local capital = player:GetCapitalCity()
		[COLOR="Red"]capital:SetNumRealBuilding(GameInfoTypes["BUILDING_TCM_DUMMY_HYKSOS_SCIENCE_AND_CULTURE"], resistance)[/COLOR]
	end
end
GameEvents.PlayerDoTurn.Add(CultureAndScienceFromResistance)
 
Thank-you!! I thought I could apply the same thing to another piece of lua with a similar issue, but it didn't work. It's the highlighted line that gets the message "Hyksos/Code/Functions.lua:42: attempt to index local 'capital' (a nil value)"

Any suggestions?

Code:
function CultureAndScienceFromResistance(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_TCM_HYKSOS"] then
		local resistance = 0
		for city in player:Cities() do
			resistance = math.ceil((city:GetResistanceTurns() * 0.8) + resistance)
		end
		local capital = player:GetCapitalCity()
		[COLOR="Red"]capital:SetNumRealBuilding(GameInfoTypes["BUILDING_TCM_DUMMY_HYKSOS_SCIENCE_AND_CULTURE"], resistance)[/COLOR]
	end
end
GameEvents.PlayerDoTurn.Add(CultureAndScienceFromResistance)

looks like the same issue as before. If a player moves their settler on the 1st turn, or for some otter reason does not have a capital city, you will get the error you are getting.

To fix this issue, alter to:
Code:
function CultureAndScienceFromResistance(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_TCM_HYKSOS"] then
		local capital = player:GetCapitalCity()
		if capital ~= nil then
			local resistance = 0
			for city in player:Cities() do
				resistance = math.ceil((city:GetResistanceTurns() * 0.8) + resistance)
			end
			capital:SetNumRealBuilding(GameInfoTypes["BUILDING_TCM_DUMMY_HYKSOS_SCIENCE_AND_CULTURE"], resistance)
		end
	end
end
GameEvents.PlayerDoTurn.Add(CultureAndScienceFromResistance)
You can also do it this way
Code:
function CultureAndScienceFromResistance(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_TCM_HYKSOS"] then
		local capital = player:GetCapitalCity()
		if capital then
			local resistance = 0
			for city in player:Cities() do
				resistance = math.ceil((city:GetResistanceTurns() * 0.8) + resistance)
			end
			capital:SetNumRealBuilding(GameInfoTypes["BUILDING_TCM_DUMMY_HYKSOS_SCIENCE_AND_CULTURE"], resistance)
		end
	end
end
GameEvents.PlayerDoTurn.Add(CultureAndScienceFromResistance)
I also re-arranged a little because if there is no capital city for a player there is no reason to run through the part of code where it is looping through all the player's cities in order to find out how much stuff to add to a city that does not exist. I realize you got this from "TCM", but we may as well make the code not bother to do the looping and stuff if we cannot use that data at the moment.
 
My next issue of a similar ilk is with the Champa. Again, I'd appreciate help please as I'm a real novice with lua. With respect to the red line in the code below, I'm getting the error, "attempt to index local 'pcCity' (a nil value)".

Code:
function(iPlayer)
	local pPlayer = Players[iPlayer];
	local pTeam = pPlayer:GetTeam();
	if (pPlayer:IsAlive()) then

		if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
		
			-- Other Notifications
			NotChampaGA(pPlayer, iPlayer)

		elseif (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
			
			local pcCity = pPlayer:GetCapitalCity();
			[COLOR="Red"]if pcCity:IsHasBuilding(bPlusGoldenAgeDummy) then[/COLOR]
				pcCity:SetNumRealBuilding(bPlusGoldenAgeDummy, 0);
			end
			if pcCity:IsHasBuilding(bPlusBlockGoldDummy) then
				pcCity:SetNumRealBuilding(bPlusBlockGoldDummy, 0);
			end
 
My next issue of a similar ilk is with the Champa. Again, I'd appreciate help please as I'm a real novice with lua. With respect to the red line in the code below, I'm getting the error, "attempt to index local 'pcCity' (a nil value)".

Code:
function(iPlayer)
	local pPlayer = Players[iPlayer];
	local pTeam = pPlayer:GetTeam();
	if (pPlayer:IsAlive()) then

		if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
		
			-- Other Notifications
			NotChampaGA(pPlayer, iPlayer)

		elseif (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
			
			local pcCity = pPlayer:GetCapitalCity();
			[COLOR="Red"]if pcCity:IsHasBuilding(bPlusGoldenAgeDummy) then[/COLOR]
				pcCity:SetNumRealBuilding(bPlusGoldenAgeDummy, 0);
			end
			if pcCity:IsHasBuilding(bPlusBlockGoldDummy) then
				pcCity:SetNumRealBuilding(bPlusBlockGoldDummy, 0);
			end

Try that, adding a check to make sure pcCity isn't nil.

Code:
function(iPlayer)
	local pPlayer = Players[iPlayer];
	local pTeam = pPlayer:GetTeam();
	if (pPlayer:IsAlive()) then

		if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
		
			-- Other Notifications
			NotChampaGA(pPlayer, iPlayer)

		elseif (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CHAMPA_MOD) then
			
			local pcCity = pPlayer:GetCapitalCity();
			[COLOR="Red"]if pcCity then[/COLOR]
				if pcCity:IsHasBuilding(bPlusGoldenAgeDummy) then
					pcCity:SetNumRealBuilding(bPlusGoldenAgeDummy, 0);
				end
				if pcCity:IsHasBuilding(bPlusBlockGoldDummy) then
					pcCity:SetNumRealBuilding(bPlusBlockGoldDummy, 0);
				end
			[COLOR="Red"]end[/COLOR]
 
My next issue is with the code below. It gives the lua error "attempt to index local 'oPlot' (a number value)" several times for the line highlighted in red. Again, any help would be really appreciated :).

Code:
-- Capitals
local uSettler = GameInfoTypes.UNIT_SETTLER;

GameEvents.PlayerCityFounded.Add(
function(iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer];
	local pPlot = Map.GetPlot(iCityX, iCityY);
	local pCity = pPlot:GetPlotCity();
	if (pPlayer:IsAlive()) then
		if pCity:IsOriginalCapital() then
			for oPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
				local oPlayer = Players[oPlayer];
				if (oPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_HARAPPA_MOD"]) then
					local oTeam = oPlayer:GetTeam();

					local oPlot = 0;
					if (oPlayer:GetNumCities() < 1) then
						for oUnit in oPlayer:Units() do
							if (oUnit:GetUnitType() == uSettler) then
								oPlot = oUnit:GetPlot();
								break
							end
						end
					elseif (oPlayer:GetNumCities() >= 1) then
						local ocCity = oPlayer:GetCapitalCity();
						oPlot = ocCity:Plot();
					end

					[COLOR="Red"]iDistance = Map.PlotDistance(pPlot:GetX(), pPlot:GetY(), oPlot:GetX(), oPlot:GetY());[/COLOR]					if iDistance <= 25 then
						for loop, direction in ipairs(directions) do
							local adjPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), direction);
							pPlot:SetRevealed(oTeam, true);
							adjPlot:SetRevealed(oTeam, true);
						end
					end

				end
			end
		end
	end
end)
 
Try:
Code:
-- Capitals
local uSettler = GameInfoTypes.UNIT_SETTLER;

GameEvents.PlayerCityFounded.Add(
function(iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer];
	local pPlot = Map.GetPlot(iCityX, iCityY);
	local pCity = pPlot:GetPlotCity();
	if (pPlayer:IsAlive()) then
		if pCity:IsOriginalCapital() then
			for oPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
				local oPlayer = Players[oPlayer];
				if oPlayer:IsEverAlive() and oPlayer:IsAlive() and (oPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_HARAPPA_MOD"]) then
					local oTeam = oPlayer:GetTeam();

					local oPlot = -1;
					if (oPlayer:GetNumCities() < 1) then
						for oUnit in oPlayer:Units() do
							if (oUnit:GetUnitType() == uSettler) then
								oPlot = oUnit:GetPlot();
								break
							end
						end
					elseif (oPlayer:GetNumCities() >= 1) then
						local ocCity = oPlayer:GetCapitalCity();
						oPlot = ocCity:Plot();
					end

					if oPlot ~= -1 then
						if Map.PlotDistance(iCityX, iCityY, oPlot:GetX(), oPlot:GetY()) <= 25 then
							pPlot:SetRevealed(oTeam, true);
							for loop, direction in ipairs(directions) do
								local adjPlot = Map.PlotDirection(iCityX, iCityY, direction);
								if adjPlot then
									adjPlot:SetRevealed(oTeam, true);
								end
							end
						end
					end
				end
			end
		end
	end
end)
The problem is that if CIVILIZATION_HARAPPA_MOD is not alive you would get the condiiton you have. If you run through all the major civs, as the loop here is doing
Code:
for oPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
without doing some kind of filter for whether the player is either currently alive or was ever alive (ie, ever part of the current game) you will get processing for civs that aren't even part of the current game. And for Anno Domini where you may be testing with less than the usual fourty-odd civs you can very well get one of the civs listed in the database randomly grabbed to fill all the slots not actually being "used" by the current game when an lua loop like the one noted is conducted. And since a player that is not alive can niether have cities or units, the variable valled oPlot was remaining as '0', and then "indexing" methods were attempted on an integer value, which in lua cannot by definition be "indexed".

I added a couple extra suspenders and belts "insurance-policy" sorts of checks to the code.
 
Two new issues have come to light, this time with my "East of Rome" pack.

The first gives the error "attempt to index a nil value" with the line highlighted in red below:

Code:
local buildingDefensePenaltyID = GameInfoTypes["BUILDING_JFD_NEGATIVE_DEFENSE"]

function JFD_ReligiousResistance(playerID)
	local player = Players[playerID]
	if (player ~= bulanPlayer and (not player:IsBarbarian())) then
		local religionID = bulanPlayer:GetReligionCreatedByPlayer() 
		[COLOR="Red"]if religionID == -1 then religionID = bulanPlayer:GetCapitalCity():GetReligiousMajority() end[/COLOR]		if isUsingPietyPrestige then religionID = JFD_GetStateReligion(bulanPlayer:GetID()) end
		
		if religionID then
			for city in player:Cities() do
				if Teams[player:GetTeam()]:IsAtWar(bulanPlayer:GetTeam()) then
					if city:GetNumFollowers(khazarReligionID) > 0 then
						city:SetNumRealBuilding(buildingDefensePenaltyID, city:GetNumFollowers(khazarReligionID))
					else
						if city:IsHasBuilding(buildingDefensePenaltyID) then
							city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
						end
					end
				else
					if city:IsHasBuilding(buildingDefensePenaltyID) then
						city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
					end
				end
			end	
		end			
	end
end

Incidentally, in case you need the defines for the code above, they're set as:
Code:
------------------------------------------------------------------------------------------------------------------------
-- JFD_GetKhazars
------------------------------------------------------------------------------------------------------------------------
local bulan = nil

function JFD_GetBulan()
	if bulan == nil then	
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
			local player = Players[iPlayer]			
			if player ~= nil and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"] then
				bulan = player
				break
			end
		end
	end
	
	return bulan
end
--=======================================================================================================================
-- CORE FUNCTIONS	
--=======================================================================================================================
-- Globals
-------------------------------------------------------------------------------------------------------------------------
local bulanPlayer			= JFD_GetBulan()
local civilisationID		= GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"]
local isKhazariaCivActive	= JFD_IsCivilisationActive(civilisationID)
local isUsingPietyPrestige	= JFD_IsUsingPietyPrestige()
local mathFloor				= math.floor


The second issue is with the code below, which gives the error "attempt to index local 'pcCity' (a nil value)" with the line highlighted in red:

Code:
-- Veche
local bVeche = GameInfoTypes.BUILDING_KIEVAN_RUS_MOD;
local bVecheCount = GameInfoTypes.BUILDING_KIEVAN_RUS_TRAIT_DUMMY_BUILDING;
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	local pPlayer = Players[iPlayer];
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_KIEVAN_RUS_MOD"]) then
			local pcCity = pPlayer:GetCapitalCity();
			local Maintenance = 0;
			for sCity in pPlayer:Cities() do
				if (sCity:IsHasBuilding(bVecheCount)) then
					sCity:SetNumRealBuilding(bVecheCount, 0);
				end
				if (sCity:IsHasBuilding(bVeche)) then
					local BuildingCost = sCity:GetTotalBaseBuildingMaintenance();
					Maintenance = (Maintenance + BuildingCost)
				end
			end
			local Discount = math.floor(Maintenance / 6)
			pPlayer:ChangeGold(Discount);
			[COLOR="red"]pcCity:SetNumRealBuilding(bVecheCount, Discount);[/COLOR]
		end
	end
end)

Again, I'd be most appreciative of any help :).
 
would need the whole text of the file where the "bulanplayer" error is occuring to confirm when or when not that code fires.

--------------------------------------------------

The problem with the last one is pretty much the same problem as most of the others:
Code:
local pcCity = pPlayer:GetCapitalCity();
....snips.........
pcCity:SetNumRealBuilding(bVecheCount, Discount);
So if there is no capital city yet for the player, variable pcCity is "nil", and causes the error.

This should fix the issue since if the player has no capital it is safe to assume they have no cities so there's no real point to executing the rest of the code:
Code:
-- Veche
local bVeche = GameInfoTypes.BUILDING_KIEVAN_RUS_MOD;
local bVecheCount = GameInfoTypes.BUILDING_KIEVAN_RUS_TRAIT_DUMMY_BUILDING;
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	local pPlayer = Players[iPlayer];
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_KIEVAN_RUS_MOD"]) then
			local pcCity = pPlayer:GetCapitalCity();
			if pcCity ~= nil then
				local Maintenance = 0;
				for sCity in pPlayer:Cities() do
					if (sCity:IsHasBuilding(bVecheCount)) then
						sCity:SetNumRealBuilding(bVecheCount, 0);
					end
					if (sCity:IsHasBuilding(bVeche)) then
						local BuildingCost = sCity:GetTotalBaseBuildingMaintenance();
						Maintenance = (Maintenance + BuildingCost)
					end
				end
				local Discount = math.floor(Maintenance / 6)
				pPlayer:ChangeGold(Discount);
				pcCity:SetNumRealBuilding(bVecheCount, Discount);
			end
		end
	end
end)
 
Thanks Lee! Here's the full code for the Khazar issue:

Code:
-- JFD_KhazariaFunctions
-- Author: JFD
-- DateCreated: 6/23/2014 2:36:23 PM
--=======================================================================================================================
-- UTILITY FUNCTIONS	
--=======================================================================================================================
-- JFD_IsCivilisationActive
------------------------------------------------------------------------------------------------------------------------
function JFD_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

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

	return isUsingPiety
end
------------------------------------------------------------------------------------------------------------------------
-- JFD_GetKhazars
------------------------------------------------------------------------------------------------------------------------
local bulan = nil

function JFD_GetBulan()
	if bulan == nil then	
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
			local player = Players[iPlayer]			
			if player ~= nil and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"] then
				bulan = player
				break
			end
		end
	end
	
	return bulan
end
--=======================================================================================================================
-- CORE FUNCTIONS	
--=======================================================================================================================
-- Globals
-------------------------------------------------------------------------------------------------------------------------
local bulanPlayer			= JFD_GetBulan()
local civilisationID		= GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"]
local isKhazariaCivActive	= JFD_IsCivilisationActive(civilisationID)
local isUsingPietyPrestige	= JFD_IsUsingPietyPrestige()
local mathFloor				= math.floor

if isKhazariaCivActive then
	print("Khagan Bek Bulan is in this game")
end

if isUsingPietyPrestige then
	include("PietyUtils.lua")
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_KhazarianDisporia
--------------------------------------------------------------------------------------------------------------------------
function JFD_InitiateDiaspora(playerID, oldPlayerID, city, religionID)
	local player = Players[playerID]
	local numCities = player:GetNumCities()
	local numImmigrants = city:GetNumFollowers(religionID)
	local foodChange = mathFloor(15 + 6 * (numImmigrants - 1) + ((numImmigrants - 1) * 1.8))
	foodChange = mathFloor(foodChange * 33/ 100)
	player:GetCapitalCity():ChangeFood(foodChange)
	
	if player:IsHuman() then
		local religionName = Game.GetReligionName(religionID)
		local description = Locale.ConvertTextKey("TXT_KEY_JFD_DIASPORA_DESC_NOTIFICATION", religionName, city:GetName(), foodChange)
		local shortDescription = Locale.ConvertTextKey("TXT_KEY_JFD_DIASPORA_SHORT_DESC_NOTIFICATION", religionName, Players[oldPlayerID]:GetCivilizationDescription())
		player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, description, shortDescription)
	end
end

function JFD_KhazarianImmigration(playerID, isCapital, cityX, cityY, newPlayerID)
	local player = Players[newPlayerID]
	local oldPlayer = Players[playerID]
	local city = Map.GetPlot(cityX, cityY):GetPlotCity()
	
	for otherPlayerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do	
		local khazarPlayer = Players[otherPlayerID]
		if khazarPlayer:GetCivilizationType() == civilisationID then
			local religionID = khazarPlayer:GetReligionCreatedByPlayer() or khazarPlayer:GetCapitalCity():GetReligiousMajority()
			if isUsingPietyPrestige then religionID = JFD_GetStateReligion(otherPlayerID) end
			
			if religionID then
				if city:GetNumFollowers(religionID) > 0 then
					JFD_InitiateDiaspora(iPlayer, playerID, city, religionID)
				end
			end
		end
	end
end

if isKhazariaCivActive then
	GameEvents.CityCaptureComplete.Add(JFD_KhazarianImmigration)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_ReligiousResistance
--------------------------------------------------------------------------------------------------------------------------
local buildingDefensePenaltyID = GameInfoTypes["BUILDING_JFD_NEGATIVE_DEFENSE"]

function JFD_ReligiousResistance(playerID)
	local player = Players[playerID]
	if (player ~= bulanPlayer and (not player:IsBarbarian())) then
		local religionID = bulanPlayer:GetReligionCreatedByPlayer() 
		[COLOR="Red"]if religionID == -1 then religionID = bulanPlayer:GetCapitalCity():GetReligiousMajority() end[/COLOR]
		if isUsingPietyPrestige then religionID = JFD_GetStateReligion(bulanPlayer:GetID()) end
		
		if religionID then
			for city in player:Cities() do
				if Teams[player:GetTeam()]:IsAtWar(bulanPlayer:GetTeam()) then
					if city:GetNumFollowers(khazarReligionID) > 0 then
						city:SetNumRealBuilding(buildingDefensePenaltyID, city:GetNumFollowers(khazarReligionID))
					else
						if city:IsHasBuilding(buildingDefensePenaltyID) then
							city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
						end
					end
				else
					if city:IsHasBuilding(buildingDefensePenaltyID) then
						city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
					end
				end
			end	
		end			
	end
end	

if isKhazariaCivActive then
	GameEvents.PlayerDoTurn.Add(JFD_ReligiousResistance)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_Shul
--------------------------------------------------------------------------------------------------------------------------
local buildingShulID		= GameInfoTypes["BUILDING_JFD_SHUL"]
local buildingShulGoldID	= GameInfoTypes["BUILDING_JFD_SHUL_GOLD"]

function JFD_Shul(playerID)
	local player = Players[playerID]
	 if (player:IsAlive() and player:GetCivilizationType() == civilisationID) then 
		for city in player:Cities() do
			if city:IsHasBuilding(buildingShulID) then
				local numFollowers = mathFloor(city:GetNumFollowers(JFD_GetKhazarReligion()) * 50 /100)
				city:SetNumRealBuilding(buildingShulGoldID, numFollowers)
			else
				if city:IsHasBuilding(buildingShulGoldID) then
					city:SetNumRealBuilding(buildingShulGoldID, 0)
				end
			end
		end
	end
end

if isKhazariaCivActive then
	GameEvents.PlayerDoTurn.Add(JFD_Shul)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_KhaganBek
--------------------------------------------------------------------------------------------------------------------------
local unitPromotionKhaganBekID = GameInfoTypes["PROMOTION_JFD_KHAGAN_BEK"]

function JFD_KhaganBek(playerID)
	local player = Players[playerID]
	local religionID = player:GetReligionCreatedByPlayer() or player:GetCapitalCity():GetReligiousMajority()
	if isUsingPietyPrestige then religionID = JFD_GetStateReligion(playerID) end
		
	if religionID then
		for unit in player:Units() do
			if unit:IsHasPromotion(unitPromotionKhaganBekID) then
				local unitX = unit:GetX()
				local unitY = unit:GetY()
				for otherPlayerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do
					local otherPlayer = Players[otherPlayerID]
					if (otherPlayer:IsAlive() and otherPlayerID ~= playerID) then
						local otherPlayerTeam = Teams[otherPlayer:GetTeam()]
						if otherPlayerTeam:IsAtWar(player:GetTeam()) then
							for city in otherPlayer:Cities() do
								local convertPercent = 0
								local cityX = city:GetX()
								local cityY = city:GetY()
								if Map.PlotDistance(unitX, unitY, cityX, cityY) < 2 then
									convertPercent = 30
								elseif Map.PlotDistance(unitX, unitY, cityX, cityY) < 3 then
									convertPercent = 20
								end
								
								if convertPercent > 0 then
									for religion in GameInfo.Religions() do
										if city:IsReligionInCity(religion.ID) then
											city:ConvertPercentFollowers(religionID, religion.ID, 100) 
										end
									end
									city:ConvertPercentFollowers(religionID, -1, convertPercent)
								end
							end
						end
					end
				end
			end
		end		
	end
end
GameEvents.PlayerDoTurn.Add(JFD_KhaganBek)
----------------------------------------------------------------------------------------------------------------------------
-- JFD_BekMountedXP
----------------------------------------------------------------------------------------------------------------------------	
local buildingKhaganBekXPID = GameInfoTypes["BUILDING_JFD_BEK_MOUNTED_XP"]

function JFD_BekMountedXP(playerID)
	local player = Players[playerID]
	if player:IsAlive() then
		for city in player:Cities() do
			local bekIsHere = false
			local plot = city:Plot()
			for i = 0, plot:GetNumUnits() - 1, 1 do
				if plot then
					if plot:GetUnit(i):IsHasPromotion(unitPromotionKhaganBekID) then
						bekIsHere = true
					end
				end
			end
					
			if bekIsHere then
				if (not city:IsHasBuilding(buildingKhaganBekXPID)) then
					city:SetNumRealBuilding(buildingKhaganBekXPID, 1)
				end
			else
				if city:IsHasBuilding(buildingKhaganBekXPID) then
					city:SetNumRealBuilding(buildingKhaganBekXPID, 0)
				end
			end
		end
	end
end
GameEvents.UnitSetXY.Add(JFD_BekMountedXP)
GameEvents.PlayerDoTurn.Add(JFD_BekMountedXP)
--==========================================================================================================================
--==========================================================================================================================

In addition, I've now got an error of a similar ilk, but not quite the same, with my Dark Ages pack (only one more pack to check after this, so should be about the last one of these - I really do appreciate the help!)

The error with the highlighted line is "attempt to perform arithmetic on global 'currentEra' (a nil value)"

Code:
local Decisions_MC_Wizengamot = {}
	Decisions_MC_Wizengamot.Name = "TXT_KEY_DECISIONS_MC_MERCIA_WIZENGAMOT"
	Decisions_MC_Wizengamot.Desc = "TXT_KEY_DECISIONS_MC_MERCIA_WIZENGAMOT_DESC"
	HookDecisionCivilizationIcon(Decisions_MC_Wizengamot, "CIVILIZATION_MC_MERCIA")
	Decisions_MC_Wizengamot.CanFunc = (
	function(pPlayer)
		if (pPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_MC_MERCIA"]) then return false, false end
		local era = load(pPlayer, "Decisions_MC_Wizengamot")
		local currentEra = pPlayer:GetCurrentEra()
		if era ~= nil then
			if era < currentEra then
				save(pPlayer, "Decisions_MC_Wizengamot", nil)
			else
				Decisions_MC_Wizengamot.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_MC_MERCIA_WIZENGAMOT_ENACTED")
				return false, false, true
			end
		end
		local iCost = math.ceil((currentEra + 1) * 100 * iMod)
 
		Decisions_MC_Wizengamot.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_MC_MERCIA_WIZENGAMOT_DESC", iCost)
 
		if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 1) then return true, false end
		if (pPlayer:GetGold() < iCost) then return true, false end
 
		return true, true
	end
	)
       
	Decisions_MC_Wizengamot.DoFunc = (
	function(pPlayer)
 
		local iCurrentEra = pPlayer:GetCurrentEra()
		[COLOR="Red"]local iCost = math.ceil((currentEra + 1) * 100 * iMod)[/COLOR]
		pPlayer:ChangeGold(-iCost)
	       
		pPlayer:ChangeNumResourceTotal(iMagistrate, -1)
 
		pPlayer:SetNumFreePolicies(1)
		pPlayer:SetNumFreePolicies(0)
		pPlayer:SetHasPolicy(GameInfoTypes["POLICY_MC_WIZENGAMOT"], true)
		save(pPlayer, "Decisions_MC_Wizengamot_Turns", 10)
		save(pPlayer, "Decisions_MC_Wizengamot", pPlayer:GetCurrentEra())
	end
	)

	Decisions_MC_Wizengamot.Monitors = {}
	Decisions_MC_Wizengamot.Monitors[GameEvents.PlayerDoTurn] =  (
	function(playerID)
		local pPlayer = Players[playerID]
		local iDecisions_MC_Wizengamot_Turns = load(pPlayer, "Decisions_MC_Wizengamot_Turns") or 0

		if iDecisions_MC_Wizengamot_Turns == 0 then
			pPlayer:SetHasPolicy(GameInfoTypes["POLICY_MC_WIZENGAMOT"], false)
		elseif iDecisions_MC_Wizengamot_Turns >= 0 then
			local numTurns = iDecisions_MC_Wizengamot_Turns - 1
			save(pPlayer, "Decisions_MC_Wizengamot_Turns", numTurns)
		end
	end
	)
       
Decisions_AddCivilisationSpecific(GameInfoTypes["CIVILIZATION_MC_MERCIA"], "Decisions_MC_Wizengamot", Decisions_MC_Wizengamot)
 
The last one is a simple typo - should it be iCurrentEra or currentEra (pick one and stick with it!)
 
The JFD_ReligiousResistance function has multiple problems.
  1. If the player has not founded a religion and the "bulan player" has not founded a capital city then you get the error you are getting from this line
    Code:
    if religionID == -1 then religionID = bulanPlayer:GetCapitalCity():GetReligiousMajority() end
    This is the root cause of the error you are getting from that function, which runs on player turn processing.
  2. This variable is not defined anywhere before being used, and therefore is "nil":
    Code:
    if city:GetNumFollowers([COLOR="Red"]khazarReligionID[/COLOR]) > 0 then
    	city:SetNumRealBuilding(buildingDefensePenaltyID, city:GetNumFollowers([COLOR="red"]khazarReligionID[/COLOR]))
    The second of the two lines will never execute.
  3. Do you have file PietyUtils.lua added to the mod and set as VFS=true ? If not, then the code will not be able to find certain functions that are being called for.
  4. City:GetReligiousMajority() returns -1 when a player has no religion in the city, so unless the function JFD_GetStateReligion returns "nil" when the specified player has no religion, this line will always be evaluated as "true":
    Code:
    if religionID then
    • "-1" is not evaluated as "false", nor "nil"
    • Any integer value for variable religionID will be evaluated as "true"
    • You can see how this sort of thing works by going to this website and running this code:
      Code:
      ThisThing = -1
      if ThisThing then
         print("ThisThing is true")
      else
         print("ThisThing is false")
      end
      and then changing to this​
      Code:
      ThisThing = nil
      if ThisThing then
         print("ThisThing is true")
      else
         print("ThisThing is false")
      end
      or this​
      Code:
      ThisThing = 57
      if ThisThing then
         print("ThisThing is true")
      else
         print("ThisThing is false")
      end
    This part of the code is always going to want to execute unless function JFD_GetStateReligion returns "nil" when the specified player has no religion:
    Code:
    for city in player:Cities() do
    	if Teams[player:GetTeam()]:IsAtWar(bulanPlayer:GetTeam()) then
    		if city:GetNumFollowers(khazarReligionID) > 0 then
    			city:SetNumRealBuilding(buildingDefensePenaltyID, city:GetNumFollowers(khazarReligionID))
    		else
    			if city:IsHasBuilding(buildingDefensePenaltyID) then
    				city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
    			end
    		end
    	else
    		if city:IsHasBuilding(buildingDefensePenaltyID) then
    			city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
    		end
    	end
    end
  5. There are similar issues in the other functions within the code.
If you would like me to try fixing the issues it would probably be better to attach the actual file and the PietyUtils.lua as they currently are in the Anno CivPack. Otherwise if you haven't made any changes to JFD's original code you might PM him as to what the original intent with some of the code was (ie, the khazarReligionID variable)
 
Again, thanks for the help, I really appreciate it :).

After reading your last post, I realised that the PietyUtils.lua (which was set to VFS=true) only kicks in if Piety & Prestige is being used - and it is checked against the actual Piety & Prestige mod. I'm using Piety, but as an element of Anno Domini, therefore, all the statements that were basically stating "let religionID = this, but if Piety & Prestige is active then let religionID = that" I've changed to read "let religionID = whatever it would be if Piety & Prestige were active".

I hope you understand what I mean!

There is, however a new error and perhaps one that a lua expert could easily sort out. It's saying for the highlighted line in my new code, '<eof>' expected near 'end'

If you're having difficulty finding the highlight - it's only the word "end" and it's at the end of the JFD_KhazarianDisporia section.

Any help would be very much appreciated - oh, I hope I've done the right thing with respect to my amendments!

Code:
-- JFD_KhazariaFunctions
-- Author: JFD
-- DateCreated: 6/23/2014 2:36:23 PM
--=======================================================================================================================
-- UTILITY FUNCTIONS	
--=======================================================================================================================
-- JFD_IsCivilisationActive
------------------------------------------------------------------------------------------------------------------------
function JFD_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

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

	return isUsingPiety
end
------------------------------------------------------------------------------------------------------------------------
-- JFD_GetKhazars
------------------------------------------------------------------------------------------------------------------------
local bulan = nil

function JFD_GetBulan()
	if bulan == nil then	
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
			local player = Players[iPlayer]			
			if player ~= nil and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"] then
				bulan = player
				break
			end
		end
	end
	
	return bulan
end
--=======================================================================================================================
-- CORE FUNCTIONS	
--=======================================================================================================================
-- Globals
-------------------------------------------------------------------------------------------------------------------------
local bulanPlayer			= JFD_GetBulan()
local civilisationID		= GameInfoTypes["CIVILIZATION_JFD_KHAZARIA"]
local isKhazariaCivActive	= JFD_IsCivilisationActive(civilisationID)
local isUsingPietyPrestige	= JFD_IsUsingPietyPrestige()
local mathFloor				= math.floor

if isKhazariaCivActive then
	print("Khagan Bek Bulan is in this game")
end


include("PietyUtils.lua");
--------------------------------------------------------------------------------------------------------------------------
-- JFD_KhazarianDisporia
--------------------------------------------------------------------------------------------------------------------------
function JFD_InitiateDiaspora(playerID, oldPlayerID, city, religionID)
	local player = Players[playerID]
	local numCities = player:GetNumCities()
	local numImmigrants = city:GetNumFollowers(religionID)
	local foodChange = mathFloor(15 + 6 * (numImmigrants - 1) + ((numImmigrants - 1) * 1.8))
	foodChange = mathFloor(foodChange * 33/ 100)
	player:GetCapitalCity():ChangeFood(foodChange)
	
	if player:IsHuman() then
		local religionName = Game.GetReligionName(religionID)
		local description = Locale.ConvertTextKey("TXT_KEY_JFD_DIASPORA_DESC_NOTIFICATION", religionName, city:GetName(), foodChange)
		local shortDescription = Locale.ConvertTextKey("TXT_KEY_JFD_DIASPORA_SHORT_DESC_NOTIFICATION", religionName, Players[oldPlayerID]:GetCivilizationDescription())
		player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, description, shortDescription)
	end
end

function JFD_KhazarianImmigration(playerID, isCapital, cityX, cityY, newPlayerID)
	local player = Players[newPlayerID]
	local oldPlayer = Players[playerID]
	local city = Map.GetPlot(cityX, cityY):GetPlotCity()
	
	for otherPlayerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do	
		local khazarPlayer = Players[otherPlayerID]
		if khazarPlayer:GetCivilizationType() == civilisationID then
			local religionID = JFD_GetStateReligion(otherPlayerID) end
			
			if religionID then
				if city:GetNumFollowers(religionID) > 0 then
					JFD_InitiateDiaspora(iPlayer, playerID, city, religionID)
				end
			end
		end
	end
[COLOR="Red"]end[/COLOR]

if isKhazariaCivActive then
	GameEvents.CityCaptureComplete.Add(JFD_KhazarianImmigration)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_ReligiousResistance
--------------------------------------------------------------------------------------------------------------------------
local buildingDefensePenaltyID = GameInfoTypes["BUILDING_JFD_NEGATIVE_DEFENSE"]

function JFD_ReligiousResistance(playerID)
	local player = Players[playerID]
	if (player ~= bulanPlayer and (not player:IsBarbarian())) then
		local religionID = bulanPlayer:GetReligionCreatedByPlayer() 
		if religionID == -1 then religionID = JFD_GetStateReligion(bulanPlayer:GetID()) end 
		
		if religionID then
			for city in player:Cities() do
				if Teams[player:GetTeam()]:IsAtWar(bulanPlayer:GetTeam()) then
					if city:GetNumFollowers(khazarReligionID) > 0 then
						city:SetNumRealBuilding(buildingDefensePenaltyID, city:GetNumFollowers(khazarReligionID))
					else
						if city:IsHasBuilding(buildingDefensePenaltyID) then
							city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
						end
					end
				else
					if city:IsHasBuilding(buildingDefensePenaltyID) then
						city:SetNumRealBuilding(buildingDefensePenaltyID, 0)
					end
				end
			end	
		end			
	end
end	

if isKhazariaCivActive then
	GameEvents.PlayerDoTurn.Add(JFD_ReligiousResistance)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_Shul
--------------------------------------------------------------------------------------------------------------------------
local buildingShulID		= GameInfoTypes["BUILDING_JFD_SHUL"]
local buildingShulGoldID	= GameInfoTypes["BUILDING_JFD_SHUL_GOLD"]

function JFD_Shul(playerID)
	local player = Players[playerID]
	 if (player:IsAlive() and player:GetCivilizationType() == civilisationID) then 
		for city in player:Cities() do
			if city:IsHasBuilding(buildingShulID) then
				local numFollowers = mathFloor(city:GetNumFollowers(JFD_GetKhazarReligion()) * 50 /100)
				city:SetNumRealBuilding(buildingShulGoldID, numFollowers)
			else
				if city:IsHasBuilding(buildingShulGoldID) then
					city:SetNumRealBuilding(buildingShulGoldID, 0)
				end
			end
		end
	end
end

if isKhazariaCivActive then
	GameEvents.PlayerDoTurn.Add(JFD_Shul)
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_KhaganBek
--------------------------------------------------------------------------------------------------------------------------
local unitPromotionKhaganBekID = GameInfoTypes["PROMOTION_JFD_KHAGAN_BEK"]

function JFD_KhaganBek(playerID)
	local player = Players[playerID]
	local religionID = JFD_GetStateReligion(playerID) end
		
	if religionID then
		for unit in player:Units() do
			if unit:IsHasPromotion(unitPromotionKhaganBekID) then
				local unitX = unit:GetX()
				local unitY = unit:GetY()
				for otherPlayerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do
					local otherPlayer = Players[otherPlayerID]
					if (otherPlayer:IsAlive() and otherPlayerID ~= playerID) then
						local otherPlayerTeam = Teams[otherPlayer:GetTeam()]
						if otherPlayerTeam:IsAtWar(player:GetTeam()) then
							for city in otherPlayer:Cities() do
								local convertPercent = 0
								local cityX = city:GetX()
								local cityY = city:GetY()
								if Map.PlotDistance(unitX, unitY, cityX, cityY) < 2 then
									convertPercent = 30
								elseif Map.PlotDistance(unitX, unitY, cityX, cityY) < 3 then
									convertPercent = 20
								end
								
								if convertPercent > 0 then
									for religion in GameInfo.Religions() do
										if city:IsReligionInCity(religion.ID) then
											city:ConvertPercentFollowers(religionID, religion.ID, 100) 
										end
									end
									city:ConvertPercentFollowers(religionID, -1, convertPercent)
								end
							end
						end
					end
				end
			end
		end		
	end
end
GameEvents.PlayerDoTurn.Add(JFD_KhaganBek)
----------------------------------------------------------------------------------------------------------------------------
-- JFD_BekMountedXP
----------------------------------------------------------------------------------------------------------------------------	
local buildingKhaganBekXPID = GameInfoTypes["BUILDING_JFD_BEK_MOUNTED_XP"]

function JFD_BekMountedXP(playerID)
	local player = Players[playerID]
	if player:IsAlive() then
		for city in player:Cities() do
			local bekIsHere = false
			local plot = city:Plot()
			for i = 0, plot:GetNumUnits() - 1, 1 do
				if plot then
					if plot:GetUnit(i):IsHasPromotion(unitPromotionKhaganBekID) then
						bekIsHere = true
					end
				end
			end
					
			if bekIsHere then
				if (not city:IsHasBuilding(buildingKhaganBekXPID)) then
					city:SetNumRealBuilding(buildingKhaganBekXPID, 1)
				end
			else
				if city:IsHasBuilding(buildingKhaganBekXPID) then
					city:SetNumRealBuilding(buildingKhaganBekXPID, 0)
				end
			end
		end
	end
end
GameEvents.UnitSetXY.Add(JFD_BekMountedXP)
GameEvents.PlayerDoTurn.Add(JFD_BekMountedXP)
--==========================================================================================================================
--==========================================================================================================================
 
Top Bottom