Hypereon
He was a Consul of Rome!
So, I'm building a Shrine with a GW of Writing slot that will add extra faith when filled.
Pouakai and Sukritact's Burma did this with +2 Gold, and I tried to replicate this with adding Burmese Civilization's BuildingYieldFromGreatWorksInBuilding.lua and Tables.sql in the mod.
Tables.sql:
BuildingYieldFromGreatWorksInBuilding.lua:
Then I added the table for the Building:
However, this causes the building to commpletely disappear from the game.
Did I forget something important (I'm a newbie for lua)?
So, does anybody know how it is supposed to be done in order to make things work?
Thanks in advance
Pouakai and Sukritact's Burma did this with +2 Gold, and I tried to replicate this with adding Burmese Civilization's BuildingYieldFromGreatWorksInBuilding.lua and Tables.sql in the mod.
Tables.sql:
Code:
-- Create Table --
CREATE TABLE IF NOT EXISTS Building_YieldFromGreatWorksInBuilding (
BuildingType text,
YieldType text,
Yield integer default 0
);
BuildingYieldFromGreatWorksInBuilding.lua:
Code:
-- BuildingYieldFromGreatWorksInBuilding
-- Author: Sukritact
--------------------------------------------------------------
print("loaded")
WARN_NOT_SHARED = false; include( "SaveUtils" ); MY_MOD_NAME = "BuildingYieldFromGreatWorksInBuilding";
function BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
--print(bIsTurnStart)
for row in GameInfo.Building_YieldFromGreatWorksInBuilding() do
local iBuilding = GameInfo.Buildings[row.BuildingType].ID
strName = GameInfo.Buildings[iBuilding].Description
local iYield = YieldTypes[row.YieldType]
local iDeltaModifier = row.Yield
for pCity in pPlayer:Cities() do
local iCity = pCity:GetID()
--local strCityName = pCity:GetName()
local strBuildingClass = GameInfo.Buildings[iBuilding].BuildingClass
local iBuildingClass = GameInfo.BuildingClasses[strBuildingClass].ID
local iGreatWorksNum = pCity:GetNumGreatWorksInBuilding(iBuildingClass)
local iDelta = (iGreatWorksNum*iDeltaModifier)
--print (iCity .. strCityName .. iGreatWorksNum)
if pCity:IsHasBuilding(iBuilding) then
--print("Building: " .. strName .. " exists in city: " .. strCityName)
if iYield == 4 then
local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4)
--print (iYield .. "NUM" .. tostring(iOldDelta))
save( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4, iDelta)
if iOldDelta == nil then
pCity:ChangeJONSCulturePerTurnFromBuildings(iDelta)
else
pCity:ChangeJONSCulturePerTurnFromBuildings(iDelta - iOldDelta)
end
elseif iYield == 5 then
if bIsTurnStart == true then
pPlayer:ChangeFaith(iDelta)
--else
--print ("Not Turn Start")
end
else
local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield)
--print (iYield .. "NUM" .. tostring(iOldDelta))
save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield, iDelta)
if iOldDelta == nil then
pCity:ChangeBaseYieldRateFromBuildings(iYield, iDelta)
else
pCity:ChangeBaseYieldRateFromBuildings(iYield, iDelta - iOldDelta)
end
end
-- Clear data if Building does not exist --
else
--print("Building: " .. strName .. " does not exist in city: " .. strCityName)
if iYield == 4 then
local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4)
if iOldDelta == nil then
--print("Never existed")
elseif iOldDelta > 0 then
save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4, 0)
pCity:ChangeJONSCulturePerTurnFromBuildings(-iOldDelta)
--print("Data Cleared")
end
elseif iYield == 5 then
--print("Faith = Nil")
else
local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield)
if iOldDelta == nil then
--print("Never existed")
elseif iOldDelta > 0 then
save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield, 0)
pCity:ChangeBaseYieldRateFromBuildings(iYield, -iOldDelta)
--print("Data Cleared")
end
end
end
end
end
end
-- End of Main Code --
function BuildingYieldFromGreatWorksInBuildingTurnStart(iPlayer, pPlayer)
--print ("Turn Trigger")
local pPlayer = Players[iPlayer]
local bIsTurnStart = true
BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
end
function BuildingYieldFromGreatWorksInBuildingSwap()
local iPlayer = Game.GetActivePlayer()
local pPlayer = Players[iPlayer]
if pPlayer:IsTurnActive() then
--print ("Swap Trigger")
local bIsTurnStart = false
BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
end
end
GameEvents.PlayerDoTurn.Add(BuildingYieldFromGreatWorksInBuildingTurnStart)
Events.SerialEventCityInfoDirty.Add(BuildingYieldFromGreatWorksInBuildingSwap)
Then I added the table for the Building:
Code:
<Building_YieldFromGreatWorksInBuilding>
<Row>
<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
<YieldType>YIELD_FAITH</YieldType>
<Yield>3</Yield>
</Row>
<Row>
<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
<YieldType>YIELD_TOURISM</YieldType>
<Yield>-2</Yield>
</Row>
</Building_YieldFromGreatWorksInBuilding>
However, this causes the building to commpletely disappear from the game.

Did I forget something important (I'm a newbie for lua)?
So, does anybody know how it is supposed to be done in order to make things work?
Thanks in advance
