Making a civ start with a pantheon

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
As a part of the traits of some civs, I want to make them start the game with a specific pantheon belief already active (for example, CIVILIZATION_VODNIKS should always start with BELIEF_GOD_WATER). I'm not good at Lua modding, so if someone can help me, it will be appreciated :)
 
Assuming you want to give several civs starting beliefs in your scenario(s), use the following. (If you just want code "per civ", eg for a standalone civ mod, you could simplify the following by removing the array of civs/beliefs and testing directly for that civ and giving them a specific belief)

Code:
local startingPantheonBeliefs = {
  CIVILIZATION_ENGLAND  = GameInfoTypes.BELIEF_GOD_SEA,
  CIVILIZATION_EGYPT    = GameInfoTypes.BELIEF_SACRED_WATERS,
  CIVILIZATION_IROQUOIS = GameInfoTypes.BELIEF_ANCESTOR_WORSHIP,
}

function InitPantheons()
  for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local pPlayer = Players[iPlayer]
    local iBelief = startingPantheonBeliefs[GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type]
  
    if (iBelief) then
      if (not pPlayer:HasCreatedPantheon()) then
        pPlayer:SetFaith(Game.GetMinimumFaithNextPantheon())
        Network.SendFoundPantheon(iPlayer, iBelief)
      end
    end
  end
end
InitPantheons()

EDIT: Don't be tempted to ditch the "if (not pPlayer:HasCreatedPantheon()) then ... end" condition, it's needed to stop the belief being granted every time a saved game is re-loaded
 
I mean it for normal games on random maps, not only for scenarios. I'm going to add a new column to the Civilizations table in the database, called StartingPantheon or something like that. I think I can handle adapting your code to this, but one problem remains - which event should I use to make things happen when the game starts? GameEvents.PreGameStart seems to fire too early for this...
 
Just calling the InitPantheons() method at the end of an InGameUIAddin file effectively acts as a "OnGameLoaded" event (because the InGame addins are loaded by the InGame.lua file, which is loaded as part of the game start-up sequence)
 
no event, whoward's code above is executed when your lua file is read by the game (which is just after ingame.lua)

edit: toasted :)
 
Is there a reason why I should use Network.SendFoundPantheon instead of Game.FoundPantheon?
 
:help: Something bad happened after the latest patch - founding a pantheon using Lua crashes the game (using both Game.FoundPantheon and Network.SendFoundPantheon). Any ideas how to fix it?

Edit: Does anyone have the old version of the DLL source code? Then I can compare it with the new version to see what's changed (I need CvLuaGame.cpp and CvReligionClasses.cpp).

Edit2: After further testing I noticed that it doesn't crash the game when the pantheon is founded after the player has founded a city. So I will have to modify my code a bit...
 
OK, I fixed it. If anyone is interested, here is the current version of the script:

Code:
function InitPantheon (iPlayer, x, y)

	local pPlayer = Players [iPlayer]
	if (not pPlayer:IsMinorCiv ()) and (not pPlayer:HasCreatedPantheon ()) then

		local iBelief = GameInfoTypes [GameInfo.Civilizations [pPlayer:GetCivilizationType ()].CoA_StartingPantheon]
		if (iBelief) then

			pPlayer:SetFaith (Game.GetMinimumFaithNextPantheon ())
			Game.FoundPantheon (iPlayer, iBelief)

		end
	end
end

GameEvents.PlayerCityFounded.Add (InitPantheon)

(It uses a new column in the Civilizations table called CoA_StartingPantheon)
 
Hi

I'm interested by this trait but I think I missed something to make it work.Is that the whole LUA?
Thanks

I've got this error in log:

Guarani.lua:15: "Cannot find key - CoA_StartingPantheon"


This is what I wrote :(the Civ is the Guarani, and the pantheon is a custom belief called "jungle god")


local startingPantheonBeliefs = {
CIVILIZATION_GUARANI = GameInfoTypes.BELIEF_JUNGLE_GOD,
}

function InitPantheon (iPlayer, x, y)

local pPlayer = Players [iPlayer]
if (not pPlayer:IsMinorCiv ()) and (not pPlayer:HasCreatedPantheon ()) then

local iBelief = GameInfoTypes [GameInfo.Civilizations [pPlayer:GetCivilizationType ()].CoA_StartingPantheon]
if (iBelief) then

pPlayer:SetFaith (Game.GetMinimumFaithNextPantheon ())
Game.FoundPantheon (iPlayer, iBelief)

end
end
end

GameEvents.PlayerCityFounded.Add (InitPantheon)
 
column "CoA_StartingPantheon" does not exist in the unmodded game within table "Civilizations". PawelS is adding it as part of his mod:
(It uses a new column in the Civilizations table called CoA_StartingPantheon)
And then it appears he is sticking the starting Pantheon "name" into that new column for each civilization.
 
column "CoA_StartingPantheon" does not exist in the unmodded game within table "Civilizations". PawelS is adding it as part of his mod:And then it appears he is sticking the starting Pantheon "name" into that new column for each civilization.

Thanks for your answer, but how can I do that?

What should I write in the LUA file to make it work ? (I'm a very poor at LUA:mischief:)
 
Adding new columns to a table can't be done in Lua (AFAIK). You should use SQL. Here is how I did it:
Code:
ALTER TABLE Civilizations ADD COLUMN CoA_StartingPantheon TEXT DEFAULT NULL REFERENCES Beliefs (Type);

(I'm not sure if the DEFAULT NULL part is needed here, probably the effect will be the same without it.)

Then when defining a civ using XML or SQL, just define the content of the new column as you do with any other column:

Code:
	<Civilizations>
		<Row>
			<Type>CIVILIZATION_DWARVES</Type>
			...
			<CoA_StartingPantheon>BELIEF_MOTHER_EARTH</CoA_StartingPantheon>
			...
		</Row>
	</Civilizations>

Alternatively, you can use Update to set it for already defined civs:

Code:
	<Civilizations>
		<Update>
			<Where Type="CIVILIZATION_DWARVES"/>
			<Set CoA_StartingPantheon = "BELIEF_MOTHER_EARTH"/>
		</Update>
	</Civilizations>

(Note: The SQL code that adds the new column must be executed in the Actions tab before the code that sets the value of that column.)
 
Adding new columns to a table can't be done in Lua (AFAIK). You should use SQL. Here is how I did it:
Code:
ALTER TABLE Civilizations ADD COLUMN CoA_StartingPantheon TEXT DEFAULT NULL REFERENCES Beliefs (Type);

(I'm not sure if the DEFAULT NULL part is needed here, probably the effect will be the same without it.)

Then when defining a civ using XML or SQL, just define the content of the new column as you do with any other column:

Code:
	<Civilizations>
		<Row>
			<Type>CIVILIZATION_DWARVES</Type>
			...
			<CoA_StartingPantheon>BELIEF_MOTHER_EARTH</CoA_StartingPantheon>
			...
		</Row>
	</Civilizations>

Alternatively, you can use Update to set it for already defined civs:

Code:
	<Civilizations>
		<Update>
			<Where Type="CIVILIZATION_DWARVES"/>
			<Set CoA_StartingPantheon = "BELIEF_MOTHER_EARTH"/>
		</Update>
	</Civilizations>

(Note: The SQL code that adds the new column must be executed in the Actions tab before the code that sets the value of that column.)

Thanks!! Now it works fine! :goodjob:
 
There is one problem I noticed when using this method of creating a pantheon - when you found your first city as a civ that should get a pantheon, you get a "Pantheon Founded" notification, but it doesn't display any additional information on mouseover, although it works properly when an AI civ does so. I don't know why it's like this, so any help is appreciated (although it's not a game breaking problem, so I can live with it :))
 
Hello. For the past day or so I have been trying to get this to work specifically for one civilization only (i.e. only this one civ starts with the pantheon). I tried using what was said in this thread combined with this tutorial in order to get a working lua script, but it does not seem to fire. The game loads up fine, but I do not receive the faith (I have not added a function that sets the pantheon itself because I wanted to do baby-steps of sorts). I have obviously done something wrong, but I am not sure what I need to do to fix it. I also checked the lua log file and I didn't see any errors (it does mention that it was loaded).

Code:
print("loaded")

function InitPantheon (iPlayer)

	local pPlayer = Players[Game.GetActivePlayer()] [iPlayer]

	if (pPlayer:GetCivilizationType() == GameInfo.Civilizations["CIVILIZATION_NEWCIV"].ID) and (not pPlayer:HasCreatedPantheon()) then 
	pPlayer:SetFaith(Game.GetMinimumFaithNextPantheon())
	end
	end

Thanks for the help in advance. I have been lurking on this site for maybe a little less than a year and I have found the modding tutorials extremely useful.
 
Hello. For the past day or so I have been trying to get this to work specifically for one civilization only (i.e. only this one civ starts with the pantheon). I tried using what was said in this thread combined with this tutorial in order to get a working lua script, but it does not seem to fire. The game loads up fine, but I do not receive the faith (I have not added a function that sets the pantheon itself because I wanted to do baby-steps of sorts). I have obviously done something wrong, but I am not sure what I need to do to fix it. I also checked the lua log file and I didn't see any errors (it does mention that it was loaded).

Code:
print("loaded")

function InitPantheon (iPlayer)

	local pPlayer = Players[Game.GetActivePlayer()] [iPlayer]

	if (pPlayer:GetCivilizationType() == GameInfo.Civilizations["CIVILIZATION_NEWCIV"].ID) and (not pPlayer:HasCreatedPantheon()) then 
	pPlayer:SetFaith(Game.GetMinimumFaithNextPantheon())
	end
	end

Thanks for the help in advance. I have been lurking on this site for maybe a little less than a year and I have found the modding tutorials extremely useful.
I'm suprised you are not getting a syntax error message in the lua.log:
Code:
local pPlayer = Players[Game.GetActivePlayer()] [COLOR="Red"][iPlayer][/COLOR]
It should be either
Code:
local pPlayer = Players[Game.GetActivePlayer()]
or
Code:
local pPlayer = Players[iPlayer]
and for any game-event-hook that gives you an argument called 'iPlayer' or anything similar you would want the second method in most cases.

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

Your most basic problem is you have no 'hook-event' upon which your function InitPantheon is running. So the game never does anything with the code except make the print statement into the lua.log. If you wanted this to run every turn as part of turn processing, you would need as
Code:
function InitPantheon(iPlayer)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_NEWCIV"]) and not pPlayer:HasCreatedPantheon() then 
		pPlayer:SetFaith(Game.GetMinimumFaithNextPantheon())
	end
end
GameEvents.PlayerDoTurn.Add(InitPantheon)

print("loaded")
or something akin to that code.

I generally always place my print confirmation line that the code has loaded successfully at the bottom of my lua files.
 
@LeeS: Sorry about the delayed response. Thank you so much for the help. It works perfectly now. The only thing that I changed was I replaced:

Code:
GameEvents.PlayerDoTurn.Add(InitPantheon)

With:

Code:
GameEvents.PlayerCityFounded.Add(InitPantheon)

The problem with the "PlayerDoTurn" event is that it does not fire until the second turn. With the "PlayerCityFounded", the event will fire on turn one. Therefore, the completed code that I am using is a followed:

Code:
function InitPantheon(iPlayer)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_NEWCIV"]) and not pPlayer:HasCreatedPantheon() then 
		local iBelief = GameInfoTypes.BELIEF_PANTHEON
		pPlayer:SetFaith(Game.GetMinimumFaithNextPantheon())
		Game.FoundPantheon (iPlayer, iBelief)
	end
end
GameEvents.PlayerCityFounded.Add(InitPantheon)

print("loaded")

All you have to do is substitute "CIVILIZATION_NEWCIV" with the string that corresponds to your new civ and "BELIEF_PANTHEON" with whichever belief you want (preexisting or new).

I just want to say thanks again!
 
Back
Top Bottom