Building Prerequisites and Mutually Exclusive Groups

Starrynite120

Prince
Joined
Jul 15, 2015
Messages
472
I made a national wonder, and I want it to have Old Earth relics needed in every city. Problem is, I made 3 buildings, one for each affinity, equivalent to Relics (like Affinity as yields), and they are mutually exclusive. So I want a way just to say you need this building group in each city, having any combination of the 3 buildings as long as one is in each city, in order to build the national wonder, and I am not sure how to do this. Anyone know?
 
Use a CityCanConstruct check to implement the restriction.

Do what ever logic you want via lua, if you return false the building will be blocked.

Similar to this thread
 
So what I'm trying to do here is a bit different than the above question, but it is a CutyCanConstruct. I'm trying to limit whether you can build something based off how many virtues you have, and I'm using the Old Earth Relic as a test case. Any idea why this isn't working?

function CultureVictory (iPlayer, iCity, iBuildingType)
local virtue = 0
local wonderInfo = GameInfo.Buildings["BUILDING_RELIC"]
local wonderID = wonderInfo.ID

if iPlayer = 0 then
virtue = player:GetNumPolicies()
iBuildingType = wonderID
end

if virtue < 3 then
return false
end
GameEvents.CityCanConstruct.Add(CultureVictory)
 
Ok, so I fixed that, but I still can't get it to work. I've been playing around with it, and this is what I've got now.

function CultureVictory (playerID, cityID, buildingID)
local virtue = 0
local wonderInfo = GameInfo.Buildings["BUILDING_RELIC"]
local wonderID = wonderInfo.ID

if playerID == 0 then
virtue = player:GetNumPolicies()
buildingID = wonderID
end

if virtue < 3 then
return false
else
return true
end
GameEvents.CityCanConstruct.Add(CultureVictory)
 
Just from looking at the code I assume it's because you haven't defined the 'player'-variable that you're trying to use. Add:

local player = Players[playerID]

to the top block and see if it works.

That kind of error is rather easy to debug if you're using FireTuner (or the lua.log), so I assume you're currently not using it - I strongly recommend to get familiar with the tool, as it will point you directly to (most of) the errors in your code.

You can find it inside the SDK-Folder, more specifically:
Steam\steamapps\common\Sid Meier's Civilization Beyond Earth SDK\FireTuner2
 
I just tried that, still didn't work. I'm not sure what's wrong with it. I think its something to do with the variable virtue. I was able to get Old Earth Relic unbuildable by saying if buildingID == GameInfo.Buildings["BUILDING_RELIC"].ID and playerID == 0 then return false. But when I introduced the virtue variable to this it stopped working. This is what I have now and its not working.

function CultureVictory (playerID, cityID, buildingID)
local virtue = 0
local wonderInfo = GameInfo.Buildings["BUILDING_RELIC"]
local wonderID = wonderInfo.ID
local player = Players[playerID]

if playerID == 0 then
virtue = player:GetNumPolicies()
buildingID = wonderID
end

if virtue < 3 then
return false
else
return true
end
GameEvents.CityCanConstruct.Add(CultureVictory)
 
Did a little more testing. This works:

GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)

if (iBuildingType == GameInfo.Buildings["BUILDING_RELIC"].ID) and iPlayer == 0 then
return false
end

return true
end)




This doesn't:

GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)
local virtue = player:GetNumPolicies()

if (iBuildingType == GameInfo.Buildings["BUILDING_RELIC"].ID) and iPlayer == 0 and virtue < 3 then
return false
end

return true
end)




And neither does this:

GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)
local virtue = player:GetNumPolicies()
local player = Players[iPlayer]

if (iBuildingType == GameInfo.Buildings["BUILDING_RELIC"].ID) and iPlayer == 0 and virtue < 3 then
return false
end

return true
end)




So the problem has to be with virtue, but I don't know why.
 
Well, you're also missing an end at the end:

Code:
function CultureVictory (playerID, cityID, buildingID)
	local virtue = 0
	local wonderInfo = GameInfo.Buildings["BUILDING_RELIC"]
	local wonderID = wonderInfo.ID
	local player = Players[playerID]

	if playerID == 0 then
		virtue = player:GetNumPolicies()
		buildingID = wonderID
	end

	if virtue < 3 then
		return false
	else
		return true
	[U][B]end[/B][/U]
end
GameEvents.CityCanConstruct.Add(CultureVictory)

But again, debugging that took like 30 Seconds in FireTuner, get familiar with that tool.
 
Thanks for all your help. I've got this below working.

function CultureVictory (playerID, cityID, buildingID)
local virtue = 0
local wonderInfo = GameInfo.Buildings["BUILDING_RELIC"]
local wonderID = wonderInfo.ID
local player = Players[playerID]

if playerID == 0 then
virtue = player:GetNumPolicies()
end

if virtue < 3 and buildingID == wonderID then
return false
else
return true
end
end
GameEvents.CityCanConstruct.Add(CultureVictory)




I'm now trying to apply it to the Exodus Gate Project, and I'm having trouble getting it working. I've realized applying it to a project is a bit different, and I've taken a look at the quest lua file, and tried to adapt it but it is not working. This is what I've got.

function CultureVictory (playerID, cityID, projectID)
local virtue = 25
local wonderInfo = GameInfo.Projects["PROJECT_PURITY_GATE"]
local wonderID = wonderInfo.ID
local player = Players[playerID]
local team = Teams[player:GetTeam()]

if playerID == 0 then
virtue = player:GetNumPolicies()
end

if virtue < 25 then
team:SetQuestProjectAllowed(wonderID, false)
else
team:SetQuestProjectAllowed(wonderID, true)
end
end


Of course if this is a pain to get to work for a project, I can just create a new building, make that a prerequisite building for the victory project (which is in the project table already) and then apply the virtue requirement to that building. However, I would like to avoid that if possible, just applying it to the victory project would be cleaner.


EDIT: Nevermind, I got it working. I just had to change the gameevent for the project to CityCanCreate instead of CityCanConstruct
 
So I've got the restrictions for the gates working, but I'm having trouble with the mind flower. I'm trying to make it unbuildable if the city you're trying to build it in has less than 40 population. I'm assuming my problem is because the other two I was working with global yields, while this one I'm trying to get something from a specific city (which I've never done before and am not sure how to do). This is what I've got.



function PopulationVictory (playerID, cityID, ProjectType)
local requirement = 50
local wonderInfo = GameInfo.Projects["PROJECT_MIND_FLOWER"]
local wonderID = wonderInfo.ID
local player = Players[playerID]

if playerID == 0 then
requirement = city:GetPopulation()
end

if requirement < 40 and ProjectType == wonderID then
return false
else
return true
end
end
GameEvents.CityCanCreate.Add(PopulationVictory)

Also, I have looked at firetuner and am trying to figure out how to use it.
 
To get firetuner to work you'll first need to open up the game's config.ini file in a text editor and set EnableTuner = 1

There's a more thorough tutorial on the tuner here if you're interested, but the most useful feature is simply to look at the "lua console" tab while playing, and see the error messages pop up from mistakes in your code.
 
Runtime Error: C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:12: attempt to index a nil value
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:12: in function 'PopulationVictory'
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:6: in function 'PopulationVictory'
Runtime Error: C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:12: attempt to index a nil value
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:12: in function 'PopulationVictory'
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/Transcendance.lua:6: in function 'PopulationVictory'
NotificationPanel: Attempt to remove unknown Notification 1

So this is the error message I got with my above script. I see the primary problem is that I have a nil value, which is what I thought the problem was, but I don't know how to fix it. I'm trying to make "requirement" equal the population of whatever city you're trying to build the Mind Flower in, thus making the mind flower unbuildable in any city with less than 40 population. My problem I think is I don't know how to make my variable requirement refer to a specific city.
 
Well, you've once again not defined the variable that you're trying to use. 'city' does not exist, only cityID, so you have to transform cityID (which is just a number) into the actual city, which is done by:

local city = player:GetCityByID(cityID)
 
Ok wondeful. I've got to say my biggest problem is just knowing what the specifics are for defining variables. I knew what you said was the problem, I just didn't know he syntax for defining cityID. Is there a cheat sheet or something somewhere that can tell you hear kinda of things?
 
There's Lua documentation for Civ5 here: http://modiki.civfanatics.com/index.php?title=Lua_and_UI_Reference_(Civ5)

Most stuff is still the same, but not everything.

Other than that, just get Notepad++ (and possibly a ton of mods that use lua), then open all lua files with that program and just do some basic "search all files"-searches. I didn't remember the name of the GetCityByID-Function, so I just searched for cityID and found it like 3 seconds later.
 
Ok great, that's very helpful. I feel like a pain asking all these questions on this forum, so it'd be great to be able to find it all myself.
 
Back
Top Bottom