Yield from filling Great Work Slots??

Hypereon

He was a Consul of Rome!
Joined
Jun 19, 2012
Messages
414
Location
Helsinki, Finland
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:
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.:confused:
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 :)
 
Sounds like it's an issue with the table not showing up, since having an incorrect XML tag will cause the whole file to fail. If the SQL doesn't add the table, it won't exist, meaning that XML code you've got will cause the whole file to fail and therefore not add the building. How have you added the SQL file in?
 
Also, YIELD_TOURISM isn't defined as a Yield in the <Yields> table, so this may also be causing a problem.
Tried removing that part - no effect. Still doesn't show up.

The SQL file is added just like any file in the mod, with OnModActivated and so on.
 
Tried removing that part - no effect. Still doesn't show up.

The SQL file is added just like any file in the mod, with OnModActivated and so on.

post your entire building file. If it has a seperate file for Building-Class, post that as well. Has to be a problem elsewhere in your building file is what I'm thinking at this point....
 
Here's the entire building file:
Code:
<GameData>
	<Buildings>
		<Row>
			<Type>BUILDING_FINNIC_SHRINE</Type>
			<Description>TXT_KEY_BUILDING_SHRINE</Description>
			<Civilopedia>TXT_KEY_CIV5_BUILDINGS_SHRINE_TEXT</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_SHRINE_STRATEGY</Strategy>
			<GoldMaintenance>1</GoldMaintenance>
			<MutuallyExclusiveGroup>-1</MutuallyExclusiveGroup>
			<NullifyInfluenceModifier>0</NullifyInfluenceModifier>
			<Cost>40</Cost>
			<HurryCostModifier>25</HurryCostModifier>
			<MinAreaSize>-1</MinAreaSize>
			<ConquestProb>66</ConquestProb>
			<BuildingClass>BUILDINGCLASS_SHRINE</BuildingClass>
			<ArtDefineTag>TEMPLE</ArtDefineTag>
			<FreeStartEra>ERA_MEDIEVAL</FreeStartEra>
			<MaxStartEra>ERA_RENAISSANCE</MaxStartEra>
			<PrereqTech>TECH_POTTERY</PrereqTech>
			<SpecialistCount>0</SpecialistCount>
			<GreatWorkSlotType>GREAT_WORK_SLOT_LITERATURE</GreatWorkSlotType>
			<GreatWorkCount>1</GreatWorkCount>
			<DisplayPosition>0</DisplayPosition>
			<PortraitIndex>9</PortraitIndex>
			<IconAtlas>EXPANSION_BW_ATLAS_1</IconAtlas>
		</Row>
	</Buildings>
	<Building_YieldChanges>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<YieldType>YIELD_FAITH</YieldType>
			<Yield>1</Yield>
		</Row>
	</Building_YieldChanges>
	<Building_DomainFreeExperiencePerGreatWork>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<DomainType>DOMAIN_LAND</DomainType>
			<Experience>5</Experience>
		</Row>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<DomainType>DOMAIN_SEA</DomainType>
			<Experience>5</Experience>
		</Row>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<DomainType>DOMAIN_AIR</DomainType>
			<Experience>5</Experience>
		</Row>
	</Building_DomainFreeExperiencePerGreatWork>
	<Building_Flavors>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<FlavorType>FLAVOR_RELIGION</FlavorType>
			<Flavor>35</Flavor>
		</Row>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<FlavorType>FLAVOR_MILITARY_TRAINING</FlavorType>
			<Flavor>5</Flavor>
		</Row>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<FlavorType>FLAVOR_CULTURE</FlavorType>
			<Flavor>10</Flavor>
		</Row>
	</Building_Flavors>
	<Building_YieldFromGreatWorksInBuilding>
		<Row>
			<BuildingType>BUILDING_FINNIC_SHRINE</BuildingType>
			<YieldType>YIELD_FAITH</YieldType>
			<Yield>2</Yield>
		</Row>
	</Building_YieldFromGreatWorksInBuilding>
</GameData>
 
never mind. Duh. That's not it. It runs the way you have it with the special table removed. Has to be the Special Table is not being added correctly by the SQL.

Double-check your modBuddy setting for the SQL file. I just tested using your SQL and your Building. The only change I made was to assign the building as a unique to Rome. On my end your version of the shrine shows just fine in the civilopedia. Though you do need to change your <Description> tag so there aren't two 'Shrine' in the civilopedia lists.
 
Top Bottom