bouncymischa
Synthetic Genie
I've been trying to start learning Lua, and figured a good starting point would be to implement the trait from Hambil's tutorial here. However, I'm running into problems getting the lua function to execute, so I suspect I'm missing something in the enormous amount of Lua code the CivUP project used.
I know the Lua code is loading and executing as the print statement at the start executes, but the function itself never seems to get called. I can't get FireTuner to work, so I can't test it out that way. I took at look at the modiki, but it's difficult to navigate through with bunches of the material missing or causing errors. As near as I can tell, the event I'm trying to tie the event to doesn't exist.
This is the code I'm trying to use:
Looking at the modiki, I can't find any sign of "BuildingConstructed" in the event handlers, so I'm not sure if it's something in the CivUP code and not an event in the core game, or what... so I'm wondering what events DO trigger when a building is constructed? I'm assuming this code could be linked to them...
I know the Lua code is loading and executing as the print statement at the start executes, but the function itself never seems to get called. I can't get FireTuner to work, so I can't test it out that way. I took at look at the modiki, but it's difficult to navigate through with bunches of the material missing or causing errors. As near as I can tell, the event I'm trying to tie the event to doesn't exist.
This is the code I'm trying to use:
Code:
function BuildingCreated(player, city, buildingID)
local playerID = player:GetID()
local plot = city:Plot()
local buildingInfo = GameInfo.Buildings[buildingID]
local query = ""
local trait = player:GetTraitInfo()
print("***[ Calling BuildingCreated ]***")
if city:IsCapital() then
for row in GameInfo.Trait_YieldFromConstructionInCapital() do
if trait.Type == row.TraitType and buildingInfo.Type == row.BuildingType then
if row.Yield ~= 0 then
player:ChangeYieldStored(GameInfo.Yields[row.YieldType].ID, row.Yield)
--log:Debug("+%s %s from science building constructed in %s", row.Yield, GameInfo.Yields[row.YieldType].Type, city:GetName())
end
if row.YieldMod ~= 0 then
local prereqTech = buildingInfo.PrereqTech or "TECH_AGRICULTURE"
local yieldAdded = row.YieldMod/100 * GameInfo.Technologies[prereqTech].Cost * Game.GetSpeedInfo().ResearchPercent/100
player:ChangeYieldStored(GameInfo.Yields[row.YieldType].ID, yieldAdded)
--log:Debug("+%s %s from science building constructed in %s", yieldAdded, GameInfo.Yields[row.YieldType].Type, city:GetName())
end
end
end
end
for row in GameInfo.Trait_YieldFromConstruction() do
if trait.Type == row.TraitType and buildingInfo.Type == row.BuildingType then
local yieldInfo = GameInfo.Yields[row.YieldType]
City_ChangeYieldStored(city, yieldInfo.ID, row.Yield)
if playerID == Game.GetActivePlayer() then
Events.GameplayAlertMessage(string.format(
"%s gained %s %s %s from constructing a %s.",
city:GetName(),
row.Yield,
yieldInfo.IconString,
Locale.ConvertTextKey(yieldInfo.Description),
Locale.ConvertTextKey(buildingInfo.Description)
))
end
end
end
end
LuaEvents.BuildingConstructed.Add( BuildingCreated )
Looking at the modiki, I can't find any sign of "BuildingConstructed" in the event handlers, so I'm not sure if it's something in the CivUP code and not an event in the core game, or what... so I'm wondering what events DO trigger when a building is constructed? I'm assuming this code could be linked to them...