Salamandre
King
Is it possible that when we capture a settler, the worker we get is deleted then one pop is added to the closest city (or the capital if calculations are too cumbersome)?
-- Only continue if the unit is a great engineer
if(unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_ENGINEER"] and not player:IsMinorCiv() and not player:IsBarbarian() and plot:IsCity()) then
if(unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_ENGINEER"] or
unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_MERCHANT"] or
unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_WRITER"]or
unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_SCIENTIST"]or
unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_ARTIST"]or
unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_MUSICIAN"]and not player:IsMinorCiv() and not player:IsBarbarian() and plot:IsCity()) then
function OrdainedPriesthood(playerID, unitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
local player = Players[playerID];
local unit = player:GetUnitByID(unitID);
local policyID = GameInfoTypes["POLICY_FREE_RELIGION"];
local plot = unit:GetPlot();
-- Only if the player has the policy and this is missionary/inquisitor
if(player:HasPolicy(policyID) and not player:IsPolicyBlocked(policyID) and plot:IsCity() and (unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_MISSIONARY"] or unit:GetUnitClassType() == GameInfoTypes["UNITCLASS_INQUISITOR"])) then
local city = plot:GetPlotCity();
city:ChangePopulation(1, true);
-- Send a notification to the player
local header = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIESTHOOD_HEADER");
local text = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIESTHOOD_BODY", city:GetName());
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, header);
end
end
LuaEvents.SerialEventUnitCreatedGood.Add(OrdainedPriesthood);
In lua the number shown on the error message is generally refering you to the line number within the code where the error is originating from. Usually from that sort of an error I would expect to see an '[' somewhere without a matching ']', but I don't see those anywhere. Is what you are quoting the entire code from the file?Ordained_Priesthood.lua:11: ']' expected near ')'
blocks
Also also, try placing a space between 'if' and anything that follows and the same with 'elseif' -- it shouldn't ought to make a difference but it will be easier to read, and may actually make a difference.
[edit]
This part of your code will also be problematical:
[code]-- Send a notification to the player
local header = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIESTHOOD_HEADER");
local text = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIESTHOOD_BODY", city:GetName());
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, header);
function OrdainedPriesthood(playerID, unitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
local player = Players[playerID];
local unit = player:GetUnitByID(unitID);
local plot = unit:GetPlot();
-- -- Only if the player has the policy and this is a great person spawned in a city
if (player:HasPolicy(GameInfoTypes.POLICY_TRADITION_FINISHER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_TRADITION_FINISHER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_PROPHET)) then
-- Get the city
local city = plot:GetPlotCity();
city:ChangePopulation(1, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_ASTHETICS_FINISHER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_ASTHETICS_FINISHER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_ARTIST)) then
-- Get the city
local city = plot:GetPlotCity();
city:ChangePopulation(1, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_HONOR_FINISHER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_HONOR_FINISHER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_ENGINEER)) then
-- Get the city
local city = plot:GetPlotCity();
city:ChangePopulation(1, true);
end
-- Send a notification to the player
--local header = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIEST HOOD_HEADER");
--local text = Locale.ConvertTextKey("TXT_KEY_NEW_ORDAINED_PRIEST HOOD_BODY", city:GetName());
--player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, header);
end
LuaEvents.SerialEventUnitCreatedGood.Add(OrdainedPriesthood);
Your code works fine for me as this:
function GreatEngineerBorn_GivePopulation(playerID, unitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
local player = Players[playerID];
local unit = player:GetUnitByID(unitID);
local plot = unit:GetPlot();
local city = plot:GetPlotCity();
-- Only continue if the unit is a specialist
if (player:HasPolicy(GameInfoTypes.POLICY_TRADITION_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_TRADITION_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_ENGINEER and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_LIBERTY_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_LIBERTY_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_WRITER and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_HONOR_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_HONOR_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_GREAT_GENERAL and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_PIETY_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_PIETY_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_PROPHET and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_AESTHETICS_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_AESTHETICS_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_ARTIST and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_COMMERCE_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_COMMERCE_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_MERCHANT and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
elseif (player:HasPolicy(GameInfoTypes.POLICY_RATIONALISM_OPENER) and not player:IsPolicyBlocked(GameInfoTypes.POLICY_RATIONALISM_OPENER) and (unit:GetUnitClassType() == GameInfoTypes.UNITCLASS_SCIENTIST and plot:IsCity())) then
local bonusPop = 1;
city:ChangePopulation(bonusPop, true);
-- Send a notification to the player
local header = Locale.ConvertTextKey("TXT_KEY_TITANS_ENGINEER_POPULATION_ON_BIRTH_HEADER", tostring(bonusPop), city:GetName());
local text = Locale.ConvertTextKey("TXT_KEY_TITANS_ENGINEER_POPULATION_ON_BIRTH_BODY", tostring(bonusPop), city:GetName(), unit:GetName());
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, header);
end
end
LuaEvents.SerialEventUnitCreatedGood.Add(GreatEngineerBorn_GivePopulation);
Okay, after I fixed all errors, this has a new look. Lua is working now, the only backside is that it seems I can't put "adopt policy" as condition (TRADITION_OPENER, etc), it has to be one policy from list. Do you know why? I like having those births bonuses on adopting the required branch, not somewhere inside.
This is not normal behavior. If you have directed ModBuddy to save all your work in the game's MODS folder, this is not a good idea, and is likely the culprit for this behavior. You should not be seeing the ModBuddy "Project" folders such as "Packages" or "Build" anywhere within the game's MODS folder.And no, changing syntax in Mods folder does not work, the game will instantly read from modbuddy when reload and will delete my changes.