Sid Meier's Civilization: Beyond Earth

Sid Meier's Civilization: Beyond Earth

Experience Worlds Beyond Earth
Game modifications, scenarios, interface, and so much more. Explore the modding world of Beyond Earth, and when you're ready, download the SDK to create and upload your own.
Help with LUA
Good day all! I'm having a bit of trouble trying to tweak a code in the LUA where the chosen cargo grants the human player a certain building but if chosen by the AI, it will not have it. (Instead I would have to create a different script to grant them something else). I have the snippet here but it looks like this code creates the building in every city that is going to be built but I just wanted the building to appear only in the capital when the player makes planetfall. In this case, the cargo option is called "Dyson" and the building is "Aizenvault". What lines do I need or change to set the building to only appear at the capital? Thanks in advance to those who can help.

if(currentCargo == GameInfo.Cargo["CARGO_DYSON"].ID) then
for pCity in Players[playerID]:Cities() do
pCity:SetNumRealBuilding(GameInfo.Buildings["BUILDING_AIZENVAULT"].ID, 1)
end
end
Last edited by Ghoulvarine; 4 Jun, 2016 @ 2:26pm
< >
Showing 1-3 of 3 comments
Ryika 42 4 Jun, 2016 @ 2:46pm 
You can use Game.GetActivePlayer() to find out which slot is filled by the Human Player.
And you can use city:IsCapital() to find out whether a City is the Capital City of a Player.

But if your goal is to only add a building to the capital anyway, then the function of choice is usually player:GetCapitalCity()


So overall that part of the script would look something like this:

if(currentCargo == GameInfo.Cargo["CARGO_DYSON"].ID) then
local activePlayer = Game.GetActivePlayer()
local capital = player:GetCapitalCity()
if player == activePlayer then
if capital ~= nil then
capital:SetNumRealBuilding(GameInfo.Buildings["BUILDING_AIZENVAULT"].ID, 1)
end
else
<Do stuff for AIs>
end
end

There's probably a few syntax errors in the script and I can't actually test whether it works properly right now, but it should be a good place to start from.
Last edited by Ryika; 4 Jun, 2016 @ 2:47pm
Ghoulvarine 4 Jun, 2016 @ 7:21pm 
If there's another custom building in place like from another source (i.e. spacecraft), will I need a different building ID for this one? I tested the script earlier and it removed another building that was supposed to be granted at the start so neither one of them were showing up and grant the appropriate effects.
Ryika 42 5 Jun, 2016 @ 6:50am 
Not quite sure what exactly you mean, but it seems most likely you've just some errors in your script that prevent it from working. If you haven't already, setup FireTuner, it's pretty important for using Lua as it shows you a live-update of the log. See:
http://forums.civfanatics.com/showthread.php?t=399821

If that's not the problem, then please rephrase what you meant.
< >
Showing 1-3 of 3 comments
Per page: 1530 50