Founding Religions

Civitar

Adventurer
Joined
Mar 23, 2014
Messages
1,507
Location
Switzerland
I'm having a little trouble using Game.FoundReligion. It is founding the correct religion when I want it to but it is founding it at the same time in all cities of all major civs on the map.
Here is the line I used:
Code:
Game.FoundReligion(iPlayerID, GameInfoTypes[row.ReligionType], nil, -1, -1, -1, -1, pCity);

Can anyone see a mistake here?
 
from the Medieval Scenario:
Code:
	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(iVaticanPlayer, eBelief1);
	Game.FoundReligion(iVaticanPlayer, eReligion, nil, eBelief2, eBelief3, -1, -1, pVaticanCity);
	Game.EnhanceReligion(iVaticanPlayer, eReligion, eBelief4, eBelief5);

and

	eReligion = GameInfoTypes["RELIGION_ISLAM"];
	eBelief1 = GameInfoTypes["BELIEF_TITHE"];
	eBelief2 = GameInfoTypes["BELIEF_HAJJ"];
	eBelief3 = GameInfoTypes["BELIEF_MOSQUES"];
	eBelief4 = GameInfoTypes["BELIEF_SALAT"];
	eBelief5 = GameInfoTypes["BELIEF_MISSIONARY_ZEAL"];
	Game.FoundPantheon(iMeccaPlayer, eBelief1);
	Game.FoundReligion(iMeccaPlayer, eReligion, nil, eBelief2, eBelief3, -1, -1, pMeccaCity);
	Game.EnhanceReligion(iMeccaPlayer, eReligion, eBelief4, eBelief5);
But they appear to do all that at game start, so don't know if that makes a difference. Bear in mind in that scenario they probably also re-worked the XML for the various beliefs.

The more important question is when and under what hook (if any) are you running your code ? Firaxis were doing it outside any hook as a loop through all players that appears to be running on game loading (game setup start).
 
Here is the entire Lua file that I used. I have Machiavelli's Building Created Event and Religions Grant Buildings snippets to make these work, and the building created event definitely fired when it should have.
Code:
--------------------
--Warhammer: Battles of Eternity
--Religions
--Civitar
--------------------

function WHFB_FoundReligion(iPlayerID, iCityID, iBuildingClassID)
	local pPlayer = Players[iPlayerID];
	local pCity = pPlayer:GetCityByID(iCityID);
	local iBuildingClass = GameInfo.BuildingClasses[iBuildingClassID].Type;
	for row in GameInfo.Religion_BuildingClasses() do
		if iBuildingClass == row.BuildingClassType then
			Game.FoundReligion(iPlayerID, GameInfoTypes[row.ReligionType], nil, -1, -1, -1, -1, pCity);
		end
	end
end

LuaEvents.BuildingCreatedEvent.Add(WHFB_FoundReligion);
 
I assume you're trying to give the player the ability to choose the beliefs, but as a test, does it work if you specify some random beliefs for them? Also, you may need to have them found a Pantheon as well, since I don't think the game ever expects a player to have a Religion before a Pantheon.
 
1. Use unit (Prophet for example) + PushMission to found religion.
2. Check Whoward events from recent patch - I think one of them should allow you to precise, which religion can be found by a player.

You can also allow them to found any religion then refound religion with chosen beliefs using Game.FoundReligion.
 
I think I've found the problem - bad luck.:( My test mod had set RELIGION_CATHOLICISM to be founded in a city that constructed BUILDING_MONUMENT - and since I didn't use IGE to test it, my capital and all other capitals in my first test game happened to complete the same building on the same turn.
 
Ouch!

Anyway, at least your and LastSword's response are reassurance that it is far more adaptable an lua method than I was at 1st afriad it might be.

IE, given the limited way Firaxis used it, and it was giving you crazy results when you were trying to use it in a way different than they used, I was beginning to wonder if it was one of those deals where Firaxis only added it to get a specific effect, and boinked us thereby on being able to use it more adaptively.

Just FYI, in the most recent patch Firaxis added a series of hooks to use in lua. (Hook) GameEvents.CityConstructed(ownerId, cityId, buildingType, bGold, bFaithOrCulture); fires whenever a building is constructed and does not require the work-arounds Machiavelli was forced to come up with in order to detect the construction of a building. The hook Firaxis added is back-compatible to work with all three expansions. On the second or third page of the linked thread Whoward presented a table of what hooks are usable in which expansions. And remember, so far as XML (and lua events) is concerned there is no difference between a 'building' and a 'wonder'. 'Wonder' and 'National Wonder' are merely subsets of 'Buildings'.
 
Well the link to the new Lua hooks should come in very useful, thanks.:)
It does appear that Game.FoundReligion works quite nicely - it's just that, as with any other code, you have to anticipate what might happen that you don't want.
 
Just a follow-up note, the CityConstructed event does not fire when you use IGE to 'Magic-In' a building into a city. The event has to happen 'naturally', ie: as part of gold purchasing, faith purchasing, or player turn processing.
 
Back
Top Bottom