Hello,
I've recently been trying to augment an XML mod of mine with some Lua:
It is a simple Mod Test Kit ("Mod Test Helper" in the Steam Workshop), that grants some light-weight, low impact tools to test mods (FireTuner is a bit heavy metal for some repeated runs at a minor Xml mod). All it really does right now is add some additional buildings. Now I'd like a way to get rid of those buildings again. Easier said than done, since somehow you can't sell/demolish buildings.
Which left me with the idea that Lua might be able to do something for me.
Why not have a check run every turn for player-cities that meet a certain criterion (say: Another building that serves as flag for demolishing), and then demolishes all the buildings my mod adds to the game?
Sounded like a good idea, but I have absolutely no experience doing Lua. Reading up on reference material - no tutorials for CivBE yet, but plenty for Civ 5, which appears to be fairly similar - I happily started my quest for building annihilation.
Some frustration later I had something that sounded workable. Ran it, it failed, compared to other mods, fixed some Lua language errors, tried again, looked up more reference, fixed some more language errors, ... AndSoOnAndSoOn ...
Oh, and Firetuner didn't say a thing, it's as if the lua files never loaded at all (and yes, it's set to Import into VFS).
Soo ... I've finally given up on fixing it myself and have come asking for help. Would anybody look over this and tell me where I messed up? (And feel free to recommend/explain better ways for me to reach my goal - I just pieced things together as I found them in the reference here in the Modiki mostly)
Any insights would be most welcome.
Cheers and thanks in advance,
Bosparan
I've recently been trying to augment an XML mod of mine with some Lua:
It is a simple Mod Test Kit ("Mod Test Helper" in the Steam Workshop), that grants some light-weight, low impact tools to test mods (FireTuner is a bit heavy metal for some repeated runs at a minor Xml mod). All it really does right now is add some additional buildings. Now I'd like a way to get rid of those buildings again. Easier said than done, since somehow you can't sell/demolish buildings.
Which left me with the idea that Lua might be able to do something for me.
Why not have a check run every turn for player-cities that meet a certain criterion (say: Another building that serves as flag for demolishing), and then demolishes all the buildings my mod adds to the game?
Sounded like a good idea, but I have absolutely no experience doing Lua. Reading up on reference material - no tutorials for CivBE yet, but plenty for Civ 5, which appears to be fairly similar - I happily started my quest for building annihilation.
Some frustration later I had something that sounded workable. Ran it, it failed, compared to other mods, fixed some Lua language errors, tried again, looked up more reference, fixed some more language errors, ... AndSoOnAndSoOn ...
Oh, and Firetuner didn't say a thing, it's as if the lua files never loaded at all (and yes, it's set to Import into VFS).
Soo ... I've finally given up on fixing it myself and have come asking for help. Would anybody look over this and tell me where I messed up? (And feel free to recommend/explain better ways for me to reach my goal - I just pieced things together as I found them in the reference here in the Modiki mostly)
Code:
function DemolishBuildings (player)
print("Demolish Buildings function was called");
local pPlayer = Players[player];
if (pPlayer:IsHuman() == 1) then
print("Human PLayer detected");
for city in pPlayer:Cities() do
print("Processing a city");
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_DEMOLISHER"])) then
print("Demolisher was found in city");
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_CULTURE"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_CULTURE"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_ENERGY"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_ENERGY"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_EXPERIENCE"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_EXPERIENCE"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_FOOD"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_FOOD"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_HEALTH"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_HEALTH"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_PRODUCTION"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_PRODUCTION"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_SCIENCE"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_SCIENCE"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_UNLOCKER"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_UNLOCKER"], 0);
end
if (city:IsHasBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_DEMOLISHER"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_BOS_MOD_TEST_DEMOLISHER"], 0);
end
end
end
end
end
GameEvents.PlayerDoTurn.Add( DemolishBuildings );
Any insights would be most welcome.
Cheers and thanks in advance,
Bosparan