Set Religions from Game Start???

Formulapower

Warlord
Joined
Nov 5, 2007
Messages
148
I am new to Lua and I need some help getting specific civs to start with a specific religion for my medieval mod. Does anyone have some code I can look at to figure this our...like I said lua is not what I do so I need as much help as possible.

Here is how far I have gotten but I can't get it to work in the game

Spoiler :
function SetupReligions()

local ePlayer;
local eReligion;
local eBelief1;
local eBelief2;
local eBelief3;
local eBelief4;
local eBelief5;
local capital;

local iCrusadePlayer;

local pCrusadePlot;


-- First pass to set religions
for iPlayer = 4, do
local pPlayer = Players[iPlayer];
if (pPlayer:IsAlive()) then
local civType = pPlayer:GetCivilizationType();
capital = pPlayer:GetCapitalCity();
if (capital ~= nil) then
if (civType == GameInfo.Civilizations["CIVILIZATION_EGYPT"].ID) then
eReligion = GameInfoTypes["RELIGION_CHRISTIANITY"];
eBelief1 = GameInfoTypes["BELIEF_PAPAL_PRIMACY"];
eBelief2 = GameInfoTypes["BELIEF_HOLY_WARRIORS"];
eBelief3 = GameInfoTypes["BELIEF_CATHEDRALS"];
eBelief4 = GameInfoTypes["BELIEF_INDULGENCES"];
eBelief5 = GameInfoTypes["BELIEF_HOLY_ORDER"];
Game.FoundPantheon(iPlayer, eBelief1);
Game.FoundReligion(iPlayer, eReligion, nil, eBelief2, eBelief3, -1, -1, capital);
Game.EnhanceReligion(iPlayer, eReligion, eBelief4, eBelief5);
iCrusadePlayer = iPlayer;
pCrusadePlot = capital:plot();
end
end
end
end
end
 
Enable logging and check your log files, as this line is garbage

Code:
for iPlayer = 4, do

Edit: Also iCrusadePlayer and pCrusadePlot are redundant as they are declared as local scope within the SetupReligions() function but never used
 
I may be lacking in knowledge of code, but where it says:

eBelief1 = GameInfoTypes["BELIEF_PAPAL_PRIMACY"];

and later,

Game.FoundPantheon(iPlayer, eBelief1);

Should not the belief in question be a pantheon belief...? It's a founder belief unless Into the Renaissance altered that.

I know you are following the code in Into the Renaissance, but perhaps they updated something in the xml files that changed some of the beliefs. I know they added a religion, for example, Orthodoxy... and perhaps they changed the beliefs as well.
 
Try the following, it's untested so I may have a syntax error or two in there

Code:
local pCrusadePlot = FoundChristianity():Plot()

-- Find the Egyptian player and found Christianity in their capital, returning the city
function FoundChristianity()
  for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsAlive()) then
      if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_EGYPT) then
        local pCity = pPlayer:GetCapitalCity()
        CreateHolyCity(pCity, "RELIGION_CHRISTIANITY", "BELIEF_PAPAL_PRIMACY",
                              "BELIEF_HOLY_WARRIORS", "BELIEF_CATHEDRALS",
                              "BELIEF_INDULGENCES", "BELIEF_HOLY_ORDER")

        return pCity
      end
    end
  end
end

function CreateHolyCity(pCity, religion, pantheonBelief, founderBelief, followerBelief, followerBelief2, enhancerBelief)
  local iPlayer = pCity:GetOwner()
  local iReligion = GameInfoTypes[religion]

  -- Optional extra beliefs
  local iBelief4 = followerBelief2 and GameInfoTypes[followerBelief2] or -1
  local iBelief5 = enhancerBelief and GameInfoTypes[enhancerBelief] or -1

  Game.FoundPantheon(iPlayer, GameInfoTypes[pantheonBelief])
  Game.FoundReligion(iPlayer, iReligion, nil, GameInfoTypes[founderBelief], GameInfoTypes[followerBelief], iBelief4, iBelief5, pCity)
end
 
Should not the belief in question be a pantheon belief...?

It's merely symantic interpretation - the game just has beliefs, it doesn't (seem to) care which ones you use for what
 
This is the code I've been trying to use:

Code:
-- FoundReligion
-- Author: ebeach (modified by Craig Sutter)
--------------------------------------------------------------
function SetupReligions()

	local ePlayer;
	local eReligion;
	local eBelief1;
	local eBelief2;
	local eBelief3;
	local eBelief4;
	local eBelief5;
	local capital;

	local iSwedishPlayer;

	local pSwedishPlot;
	
	-- Find holy cities
	
   	-- First pass to set religions
	for iPlayer = 0, 16 do
		local pPlayer = Players[iPlayer];
		if (pPlayer:IsAlive()) then
			local civType = pPlayer:GetCivilizationType();
			capital = pPlayer:GetCapitalCity();
			if (capital ~= nil) then
				if (civType == GameInfo.Civilizations["CIVILIZATION_SWEDEN"].ID) then
					eReligion = GameInfoTypes["RELIGION_CHRISTIANITY"];
					eBelief1 = GameInfoTypes["BELIEF_PAPAL_PRIMACY"];
					eBelief2 = GameInfoTypes["BELIEF_HOLY_WARRIORS"];
					eBelief3 = GameInfoTypes["BELIEF_CATHEDRALS"];
					eBelief4 = GameInfoTypes["BELIEF_INDULGENCES"];
					eBelief5 = GameInfoTypes["BELIEF_HOLY_ORDER"];
					Game.FoundPantheon(iPlayer, eBelief1);
					Game.FoundReligion(iPlayer, eReligion, nil, eBelief2, eBelief3, -1, -1, capital);
					Game.EnhanceReligion(iPlayer, eReligion, eBelief4, eBelief5);
					iSwedenPlayer = iPlayer;
					pSwedenPlot = capital:Plot();
				end
			end
		end
	end
	
	-- Second pass to establish followers
	for iPlayer = 0, 16 do
		local pPlayer = Players[iPlayer];
		if (pPlayer:IsAlive()) then
			local civType = pPlayer:GetCivilizationType();
			capital = pPlayer:GetCapitalCity();
			if (capital ~= nil) then
		
				if (civType == GameInfo.Civilizations["CIVILIZATION_CELTS"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_ENGLAND"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_FRANCE"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_RUSSIA"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_ARABIA"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_OTTOMAN"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				elseif (civType == GameInfo.Civilizations["CIVILIZATION_SONGHAI"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CHRISTIANITY"]);
				end
			end
		end
	end

	-- And finally for city states
	-- Finally make sure everyone has contact with their holy city
	local byzantineTeamID = Players[iByzantinePlayer]:GetTeam();
	local vaticanTeamID = Players[iVaticanPlayer]:GetTeam();
	local meccaTeamID = Players[iMeccaPlayer]:GetTeam();
	local jerusalemTeamID = Players[iJerusalemPlayer]:GetTeam();
	for iPlayer = 0, 11, 1 do
		local pPlayer = Players[iPlayer];
		if (pPlayer:IsAlive()) then
			local civType = pPlayer:GetCivilizationType();
			local iTeam = pPlayer:GetTeam();
			local pTeam = Teams[iTeam];
			if (civType == GameInfo.Civilizations["CIVILIZATION_CELTS"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_ENGLAND"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_SPAIN"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_NETHERLANDS"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_AUSTRIA"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_SWEDEN"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_FRANCE"].ID) then
				pTeam:Meet(vaticanTeamID, true);
				RevealPlotAndAdjacent(pVaticanPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_RUSSIA"].ID) then
				pTeam:Meet(byzantineTeamID, true);
				RevealPlotAndAdjacent(pByzantinePlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_SONGHAI"].ID) then
				pTeam:Meet(meccaTeamID, true);
				RevealPlotAndAdjacent(pMeccaPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_ARABIA"].ID) then
				pTeam:Meet(meccaTeamID, true);
				RevealPlotAndAdjacent(pMeccaPlot, iTeam);
			elseif (civType == GameInfo.Civilizations["CIVILIZATION_OTTOMAN"].ID) then
				pTeam:Meet(meccaTeamID, true);
				RevealPlotAndAdjacent(pMeccaPlot, iTeam);
			end

			-- Always reveal Jerusalem
		end
	end
	
	-- Set which civs are Catholic
	SetPersistentProperty("CeltsCatholic", 1);
	SetPersistentProperty("EnglandCatholic", 1);
	SetPersistentProperty("FranceCatholic", 1);
	SetPersistentProperty("SwedenCatholic", 1);
end

The error log shows the following error... which I've gotten numerous times. Don't know what it means, though.

Spoiler :

[29108.086] ChoosePantheonPopup: -120
[29108.086] ChoosePantheonPopup: 963
[29108.086] ChoosePantheonPopup: 843
[29108.210] Runtime Error: [string "Assets\DLC\Expansion\UI\InGame\InGame.lua"]:1169: attempt to index local 'addinFile' (a nil value)
stack traceback:
[string "Assets\DLC\Expansion\UI\InGame\InGame.lua"]:1169: in main chunk
[C]: ?
[29108.210] Runtime Error: Error loading Assets\DLC\Expansion\UI\InGame\InGame.lua.


I'm going to continue to work on various iterations.

By the way: I've set it up as LUA\Religions.lua as an InGameUIAddin in the project properties page.

Also, it shows up in the modinfo file...

<EntryPoints>
<EntryPoint type="InGameUIAddin" file="LUA\Religions.lua">
<Name>Religion</Name>
<Description>Religion</Description>
</EntryPoint>
</EntryPoints>
 
Still unable to get this to work... same error as previous post as indicated by Lualog... no idea what is wrong.

Used this code in my last attempt:

Code:
local pCrusadePlot = FoundChristianity():Plot()

-- Find the Swedusg player and found Christianity in their capital, returning the city
function FoundChristianity()
  for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsAlive()) then
      if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SWEDEN) then
        local pCity = pPlayer:GetCapitalCity()
        CreateHolyCity(pCity, "RELIGION_CHRISTIANITY", "BELIEF_PAPAL_PRIMACY",
                              "BELIEF_HOLY_WARRIORS", "BELIEF_CATHEDRALS",
                              "BELIEF_INDULGENCES", "BELIEF_HOLY_ORDER")

        return pCity
      end
    end
  end
end

function CreateHolyCity(pCity, religion, pantheonBelief, founderBelief, followerBelief, followerBelief2, enhancerBelief)
  local iPlayer = pCity:GetOwner()
  local iReligion = GameInfoTypes[religion]

  -- Optional extra beliefs
  local iBelief4 = followerBelief2 and GameInfoTypes[followerBelief2] or -1
  local iBelief5 = enhancerBelief and GameInfoTypes[enhancerBelief] or -1

  Game.FoundPantheon(iPlayer, GameInfoTypes[pantheonBelief])
  Game.FoundReligion(iPlayer, iReligion, nil, GameInfoTypes[founderBelief], GameInfoTypes[followerBelief], iBelief4, iBelief5, pCity)
end

I wonder if it is not finding the capital city for some reason? I'm not certain how it is flagged on the map... it has the palace, so I'd think that would be sufficient, but is there another flag it is looking for... some sort of make capital entry I should do in the worldbuilder?

Next, I'm going to add the map as an addin to see if that changes things.

By the way, I am running no other mods that use an lua file.
 
Start a game, load the map, fire up LiveTuner and make sure you can see the capital with

Players[{ID_OF_SWEDEN}]:GetCapitalCity():GetName()
 
Zip the mod and attach it, it'll be quicker to look at the actual mod than second guess
 
The art file is too large to let me upload an attachment here.

So this is uploaded to mediafire:

HTML:
http://www.mediafire.com/?t2d2d6fwqirvth8

Keep in mind it is a work in progress... the city states are not complete nor allocated (Sweden is a placeholder for them at the moment) and neither units nor buildings (barring palaces) have been allocated. Civilpedia entries are not complete and all UUs are not yet allocated.

I updated current civilizations to create the civs (due to problems using newly created civs on my map).

Thank-you in advance.
 
It's all in the logs ;)

Code:
[436.350] Runtime Error: [string "Assets\DLC\Expansion\UI\InGame\InGame.lua"]:1169: attempt to index local 'addinFile' (a nil value)
stack traceback:
	[string "Assets\DLC\Expansion\UI\InGame\InGame.lua"]:1169: in main chunk
	[C]: ?
[436.350] Runtime Error: Error loading Assets\DLC\Expansion\UI\InGame\InGame.lua.

Code:
    <EntryPoint type="InGameUIAddin" file="LUA[COLOR="Red"][B][SIZE="3"]/[/SIZE][/B][/COLOR]Religion.lua">
      <Name>Religion</Name>
      <Description>Allocates a religion</Description>
    </EntryPoint>

You'll also need to move

Code:
FoundChristianity()

to the end of the file, as it's not being called from another method
 
local pCrusadePlot = FoundChristianity():plot()

Seems unecessary as pCrusadePlot is never used in any function... Should I just delete it?

Part of that is what you need to move to the end of the file
 
So I am able to establish religions using the above code...

Now, I wish to establish followers of said religions in the capitals of some of the other civs... this is the code I'm using.

Code:
function ConfucianismFollowers()

	--Establish followers of Confucianism
	local iReligion = GameInfoTypes[religion]
	local iPlayer = pCity:GetOwner()

	city:AdoptReligionFully(iReligion)
	
	for iPlayer = 0, 1 do
		local pPlayer = Players[iPlayer];
		if (pPlayer:IsAlive()) then
			if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_DENMARK) then
			local pCity = pPlayer:GetCapitalCity()
				 pCity:AdoptReligionFully("RELIGION_CONFUCIANISM")
				return pCity
			end
		end
	end		
end

Now, I am getting no error messages in my log files, however, I suspect I'm somehow getting a null value. Any advice on what I am doing wrong?

Keep in mind I'm new at this... I've tried many variants of above, and I think this one is my best attempt... but still no success. I've looked to the medieval scenario and the successful coding done previously in this thread for my inspiration, however, I've failed.

Help appreciated.
 
Top Bottom