Need help with Lua

OTiger

Warlord
Joined
Aug 26, 2012
Messages
178
I been trying to write this Lua code for my upcoming mod's UA, but as a person who doesn't understand Lua or programming, it's pretty confusing to do. And since there's two parts of this code, it makes even more confusing.

"For each City State are allied with, you get +2 Culture and +1 Happiness. During Golden Ages, City State influence does not degrade and you get +4% more culture for each City State you're allied with."

I've been using this code here from this thread, but I'm wondering if Lua objects like GetMinorCivCultureFriendshipBonus go here or somewhere else. How would I define the number of culture and happiness gained?
Code:
function ExtraCultureAndHappinessPerCS(iPlayer)
CSAllyCount = 0;
	local pPlayer = Players[iPlayer]
	for i, player in pairs(Players) do
	if player:IsAlive() then
		if player:IsMinorCiv() then
			if player:GetMinorCivFriendshipLevelWithMajor(iPlayer) == integer then
-- iPlayer is ID number of Major Civ your are checking. Integer, you have to check which number is Allied, because I've never used it (i assume it will be 2)
                                print(player:GetName())
				CSAllyCount = CSAllyCount + 1;

And for the second part of the code, I looked here for some help on Golden Ages and apparently the parameters for GoldenAgeStarted are unknown. Also, I guess for that part of the code, I would need a dummy policy to have zero degradation during Golden Ages.
 
OK, I've written the code now and I got some help from one of Vicevirtuoso's Madoka Civs, JFD's Milan and Poland-Lithuania Civs and reading LeeS' guide on Dummy Buildings. I'm not sure it's right though.
(Note that I decided not to put in the 4% extra culture per City State bonus and got rid of the no degradation during Golden Ages.)
Code:
--+2 Culture and +1 happiness per CS Ally
gSpongeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY
function SpongebobUA(iPlayer)
		local pPlayer = Players[iPlayer]
		local iCultureHappinessBonus = 0;
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCultureHappinessBonus = iCultureHappinessBonus + 1;
				end
			end
		iCultureHappinessBonus = if pCapitalCity:IsHasBuilding(gSpongebobDummy) then
			pCapitalCity:SetNumRealBuilding(gSpongeDummy , iNumCapitalHappyBuildings + 1)
			print("Adding 1 Spongebob Dummy Building, coming up!")
			end
		end
	end
-- SpongebobUA Part 2: No City-State degradtion during Golden Ages
	local player = Players[playerID]
	local policySpongebobUA = GameInfoTypes["POLICY_SPONGEBOBUA"]

		if (player:IsGoldenAge() and not (player:HasPolicy(policySpongebobID))) then
			if not player:HasPolicy(GameInfoTypes["POLICY_SPONGEBOBUA"]) then
				--player:SetPolicyBranchUnlocked(GameInfoTypes["POLICY_BRANCH_PIETY"], true)
				player:SetNumFreePolicies(1)
				player:SetNumFreePolicies(0)
				player:SetHasPolicy(GameInfoTypes["POLICY_SPONGEBOBUA"], true)	
		elseif not (player:IsGoldenAge()) then
			if player:HasPolicy(policySpongebobID) then
				player:SetHasPolicy(policySpongebobID, false)
		end
end

And here's the BNW_Updates.xml:

Code:
	<GameData>
		<Buildings>
			<!-- Happiness Dummy -->
			<Update>
				<Where Type="BUILDING_SPONGEBOBDUMMY" />
				<Set>
					<GreatWorkCount>-1</GreatWorkCount>
				</Set>
			</Update>
		</Buildings>
	</GameData>

And here's the Dummy Policy:
Code:
<GameData>

	<Policies>
		<Row>
			<Type>POLICY_SPONGEBOBUA</Type>
			<Description>TXT_KEY_POLICY_SPONGEBOBUA</Description>
			<MinorFriendshipDecayMod>100</MinorFriendshipDecayMod>
		</Row>
	</Policies>



	<Language_en_US>
		<Row Tag="TXT_KEY_POLICY_SPONGEBOBUA">
			<Text>Spongebob UA</Text>
		</Row>
	</Language_en_US>

</GameData>
And finally, here's the Dummy Building itself:

Code:
<GameData>
	<Buildings>
		<Row>
			<Type>BUILDING_SPONGEBOBDUMMY</Type>
			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
			<Civilopedia>TXT_KEY_CIV5_BUILDINGS_SPONGEBOBDUMMY_TEXT</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_SPONGEBOBDUMMYSTRATEGY</Strategy>
			<Help>TXT_KEY_BUILDING_SPONGEBOBDUMMY_HELP</Help>
			<PrereqTech>NULL</PrereqTech>
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<NukeImmune>true</NukeImmune>
			<NoLimit>true</NoLimit>
			<Happiness>1</Happiness>
			<ArtDefineTag>PALACE</ArtDefineTag>
			<DisplayPosition>32</DisplayPosition>
			<PortraitIndex>19</PortraitIndex>
			<WonderSplashAnchor>R,T</WonderSplashAnchor>
			<IconAtlas>BW_ATLAS_1</IconAtlas>
			<ArtInfoCulturalVariation>1</ArtInfoCulturalVariation>
			<ArtInfoEraVariation>0</ArtInfoEraVariation>
			<ArtInfoRandomVariation>0</ArtInfoRandomVariation>
		</Row>
	</Buildings>

	<Building_YieldChanges>
		<Row>
			<BuildingType>BUILDING_PALACE</BuildingType>
			<YieldType>YIELD_CULTURE</YieldType>
			<Yield>2</Yield>
		</Row>
	</Building_YieldChanges>

	<Language_en_US>
		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY">
			<Text>Spongebob Dummy Building</Text>
		</Row>
		<Row Tag="TXT_KEY_CIV5_BUILDINGS_SPONGEBOBDUMMY_TEXT">
			<Text>
				<!-- Add Civilopedia text here -->
			</Text>
		</Row>
		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY_STRATEGY">
			<Text>This building gives out +2 Culture and +1 Happiness per City State. You're normally not supposed to see this building.</Text>
		</Row>
		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY_HELP">
			<Text>Gives out +2 [ICON_CULTURE]Culture and +1 [ICON_HAPPINESS]Happiness per City State.</Text>
		</Row>
	</Language_en_US>
</GameData>

So, is there anything wrong?
 
Buildings Issues 1st:
  1. This would make the Palace yield 2 Culture for all civilizations:
    Code:
    <Building_YieldChanges>
    	<Row>
    		<BuildingType>BUILDING_PALACE</BuildingType>
    		<YieldType>YIELD_CULTURE</YieldType>
    		<Yield>2</Yield>
    	</Row>
    </Building_YieldChanges>
    You need:
    Code:
    	<Building_YieldChanges>
    		<Row>
    			<BuildingType>BUILDING_SPONGEBOBDUMMY</BuildingType>
    			<YieldType>YIELD_CULTURE</YieldType>
    			<Yield>2</Yield>
    		</Row>
    	</Building_YieldChanges>
  2. This won't actually be needed:
    Code:
    <GameData>
    	<Buildings>
    		<!-- Happiness Dummy -->
    		<Update>
    			<Where Type="BUILDING_SPONGEBOBDUMMY" />
    			<Set>
    				<GreatWorkCount>-1</GreatWorkCount>
    			</Set>
    		</Update>
    	</Buildings>
    </GameData>
    You are already setting <GreatWorkCount>-1</GreatWorkCount> for BUILDING_SPONGEBOBDUMMY here:
    Code:
    	<Buildings>
    		<Row>
    			<Type>BUILDING_SPONGEBOBDUMMY</Type>
    			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    			<Civilopedia>TXT_KEY_CIV5_BUILDINGS_SPONGEBOBDUMMY_TEXT</Civilopedia>
    			<Strategy>TXT_KEY_BUILDING_SPONGEBOBDUMMYSTRATEGY</Strategy>
    			<Help>TXT_KEY_BUILDING_SPONGEBOBDUMMY_HELP</Help>
    			<PrereqTech>NULL</PrereqTech>
    			[color="blue"]<GreatWorkCount>-1</GreatWorkCount>[/color]
    			<FaithCost>-1</FaithCost>
    			<MinAreaSize>-1</MinAreaSize>
    			<NeverCapture>true</NeverCapture>
    			<NukeImmune>true</NukeImmune>
    			<NoLimit>true</NoLimit>
    			<Happiness>1</Happiness>
    			<ArtDefineTag>PALACE</ArtDefineTag>
    			<DisplayPosition>32</DisplayPosition>
    			<PortraitIndex>19</PortraitIndex>
    			<WonderSplashAnchor>R,T</WonderSplashAnchor>
    			<IconAtlas>BW_ATLAS_1</IconAtlas>
    			<ArtInfoCulturalVariation>1</ArtInfoCulturalVariation>
    			<ArtInfoEraVariation>0</ArtInfoEraVariation>
    			<ArtInfoRandomVariation>0</ArtInfoRandomVariation>
    		</Row>
    	</Buildings>
    So making a BNW-only update file and code for the building is not needed because the original definition of the building is locking out Vanilla and G&K.
  3. For a dummy building you do not really want any of these:
    Code:
    	<Buildings>
    		<Row>
    			<Type>BUILDING_SPONGEBOBDUMMY</Type>
    			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    			[color="red"]<Civilopedia>TXT_KEY_CIV5_BUILDINGS_SPONGEBOBDUMMY_TEXT</Civilopedia>
    			<Strategy>TXT_KEY_BUILDING_SPONGEBOBDUMMYSTRATEGY</Strategy>
    			<Help>TXT_KEY_BUILDING_SPONGEBOBDUMMY_HELP</Help>[/color]
    			<PrereqTech>NULL</PrereqTech>
    			<GreatWorkCount>-1</GreatWorkCount>
    			<FaithCost>-1</FaithCost>
    			<MinAreaSize>-1</MinAreaSize>
    			<NeverCapture>true</NeverCapture>
    			<NukeImmune>true</NukeImmune>
    			<NoLimit>true</NoLimit>
    			<Happiness>1</Happiness>
    			[color="red"]<ArtDefineTag>PALACE</ArtDefineTag>
    			<DisplayPosition>32</DisplayPosition>[/color]
    			<PortraitIndex>19</PortraitIndex>
    			[color="red"]<WonderSplashAnchor>R,T</WonderSplashAnchor>[/color]
    			<IconAtlas>BW_ATLAS_1</IconAtlas>
    			[color="red"]<ArtInfoCulturalVariation>1</ArtInfoCulturalVariation>
    			<ArtInfoEraVariation>0</ArtInfoEraVariation>
    			<ArtInfoRandomVariation>0</ArtInfoRandomVariation>[/color]
    		</Row>
    	</Buildings>
    It would be better to define the building as:
    Code:
    	<Buildings>
    		<Row>
    			<Type>BUILDING_SPONGEBOBDUMMY</Type>
    			[color="blue"]<BuildingClass>BUILDINGCLASS_SPONGEBOBDUMMY</BuildingClass>[/color]
    			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    			<PrereqTech>NULL</PrereqTech>
    			<GreatWorkCount>-1</GreatWorkCount>
    			<FaithCost>-1</FaithCost>
    			<MinAreaSize>-1</MinAreaSize>
    			<NeverCapture>true</NeverCapture>
    			<NukeImmune>true</NukeImmune>
    			<Happiness>1</Happiness>
    			<PortraitIndex>19</PortraitIndex>
    			<IconAtlas>BW_ATLAS_1</IconAtlas>
    		</Row>
    	</Buildings>
  4. You not want this in the definition of the Building in any case:
    Code:
    <NoLimit>true</NoLimit>
    Table <Buildings> has no column called <NoLimit>. You cannot conflate one game-table into another (See the next item).
  5. You have not assigned BUILDING_SPONGEBOBDUMMY to a building-class. Every building must be assigned to a Building-Class. Dummy buildings are always better defined as their own Building-Class:
    Code:
    <BuildingClasses>
    	<Row>
    		<Type>BUILDINGCLASS_SPONGEBOBDUMMY</Type>
    		<DefaultBuilding>BUILDING_SPONGEBOBDUMMY</DefaultBuilding>
    		<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    		<NoLimit>true</NoLimit>
    	</Row>
    </BuildingClasses>
    Note the line in blue in item #3
  6. In your <Language_en_US> these are not productive for your dummy building:
    Code:
    	<Language_en_US>
    		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY">
    			<Text>Spongebob Dummy Building</Text>
    		</Row>
    		[color="red"]<Row Tag="TXT_KEY_CIV5_BUILDINGS_SPONGEBOBDUMMY_TEXT">
    			<Text>
    				<!-- Add Civilopedia text here -->
    			</Text>
    		</Row>
    		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY_STRATEGY">
    			<Text>This building gives out +2 Culture and +1 Happiness per City State. You're normally not supposed to see this building.</Text>
    		</Row>
    		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY_HELP">
    			<Text>Gives out +2 [ICON_CULTURE]Culture and +1 [ICON_HAPPINESS]Happiness per City State.</Text>
    		</Row>[/color]
    	</Language_en_US>
  7. I would redefine the entire file for the dummy building as:
    Code:
    <GameData>
    	<BuildingClasses>
    		<Row>
    			<Type>BUILDINGCLASS_SPONGEBOBDUMMY</Type>
    			<DefaultBuilding>BUILDING_SPONGEBOBDUMMY</DefaultBuilding>
    			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    			<NoLimit>true</NoLimit>
    		</Row>
    	</BuildingClasses>
    	<Buildings>
    		<Row>
    			<Type>BUILDING_SPONGEBOBDUMMY</Type>
    			<BuildingClass>BUILDINGCLASS_SPONGEBOBDUMMY</BuildingClass>
    			<Description>TXT_KEY_BUILDING_SPONGEBOBDUMMY</Description>
    			<PrereqTech>NULL</PrereqTech>
    			<GreatWorkCount>-1</GreatWorkCount>
    			<FaithCost>-1</FaithCost>
    			<MinAreaSize>-1</MinAreaSize>
    			<NeverCapture>true</NeverCapture>
    			<NukeImmune>true</NukeImmune>
    			<Happiness>1</Happiness>
    			<PortraitIndex>19</PortraitIndex>
    			<IconAtlas>BW_ATLAS_1</IconAtlas>
    		</Row>
    	</Buildings>
    	<Building_YieldChanges>
    		<Row>
    			<BuildingType>BUILDING_SPONGEBOBDUMMY</BuildingType>
    			<YieldType>YIELD_CULTURE</YieldType>
    			<Yield>2</Yield>
    		</Row>
    	</Building_YieldChanges>
    	<Language_en_US>
    		<Row Tag="TXT_KEY_BUILDING_SPONGEBOBDUMMY">
    			<Text>Spongebob Dummy Building</Text>
    		</Row>
    	</Language_en_US>
    </GameData>

The lua needs a bit of work as well but I need to think it through a bit more how to explain what I see as what is being done wrong. (<-- clumbsy sentence). I'll try to respond to the lua issues later this evening if no one else responds before then.
 
This would be the lua for the +2 Culture and +1 Happiness in the capital city per city-state ally:
Code:
--+2 Culture and +1 happiness per CS Ally
gSpongeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY
local iNeededPlayer = GameInfoTypes.CIVILIZATION_YOUR_CIV_NAME_HERE
function SpongebobUA(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iNeededPlayer then
		local iCultureHappinessBonus = 0
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCultureHappinessBonus = iCultureHappinessBonus + 1
				end
			end
		end
		pCapitalCity:SetNumRealBuilding(gSpongeDummy , iCultureHappinessBonus)
		print("Setting " .. iCultureHappinessBonus .. " Spongebob Dummy Buildings into the capital city of " .. pCapitalCity:GetName())
	end
end
GameEvents.PlayerDoTurn.Add(SpongebobUA)
Just bear in mind that since you used <Happiness> in the definition of BUILDING_SPONGEBOBDUMMY instead of <UnmoddedHappiness> there might in some cases only be a partial happiness increase in the Empire, or even none at all.

I didn't do anything with the golden age part because your stated wants in your posts were unclear, and well...I wanted to keep the lua code as simple as possible, and to seperate the two issues until you were more clear on what it is you are after.
 
I didn't do anything with the golden age part because your stated wants in your posts were unclear, and well...I wanted to keep the lua code as simple as possible, and to seperate the two issues until you were more clear on what it is you are after.

Wow! Thanks for the help, LeeS.

Anyways, for the second part of the code, I wrote so that during Golden Ages, your influence to City-State degrade slower than usual like the Patronage Social Policy (I haven't though up a number yet, maybe around 50%?).

Originally, I thought up that part of the code as no degradation of your City-State influence and having a 2% boost of your culture for each City-State you're allied with during Golden Ages, but that was too complicated for me and I don't know if that's even possible, which is why I went for a "simpler" choice.

Also, I was worrying that I was wasting your time and annoying you too much.
 
Wow! Thanks for the help, LeeS.

Anyways, for the second part of the code, I wrote so that during Golden Ages, your influence to City-State degrade slower than usual like the Patronage Social Policy (I haven't though up a number yet, maybe around 50%?).

Originally, I thought up that part of the code as no degradation of your City-State influence and having a 2% boost of your culture for each City-State you're allied with during Golden Ages, but that was too complicated for me and I don't know if that's even possible, which is why I went for a "simpler" choice.

Also, I was worrying that I was wasting your time and annoying you too much.

The 2% boost to culture can be done with a different dummy building. If it is added to the capital city and has
Code:
<GlobalCultureRateModifier>2</GlobalCultureRateModifier>
as part of its definition within table <Buildings> then for each copy of such a building added to the capital, culture generation in all cities will be increased by 2%. If you only wanted the boost to occur to the capital city, then the definition within table <Buildings> would use
Code:
<CultureRateModifier>2</CultureRateModifier>
and then a piggy-back would be added to previous lua code to add the building during a golden age:
Code:
--+2 Culture and +1 happiness per CS Ally
gSpongeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY
local iGoldenAgeDummy = GameInfoTypes.BUILDING_GOLDEN_AGE_DUMMY
local iNeededPlayer = GameInfoTypes.CIVILIZATION_YOUR_CIV_NAME_HERE
function SpongebobUA(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iNeededPlayer then
		local iCultureHappinessBonus = 0
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCultureHappinessBonus = iCultureHappinessBonus + 1
				end
			end
		end
		pCapitalCity:SetNumRealBuilding(gSpongeDummy , iCultureHappinessBonus)
		print("Setting " .. iCultureHappinessBonus .. " Spongebob Dummy Buildings into the capital city of " .. pCapitalCity:GetName())
		if pPlayer:IsGoldenAge() then
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , iCultureHappinessBonus)
		else
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , 0)
		end
	end
end
GameEvents.PlayerDoTurn.Add(SpongebobUA)
 
The no degradation would take more thought. You can set (or change) the amount of influence a player has with a city-state within lua, but I don't remember how 'easy' the methods available are within lua to determine by how much a player's influence is degrading with each individual city-state.

The <MinorFriendshipDecayMod> thing you were looking at with the policy would work except that patronage actually uses a -25 value to slow down decay. "100" would double the rate at which influence dissipates.

The problem with swapping policies in and out is that you must have two different dummy policies if the 'real' dummy policy is ever removed from the player. You need:
  1. The "Real" dummy policy that has the code with the desired effects
  2. A "Placeholder" dummy policy that does not actually do anything
Then you must:
  • Remove the "Real" dummy policy and replace it with the "Placeholder" dummy policy when the real dummy policy needs to be removed from the player.
  • Remove the "Placeholder" dummy policy and replace it with the "Real" dummy policy when the real dummy policy needs to be re-added to the player.
Otherwise, you irretrievably break the social policy cost system, and the player begins to experience some very strange culture "cost" requirements for the next social policy.
 
From the sounds of it, assuming I stick with this, it looks like it's not impossible to have the less degradation during Golden Ages but's it's tricky to do so. I used JFD's Poland-Lithuania and my Squidward mod as a reference:

Code:
--+2 Culture and +1 happiness per CS Ally
gSpongeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY
local iGoldenAgeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY2
local iNeededPlayer = GameInfoTypes.CIVILIZATION_BIKINI_BOTTOM
[COLOR="Blue"]local policySpongebobUA = GameInfoTypes.POLICY_SPONGEBOBUA
local policySpongebobPlaceholder = GameInfoTypes.POLICY_SPONGEBOB_PLACEHOLDER[/COLOR]
function SpongebobUA(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iNeededPlayer then
		local iCultureHappinessBonus = 0
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCultureHappinessBonus = iCultureHappinessBonus + 1
				end
			end
		end
		pCapitalCity:SetNumRealBuilding(gSpongeDummy , iCultureHappinessBonus)
		print("Setting " .. iCultureHappinessBonus .. " Spongebob Dummy Buildings into the capital city of " .. pCapitalCity:GetName())
		if pPlayer:IsGoldenAge() then
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , iCultureHappinessBonus)
[COLOR="blue"]			--player:SetPolicyBranchUnlocked(GameInfoTypes["POLICY_BRANCH_PIETY"], true)
			player:SetNumFreePolicies(1)
			player:SetNumFreePolicies(0)
			player:SetHasPolicy(policySpongebobUA, true)[/COLOR]
		else
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , 0)
[COLOR="blue"]			--player:SetPolicyBranchUnlocked(GameInfoTypes["POLICY_BRANCH_PIETY"], true)
			player:SetNumFreePolicies(1)
			player:SetNumFreePolicies(0)
			player:SetHasPolicy(policySpongebobPlaceholder, true)[/COLOR]
		end
	end
end
GameEvents.PlayerDoTurn.Add(SpongebobUA)
Would this be correct?

And just in case, here's the Dummy Policies:
Code:
<GameData>

	<Policies>
		<Row>
			<Type>POLICY_SPONGEBOBUA</Type>
			<Description>TXT_KEY_POLICY_SPONGEBOBUA</Description>
			<MinorFriendshipDecayMod>-50</MinorFriendshipDecayMod>
		</Row>
		<Row>
			<Type>POLICY_SPONGEBOB_PLACEHOLDER</Type>
			<Description>TXT_KEY_POLICY_SPONGEBOB_PLACEHOLDER</Description>
		</Row>
	</Policies>


	<Language_en_US>
		<Row Tag="TXT_KEY_POLICY_SPONGEBOBUA">
			<Text>Spongebob UA</Text>
		</Row>
		<Row Tag="TXT_KEY_POLICY_SPONGEBOB_PLACEHOLDER">
			<Text>Spongebob UA Placeholder</Text>
		</Row>
	</Language_en_US>

</GameData>
 
  1. you have to be careful with your variable naming, especially when you are copying in code from elsewhere to use as templates.
    Code:
    player != pPlayer
  2. I got rid of the two comment lines in the lua since they would just add confusion. Anything in lua that follows -- on a line will be considered a comment and not executable code
  3. The code as you made it needs a bit more logic and a slight change to the policy 'giving' methods.
Code:
--+2 Culture and +1 happiness per CS Ally
gSpongeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY
local iGoldenAgeDummy = GameInfoTypes.BUILDING_SPONGEBOBDUMMY2
local iNeededPlayer = GameInfoTypes.CIVILIZATION_BIKINI_BOTTOM
local policySpongebobUA = GameInfoTypes.POLICY_SPONGEBOBUA
local policySpongebobPlaceholder = GameInfoTypes.POLICY_SPONGEBOB_PLACEHOLDER
function SpongebobUA(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iNeededPlayer then
		local iCultureHappinessBonus = 0
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCultureHappinessBonus = iCultureHappinessBonus + 1
				end
			end
		end
		pCapitalCity:SetNumRealBuilding(gSpongeDummy , iCultureHappinessBonus)
		print("Setting " .. iCultureHappinessBonus .. " Spongebob Dummy Buildings into the capital city of " .. pCapitalCity:GetName())
		if pPlayer:IsGoldenAge() then
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , iCultureHappinessBonus)
			if not pPlayer:HasPolicy(policySpongebobUA) and not pPlayer:HasPolicy(policySpongebobPlaceholder) then
				pPlayer:SetNumFreePolicies(1)
				pPlayer:SetNumFreePolicies(0)
				pPlayer:SetHasPolicy(policySpongebobUA, true)
			elseif pPlayer:HasPolicy(policySpongebobPlaceholder) then
				pPlayer:SetHasPolicy(policySpongebobPlaceholder, false)
				pPlayer:SetHasPolicy(policySpongebobUA, true)
			end
		else
			pCapitalCity:SetNumRealBuilding(iGoldenAgeDummy , 0)
			if pPlayer:HasPolicy(policySpongebobUA) then
				pPlayer:SetHasPolicy(policySpongebobUA, false)
				pPlayer:SetHasPolicy(policySpongebobPlaceholder, true)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(SpongebobUA)
 
So, I guess that's about it then. Thanks for the help, LeeS!
I tired it with a test mod, and It seems to work!

I'm not sure how I can repay you with this and future help. :p
 
Back
Top Bottom