esosorcdc
Chieftain
- Joined
- Aug 3, 2017
- Messages
- 90
What I want to do is make it where a new building that I made can only be built by human players. So removing a building from the list of available buildings that can the built in the cities of NPC players only.
GAME EVENTS (CityCanConstruct/PlayerCanConstruct) NOT VALID IN CIV 6:
After some research I found the game events GameEvents.CityCanConstruct(iPlayer, iCity, iBuildingType) and GameEvents.PlayerCanConstruct(playerID, buildingTypeID) in the Civ 5 forms so I tried to use them for Civ 6, but neither of them worked so I assume that these two game events are not valid in Civ 6. Also I would like to quote an extremely useful post that I found of a spreadsheet with Civ 6 LUA events and objects (See Below), which does not list the two game events I stated above solidifying my assumption that these two events are not valid in Civ 6. Am I Correct? I just want to make 100% sure and put it out there so others don't waste time trying to use these events in Civ 6.
WORKAROUND FOR HUMAN PLAYER ONLY BUILDING:
So I did some more research on finding a workaround. What I did was made it were every time a player has it's turn, the player is tested whether or not its human. If the player is not human, then it tests each of the NPC player's cities on whether or not they have the building in the build queue. If it is, then the building is removed from the build queue before any build progress is made. Then it tests each of the NPC player's cities on whether or not it has the building built in the city. If it does, then the building is removed from the city. So in actual game play, after it is kicked from the build queue the NPC civilizations just go on and start building something else. When they finish building whatever they were building they try to built it again, then something else, etc. The City States however keep trying to build it until I guess they feel like they need more units or something. I can see all this through Fire Tuner by the way. So yea, its not perfect, it does not do exactly what I want it to do, but I would say it is a viable work around. The LUA code is posted below and it works so copy and paste if you want to use it, just change BUILDING_NEW_BUILDING to your building's BuildingType. And if anyone has any other workarounds please post and explain. Like maybe there is a way to make your building not show up in the production panel of an NPC city which would make it where they can't built it? I don't know, just throwing it out there.
THE WORKAROUND LUA CODE (Working Code):
The following code is for your .lua file. Make sure to change BUILDING_NEW_BUILDING to your building's BuildingType. Also don't forget, under your project properties, under In-Game Actions, Add Action > Import Files and add your .lua file to it, then also under In-Game Actions, Add Action > AddGameplayScripts and add your .lua file to that to.
GAME EVENTS (CityCanConstruct/PlayerCanConstruct) NOT VALID IN CIV 6:
After some research I found the game events GameEvents.CityCanConstruct(iPlayer, iCity, iBuildingType) and GameEvents.PlayerCanConstruct(playerID, buildingTypeID) in the Civ 5 forms so I tried to use them for Civ 6, but neither of them worked so I assume that these two game events are not valid in Civ 6. Also I would like to quote an extremely useful post that I found of a spreadsheet with Civ 6 LUA events and objects (See Below), which does not list the two game events I stated above solidifying my assumption that these two events are not valid in Civ 6. Am I Correct? I just want to make 100% sure and put it out there so others don't waste time trying to use these events in Civ 6.
See the spreadsheets here for a dump of functions in player, unit, city, plot and some of the manager and configuration, as well as a partial dump of _G, and all the events:
https://docs.google.com/spreadsheets/d/1HQSUOmw_pI8dNSr1kmun4qAHj6SsOVfa1vGTbk5mVvs/edit#gid=0
It was made before the fall patch, and shows the difference between what's available in script and UI contexts..
WORKAROUND FOR HUMAN PLAYER ONLY BUILDING:
So I did some more research on finding a workaround. What I did was made it were every time a player has it's turn, the player is tested whether or not its human. If the player is not human, then it tests each of the NPC player's cities on whether or not they have the building in the build queue. If it is, then the building is removed from the build queue before any build progress is made. Then it tests each of the NPC player's cities on whether or not it has the building built in the city. If it does, then the building is removed from the city. So in actual game play, after it is kicked from the build queue the NPC civilizations just go on and start building something else. When they finish building whatever they were building they try to built it again, then something else, etc. The City States however keep trying to build it until I guess they feel like they need more units or something. I can see all this through Fire Tuner by the way. So yea, its not perfect, it does not do exactly what I want it to do, but I would say it is a viable work around. The LUA code is posted below and it works so copy and paste if you want to use it, just change BUILDING_NEW_BUILDING to your building's BuildingType. And if anyone has any other workarounds please post and explain. Like maybe there is a way to make your building not show up in the production panel of an NPC city which would make it where they can't built it? I don't know, just throwing it out there.
THE WORKAROUND LUA CODE (Working Code):
The following code is for your .lua file. Make sure to change BUILDING_NEW_BUILDING to your building's BuildingType. Also don't forget, under your project properties, under In-Game Actions, Add Action > Import Files and add your .lua file to it, then also under In-Game Actions, Add Action > AddGameplayScripts and add your .lua file to that to.
Code:
function NewBuildingHumanOnly( iPlayer, bIsFirstTime )
local pPlayer = Players[iPlayer]
local pNewBuilding = GameInfo.Buildings["BUILDING_NEW_BUILDING"].Index
if (not pPlayer:IsHuman()) and (pPlayer:GetCities():GetCapitalCity() ~= nil) then
local pCities:table = pPlayer:GetCities()
for i, pCity in pCities:Members() do
local pCityBuildQ = pCity:GetBuildQueue()
local pCityBuildings = pCity:GetBuildings()
local sCityName = Locale.Lookup(pCity:GetName())
local pBeingBuilt = pCityBuildQ:CurrentlyBuilding()
local pBeingBuiltStr = tostring(pBeingBuilt)
local pNewBuildingStr = "BUILDING_NEW_BUILDING"
if pBeingBuiltStr == pNewBuildingStr then
print("An NPC tried to build the New Building at " .. sCityName .. ", so it was removed from the city's build queue.")
pCityBuildQ:RemoveBuilding(pNewBuilding)
else
if pCityBuildings:HasBuilding(pNewBuilding) then
print("An NPC had the New Building built at " .. sCityName .. ", so the buiding was removed from the city.")
pCityBuildings:RemoveBuilding(pNewBuilding)
else
end
end
end
end
end
Events.PlayerTurnActivated.Add(NewBuildingHumanOnly)