AW Arcaeca
Deus Vult
In this thread I was trying to figure out how to detect when a player founds a religion, and it seems to be mostly figured out. Maybe.
Now I'm trying to figure out how to add happiness if the player is the first to found a religion. Specifically it should be 1 happiness per 2 cities that follow the religion, but the code shows 1 happiness per 4 citizens because I accidentally asked for the wrong function in the last thread.
Incidentally, it's for a UA, so it should only be working with one civ. It's also based off Machiavelli24's Race for Religion.
Detection method:
The attempt at adding happiness:
But I think someone said long ago that modding with happiness is hard because of all the times the game recalculates it. I also couldn't find a "change" function for happiness rather than a "set" function, which is why there's two more variables than there probably needs to be. Unless, is there a function called "Player.ChangeHappiness()"?
Furthermore, doesn't the code I have now effectively double the player's happiness every turn?
I'm also vaguely unsure if the "if (pPlayer:GetCivilizationType())" line is unnecessary because it's redundant. My guess is probably.
Lastly - I'm still searching for an idea for the UA that would be a bonus for founding a religion in general. For now the idea is cities following that religion are 25% harder to convert, although whoward69 informs me that it's not possible without DLL modding. Unless anyone has any idea about whether it's possible with lua?
Now I'm trying to figure out how to add happiness if the player is the first to found a religion. Specifically it should be 1 happiness per 2 cities that follow the religion, but the code shows 1 happiness per 4 citizens because I accidentally asked for the wrong function in the last thread.
Incidentally, it's for a UA, so it should only be working with one civ. It's also based off Machiavelli24's Race for Religion.
Detection method:
Spoiler :
Code:
GameEvents.CityConvertsReligion.Add(
function(iPlayer, iReligion, iX, iY)
-- First set up boolean variable firstConversion to be used later
local plot = Map.GetPlot(iX, iY);
if not (plot:IsCity()) then
return;
end
local city = plot:GetPlotCity();
local isReligion = GameInfoTypes.BUILDING_GEORGIA_DUMMY_IS_RELIGION
local hasBeenReligion = GameInfoTypes.BUILDING_GEORGIA_DUMMY_HAS_BEEN_RELIGION
if (city:GetOwner() == iPlayer)
and (iPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
if (iPlayer:HasCreatedReligion()) then
local iReligion = iPlayer:GetReligionCreatedByPlayer()
if (city:GetReligiousMajority() == iReligion) then
if not (city:IsHasBuilding(isReligion)) then
city:SetNumRealBuilding(isReligion, 1)
else
if not (city:IsHasBuilding(hasBeenReligion)) then
firstConversion = true;
city:SetNumRealBuilding(hasBeenReligion, 1)
else
firstConversion = false;
end
end
else
city:SetNumRealBuilding(isReligion, 0)
end
end
end
print("Georgian City Converts Religon Event: (iPlayer: " ..tostring(iPlayer).. " iX: " ..tostring(iX).. " iY: " ..tostring(iY).. "iReligion: " ..tostring(iReligion).. "firstConversion: " ..tostring(firstConversion).. ")");
LuaEvents.GeorgianCityConvertsReligionFirstTime(iPlayer, iX, iY, iReligion, firstConversion);
end)
Spoiler :
Code:
LuaEvents.GeorgianCityConvertsReligionFirstTime.Add(
function(iPlayer, iX, iY, iReligion, firstConversion)
for i = 0, GameDefines.MAX_MAJOR_CIVS -1, 1 do
local pPlayer = Players[i]
local mPlayer = Players[m]
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
if (pPlayer:IsAlive()) then
local city = Map.GetPlot(iX, iY):GetPlotCity()
if (firstConversion) and (city:IsHolyCityForReligion(iReligion)) then
-- Happiness if first to found a religion
if not (mPlayer:HasCreatedReligion()) then
local followers = Game.GetNumFollowers(iReligion)
local happiness = pPlayer:GetHappiness()
local followers_fixed = (math.floor(followers / 4)
happiness_fixed = (math.floor(happiness + followers_fixed)
pPlayer:SetHappiness(happiness_fixed)
else
return
end
end
end
end
end
end
end)
Furthermore, doesn't the code I have now effectively double the player's happiness every turn?
I'm also vaguely unsure if the "if (pPlayer:GetCivilizationType())" line is unnecessary because it's redundant. My guess is probably.
Lastly - I'm still searching for an idea for the UA that would be a bonus for founding a religion in general. For now the idea is cities following that religion are 25% harder to convert, although whoward69 informs me that it's not possible without DLL modding. Unless anyone has any idea about whether it's possible with lua?