[Lua] disable building from production queue


Jul 2, 2022
I recently tried on UB function that allows extra specialist slot to technology buildings (public school and laboratory 1->2)

What I did was creating a copy of original building with extra slot and used lua to replace the original building into specialized version when created in city.

It worked first of all.
Then the next problem came.
After having my new public school built in my city, the game still displayed original public school on production queue. I had to find a way to disable the original building from displaying after new version made replacement. By making new version building need certain buildingclasses in future era I could stop the new version from displaying so original could only be displayed. Then when I need original version to quit displaying I couldn't find solution. I tried Building_LockedBuildingClasses but didn't work.

There's also another problem. LABORATORY requires public school building class and since the game does not concern my new version as original, it won't unlock laboratory. So I set the new version's building class to public school, hoping to unlock the laboratory but it won't.

Would there be a lua script to disable original building from being displayed when same buildingclass has already been built in the city? And allow next building which requires building class to identify new version's as original's? I believe second problem can be solved if first one gets solved since I think the problem is that new building is identified differently from original so it remains on the list. And because of it, the game might think it's not built yet and so laboratory can't co exist in the same production queue.Only disabling the original after replacing into new one might solve this problem. What do you think about this? Does lua script enabling this exist?


Jul 2, 2022
Oh..I didn't think of PlayerCanConstruct method. If possible could you show me an example since I'm not smooth with lua script...
I already solved the problem I addressed on my thread through <Buildingclass_Overrides> except it left me another problem to solve.
I made my buildings optional by overriding two version of same building and I wanted to disable one version when the other one is created. I tried <Building_LockedBuildingClasses> and it seemed to work perfectly until I found a problem. When version1 is made in a city, the other city that has not met the condition to construct the version1 could neither produce version2 which I locked with version1's building class. I suppose with XML, that code meant once this building class is produced, it locks the building itself to all of my cities whether it has met the certain condition to unlock version1 or not. I did succeed in making two optional version to be activated under condition I want (When I created religion) and the mod itself is playable.

I want to lock the unselected building version. Could you show me how to use PlayerCanConstruct event to do it? I can't find anything similar to something like city:disableBuilding blah blah.... or SetBuildDisabled.... or Civ.getBuilding().Windmill = false

I tried this method and failed

local Yenace = GameInfoTypes["CIVILIZATION_YENACE"]
local Windmill = GameInfoTypes["BUILDING_WINDMILL"]
local Workshop = GameInfoTypes["BUILDING_WORKSHOP"]
local Factory = GameInfoTypes["BUILDING_FACTORY"]
local Market = GameInfoTypes["BUILDING_MARKET"]
local Bank = GameInfoTypes["BUILDING_BANK"]
local StockExchange = GameInfoTypes["BUILDING_STOCK_EXCHANGE"]
local PublicSchool = GameInfoTypes["BUILDING_PUBLIC_SCHOOL"]
local Laboratory = GameInfoTypes["BUILDING_LABORATORY"]
local WritersGuild = GameInfoTypes["BUILDING_WRITERS_GUILD"]
local ArtistsGuild = GameInfoTypes["BUILDING_ARTISTS_GUILD"]
local MusiciansGuild = GameInfoTypes["BUILDING_MUSICIANS_GUILD"]

function BuildingLock (iPlayer, cityId)
local pPlayer = Players[iPlayer]
local pCity = pPlayer:GetCityByID(cityId)
if pPlayer:GetCivilizationType() == Yenace and pPlayer:IsAlive() then
for pCity in pPlayer:Cities() do
if pCity:IsHasBuilding(SpecialUniversity) then

I wrote too long. thank you for reading!
Last edited:
Top Bottom