Set Religions from Game Start???

Well, religion, pCity and city are never declared, are they globals? It seems unlikely. Besides you need to check players against IsEverAlive() first or you can make the game crashes as soon as you use a player's functions. So my guess is that your function is never called.

Two advices:
* "print" is your friend. Add "print" statements in your code to see what is happening.
* Use Firetuner to get a live lua log, it's less cumbersome than the log files.
 
I've tested the following code in live tuner... it shows no errors. However, Denmark still doesn't get any followers in its capital.

This is part of a larger file that creates the religion... that part works.

Code:
function ConfucianismFollowers()
	for iPlayer = 0, 1 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_DENMARK"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				end
			end
		end
	end
end

Code:
-- Lua Script1
-- Author: Craig and Nancy
-- DateCreated: 7/16/2012 11:05:12 AM
--------------------------------------------------------------


-- Find the Swedish player and found Confucianism in their capital, returning the city

function CreateAsatruHolyCity(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

function FoundConfucianism()
  for iPlayer=0, 16 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsAlive()) then
      if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SWEDEN) then
        local pCity = pPlayer:GetCapitalCity()
        CreateAsatruHolyCity(pCity, "RELIGION_CONFUCIANISM", "BELIEF_SACRED_WATERS",
                              "BELIEF_CEREMONIAL_BURIAL", "BELIEF_ASCETISM")

        return pCity
      end
    end
  end
end

function ConfucianismFollowers()
	for iPlayer = 0, 1 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_DENMARK"].ID) then
					capital:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				end
			end
		end
	end
end

local pAsatruPlot = FoundConfucianism():Plot()

As I said, the first two functions in the code work... I am getting a holy city and the religion is created. Just the creation of followers is not working.

I put that function in livetuner and it has no errors.

Can't tell what I'm doing wrong. Denmark is civilization 1 in my scenario set up in worldbuilder. The numbering works as Sweden in the first functions is civ 16.

Don't know why the capital is not being called.
 
At a guess, Denmark is in a player slot that is not 0 or 1 (0 will always be a human player)

Do not use

Code:
for iPlayer = 0, 1 do

as that only checks the first two slots, or even

Code:
for iPlayer=0, 16 do

which only checks the first 17 player slots, but use

Code:
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do

instead, as that checks ALL possible player slots
 
Didn't realize that created a range rather than searching a specific slot. Thank you very much. I'll try it when I get home. I thought since Denmark was player 1 in my worldbuilder set up, that was the number it was checking. Of course, I suppose the greater range I unintentionally set up with the religion provided a greater chance I would luck into Sweden being a number within that range... I thought it worked because Sweden was number 16, but it could, I suppose, be any of the numbers in that range.

If I understand what you're saying correctly.

I noticed you had used that method in the code previously provided. It worked, but I made the mistake of trying to use the method in the Back to the Renaissance Scenario, which also worked (though apparently not as I thought).
 
If "0, GameDefines.MAX_MAJOR_CIVS-" processes all major civs, even if "0, GameDefines.MAX_MINOR_CIVS-1" is valid it would not only process the minor civs but also the major civs - you may want to read a Lua tutorial/reference on for loops

Don't guess at the numbers - 20 is a major civ, minors happens to start at 22 - use the GameDefines

If the last major civ is "GameDefines.MAX_MAJOR_CIVS-1" then the first minor must be GameDefines.MAX_MAJOR_CIVS

The last player is "GameDefines.MAX_PLAYERS-1" (which you can find out by searching the lua files that come with the game - get yourself a good multi-file search tool, like AgentRansack or Notepad++), but that happens to be the Barbarians

So the loop you want for minor civs is

for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_PLAYERS-2 do
 
I've been wondering about a problem similar to the original author's, myself: can the game set a specific civ's religion based on the era? (Call me a nitpicker who can't suspend her disbelief, but...it's harder to imagine a Viking raider as a churchgoing Lutheran, than it is to imagine Napoleon and Attila the Hun squaring off on the battlefield.) I'd have to add some ancient/classical alternatives to the official list, of course--but once the game accepts those, I'm looking for a rule that translates as:

If the current era is A and civilization B founds a religion, make it religion C. Otherwise, make it religion D.


Can a script be written to make the game work that way?
 
I've tested the following code in live tuner...
If you paste a function declaration in FireTuner, it declares the function, it does not invoke it.

@isnorden
I think a player cannot found a religion if it already founded one. So you need another player to found it, then you spread it.
 
I am at a phone right now but I have a working code for this... Check out the thread in the Sdk\lua section in creation and customization in the newb at modding thread...

I will post my code when I get home.

Sorry for the lack of specific directions to the thread but hard to cut and paste web pages on a phond...the thread would be near the top.
 
The following code will found a religion in a civ's capital.

Code:
-- Find the Swedish player and found Confucianism in their capital, returning the city

function CreateAsatruHolyCity(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

function FoundConfucianism()
  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()
        CreateAsatruHolyCity(pCity, "RELIGION_CONFUCIANISM", "BELIEF_SACRED_WATERS",
                              "BELIEF_CEREMONIAL_BURIAL", "BELIEF_ASCETISM")

        return pCity
      end
    end
  end
end

local pAsatruPlot = FoundConfucianism():Plot()

You can add two more enhancer beliefs (I only wanted to found the religion in my mod, not complete it).

You need to have a city in your scenario to use it of course.

This next bit will add a religion to cities on map...

Code:
-- Enumerate Playable Civ Cities with Confucianism

for iPlayer=0, GameDefines.MAX_CIV_PLAYERS - 1 do
	local pPlayer = Players[iPlayer];
		if pPlayer:IsEverAlive() then 

		print (pPlayer:GetName())
			
			-- Enumerate cities
			for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
    			local pCity = pPlayer:GetCityByID(cityIndex)
				 
				print (pCity:GetName());

				-- City exists and has the proper name?
    			if pCity ~= nil and city:GetName() == "Uppsala" then 
					pCity:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				elseif pCity ~= nil and pCity:GetName() == "Oslo" then
					pCity:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				elseif pCity ~= nil and pCity:GetName() == "Nidaros" then
					pCity:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				elseif pCity ~= nil and pCity:GetName() == "Roskilde" then
					pCity:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
				elseif pCity ~= nil and pCity:GetName() == "Bergen" then
					pCity:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
					return pCity							
    			end
			end
		end
end

I thank both DonQuiche and Whoward for assistance in figuring things out. (Code is mostly taken from their contributions)
 
Thank-you. I still have a couple of things to do... I'm going to change the holy city founding function so that it does not rely on a capital but on the city name. That way, the holy city doesn't have to be a capital and could even be in a minor civ city.

Also, I want to figure out away to combine the two files above. If I simply paste the bottom one into the top, it just does the bottom code. I am thinking I have to make the bottom into a function and then encapsulate it in a larger function that includes all of them... I need to test and look at other files to see how that works.
 
Thank-you. I still have a couple of things to do... I'm going to change the holy city founding function so that it does not rely on a capital but on the city name. That way, the holy city doesn't have to be a capital and could even be in a minor civ city.

Also, I want to figure out away to combine the two files above. If I simply paste the bottom one into the top, it just does the bottom code. I am thinking I have to make the bottom into a function and then encapsulate it in a larger function that includes all of them... I need to test and look at other files to see how that works.

Let me know when you get the above to work this way...I am going to try the code above in my mod to see if I can get it to work as well.
 
I used the code above and was able to found my holy city...but when I try to spread it to other cities it is not working...Got the following error Runtime Error

[String "C\Documents and Settings..."] attempt to index global 'city' (a nil value)

What does this mean?...how should I fix?
 
This will found a religion in any city, minor or player civ, capital or not (the code below sets the Christian holy city in Paris):

Code:
function CreateChristianHolyCity(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

function FoundChristianity()
  for iPlayer=0, GameDefines.MAX_CIV_PLAYERS - 1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsEverAlive()) then

	for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
    			local pCity = pPlayer:GetCityByID(cityIndex)

				-- City exists and has the proper name?
    			if pCity ~= nil and pCity:GetName() == "Paris" then

		             CreateChristianHolyCity(pCity, "RELIGION_CHRISTIANITY", "BELIEF_FORMAL_LITURGY",
					"BELIEF_PAPAL_PRIMACY", "BELIEF_CATHEDRALS",  "BELIEF_HOLY_ORDER", "BELIEF_MISSIONARY_ZEAL");
				return pCity
				end
			end
		end
	end
end

local pChristianPlot = FoundChristianity():Plot()

Tested and it works.
 
Back
Top Bottom