Building dummy building upon detection of citadel

You don't need to add 30 buildings, but only 5 (+1, +2, +4, +8 and +16) and use a variation of the code in this thread to add the required combination of buildings
 
I considered using a powers of two structure but that would result in more buildings in the city vs less in the civilopedia. I cared more about minimizing impact on the city screen than the civilopedia but the difference is pretty minor.
 
In the lua file you'll need to add the restriction. I would add it to the existing if statement:

Code:
if(eImprovement == GameInfo.Improvements["IMPROVEMENT_CUSTOMS_HOUSE"].ID) then

change it to something like: if(stuff and player is civ) then ...
 
In the lua file you'll need to add the restriction. I would add it to the existing if statement:

Code:
if(eImprovement == GameInfo.Improvements["IMPROVEMENT_CUSTOMS_HOUSE"].ID) then

change it to something like: if(stuff and player is civ) then ...

okay, will try that.

Thanks a lot.
 
Spoiler :
The code still doesn't work - I have probably made a mistake somewhere.

The lua.log file says the following:
Code:
[37106.975] Runtime Error: E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:55: attempt to compare number with nil
stack traceback:
	E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:55: in function <E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:19>
[37112.013] Runtime Error: E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:55: attempt to compare number with nil
stack traceback:
	E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:55: in function <E:\Libraries\Documents\My Games\Sid Meier's Civilization 5\MODS\Corsican Republic (v 1)\Lua/CorsicaFunctionsTest.lua:19>

and the relevant lua code:
Spoiler :
Code:
local civilisationID = GameInfoTypes["CIVILIZATION_CORSICA"]
------------------------------------------------------------------------------------------------------------------------
-- CorsicaCitadelTourism
------------------------------------------------------------------------------------------------------------------------
-- Use global variables to avoid having the event be called twice for the same plot
CorsicaCitadelTourism_BuildFinished_PlayerID = 0
CorsicaCitadelTourism_BuildFinished_X = 0
CorsicaCitadelTourism_BuildFinished_Y = 0
CorsicaCitadelTourism_BuildFinished_Improvement = 0

function CorsicaCitadelTourism(playerID, iX, iY, eImprovement)
	-- Don't continue if this is a duplicate call
	if(CorsicaCitadelTourism_BuildFinished_PlayerID == playerID and CorsicaCitadelTourism_BuildFinished_X == iX and CorsicaCitadelTourism_BuildFinished_Y == iY and CorsicaCitadelTourism_BuildFinished_Improvement == eImprovement) then
		return;
	end
	-- Store inputs for duplication check
	CorsicaCitadelTourism_BuildFinished_PlayerID = playerID;
	CorsicaCitadelTourism_BuildFinished_X = iX;
	CorsicaCitadelTourism_BuildFinished_Y = iY;
	CorsicaCitadelTourism_BuildFinished_Improvement = eImprovement;

	-- Max determined by number of entries in CorsicaTourismCount
	local CONSTANT_MAX_CITADEL_TOURISM = 20;

	local player = Players[playerID];
	local plot = Map.GetPlot(iX, iY);
	local city = player:GetCapitalCity();
	local buildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM"];
	local numBuilding = 0;
	local oldBuildingID = -1;
	local newBuildingID = -1;

	if(eImprovement == GameInfo.Improvements["IMPROVEMENT_CITADEL"].ID and player:GetCivilizationType() == civilisationID) then
		numBuilding = city:GetNumBuilding(buildingID);

		-- Do not continue if there is no building providing more citadel tourism
		if(numBuilding == CONSTANT_MAX_CITADEL_TOURISM) then
			print("WARN -- At max tourism from citadels, can not give more.");
			return;
		end

		city:SetNumRealBuilding(buildingID, numBuilding + 1);

		oldBuildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM_" .. tostring(numBuilding)];
		newBuildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM_" .. tostring(numBuilding + 1)];

		if(newBuildingID > 0 and (numBuilding == 0 or (oldBuildingID > 0 and city:IsHasBuilding(oldBuildingID)))) then
			city:SetNumRealBuilding(newBuildingID, 1);
			if(numBuilding > 0) then
				city:SetNumRealBuilding(oldBuildingID, 0);
			end
		end
	end
end
GameEvents.BuildFinished.Add(CorsicaCitadelTourism);

-- Move dummy building to capital in the event of conquest
function CorsicaCitadelTourism_CapitalMove(oldPlayerID, bCapital, iX, iY, newPlayerID, conquest, conquest2)
	local oldPlayer = Players[oldPlayerID];
	local newPlayer = Players[newPlayerID];
	local city =  Map.GetPlot(iX, iY):GetPlotCity();
	local buildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM"];
	local numBuilding = city:GetNumBuilding(buildingID);
	local numCitadelTourismBuildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM_" .. tostring(numBuilding)];

	-- If the old player just lost their capital, move the buildings to their new capital
	if(numBuilding > 0) then
		city:SetNumRealBuilding(buildingID, 0);
		city:SetNumRealBuilding(numCitadelTourismBuildingID, 0);
		if(oldPlayer:IsAlive()) then
			oldPlayer:GetCapitalCity():SetNumRealBuilding(buildingID, numBuilding);
			oldPlayer:GetCapitalCity():SetNumRealBuilding(numCitadelTourismBuildingID, 1);
		end
	end
	---------------------------------
	-- If the new player just recovered their capital, they will need to have their buildings moved
	if(newPlayer:GetCapitalCity():GetID() == city:GetID()) then
		for cityToRemove in newPlayer:Cities() do
			if(cityToRemove:GetID() ~= city:GetID() and cityToRemove:IsHasBuilding(buildingID)) then
				numBuilding = cityToRemove:GetNumBuilding(buildingID);
				numCitadelTourismBuildingID = GameInfoTypes["BUILDING_CORSICAN_CITADEL_TOURISM_" .. tostring(numBuilding)];
				-- Add the buildings to the player's new capital
				city:SetNumRealBuilding(buildingID, numBuilding);
				city:SetNumRealBuilding(numCitadelTourismBuildingID, 1);
				-- Remove them from the old capital
				cityToRemove:SetNumRealBuilding(buildingID, 0);
				cityToRemove:SetNumRealBuilding(numCitadelTourismBuildingID, 0);
			end
		end
	end
end
GameEvents.CityCaptureComplete.Add(CorsicaCitadelTourism_CapitalMove);
Line 55, in which the log file says there is an error, is this one:
Code:
if(newBuildingID > 0 and (numBuilding == 0 or (oldBuildingID > 0 and city:IsHasBuilding(oldBuildingID)))) then
I've no idea as to what the problem is.
Also here is the rest the relevant code:
BuildingClasses:
Code:
INSERT INTO BuildingClasses
			(Type, 										DefaultBuilding, 						Description,									NoLimit,	MaxPlayerInstances,	GoldenAgeModifier)
VALUES	    ('BUILDINGCLASS_CORSICAN_CITADEL_TOURISM',	'BUILDING_CORSICAN_CITADEL_TOURISM', 	'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM',	1,			-1,					0),
Buildings:
Code:
INSERT INTO Buildings
		(Type, 						 			BuildingClass, 								Cost,	FaithCost,	PrereqTech,				ConquestProb,	NukeImmune,	MinAreaSize,	Description, 									Help)
VALUES	('BUILDING_CORSICAN_CITADEL_TOURISM', 	'BUILDINGCLASS_CORSICAN_CITADEL_TOURISM',	-1,		-1,			'TECH_PRINTING_PRESS',	100,			1,			-1,				'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM',	'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM_HELP');
and finally my CorsicaTourismCount:
Code:
CREATE TABLE IF NOT EXISTS CorsicaTourismCount(numTourism INTEGER DEFAULT 0);

INSERT INTO CorsicaTourismCount(numTourism) VALUES
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9),
(10),
(11),
(12),
(13),
(14),
(15),
(16),
(17),
(18),
(19),
(20);

INSERT INTO BuildingClasses
			(Type,													DefaultBuilding,									Description)
SELECT		'BUILDINGCLASS_CORSICAN_CITADEL_TOURISM_'||numTourism,	'BUILDING_CORSICAN_CITADEL_TOURISM_'||numTourism,	'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM'
FROM CorsicaTourismCount;

INSERT INTO Buildings
			(Type,												BuildingClass,											Description,									NukeImmune, ConquestProb,	Cost,	FaithCost,	PrereqTech,				TechEnhancedTourism)
SELECT		'BUILDING_CORSICAN_CITADEL_TOURISM_'||numTourism,	'BUILDINGCLASS_CORSICAN_CITADEL_TOURISM_'||numTourism,	'TXT_KEY_BUILDING_CORSICAN_CITADEL_TOURISM',	1,			100,			-1,		-1,			'TECH_PRINTING_PRESS',	numTourism
FROM CorsicaTourismCount;

Help is much appreciated.


EDIT: It works now.
 
Thanks to both of you Danmacsch and DarkScythe as I'm an utter noob in LUA and I found the solution to my problem by reading your thread! Cheers! :D
 
Back
Top Bottom