Hello, I'm very new to modding this game, and I have a question for a small modification I'm trying to make. Basically, I'd like for all of Indonesia's civilian units to have the ability to embark in coast tiles (not ocean tiles) mainly as an early game advantage.
According to this< thread adding promotions to civ-specific civilian units requires the use of lua code. And @jarcast2 even provided the code to do it with. But after I copy that code into a lua file in my mod, change "CIVILIZATION_YOURCIV" to "CIVILIZATION_INDONESIA" and "PROMOTION_NAME" to "PROMOTION_EMBARKATION" for some reason that doesn't work. When my mod is loaded nothing has changed at all, no civilian units get the embarkation promotion. I can't even find any errors or reference to the mod in lua.log
How does this work? I think there's something I'm missing, and lua in general is out of my wheelhouse.
local promotionID = GameInfoTypes["PROMOTION_EMBARKATION"]
local unitSettlerID = GameInfoTypes["UNIT_SETTLER"]
local unitWorkerID = GameInfoTypes["UNIT_WORKER"]
local unitArchaeologistID = GameInfoTypes["UNIT_ARCHAEOLOGIST"]
local civilizationID = GameInfoTypes["CIVILIZATION_INDONESIA"]
function TraitFreePromotion(playerID, unitID)
local pPlayer = Players[playerID]
if pPlayer and pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civilizationID then
local unit = pPlayer:GetUnitByID(unitID)
if unit:GetUnitType() == unitSettlerID or unit:GetUnitType() == unitWorkerID or unit:GetUnitType() == unitArchaeologistID then
unit:SetHasPromotion(promotionID, true)
end
end
end
GameEvents.SerialEventUnitCreated.Add(TraitFreePromotion)
According to this< thread adding promotions to civ-specific civilian units requires the use of lua code. And @jarcast2 even provided the code to do it with. But after I copy that code into a lua file in my mod, change "CIVILIZATION_YOURCIV" to "CIVILIZATION_INDONESIA" and "PROMOTION_NAME" to "PROMOTION_EMBARKATION" for some reason that doesn't work. When my mod is loaded nothing has changed at all, no civilian units get the embarkation promotion. I can't even find any errors or reference to the mod in lua.log
How does this work? I think there's something I'm missing, and lua in general is out of my wheelhouse.
Spoiler my code :
local promotionID = GameInfoTypes["PROMOTION_EMBARKATION"]
local unitSettlerID = GameInfoTypes["UNIT_SETTLER"]
local unitWorkerID = GameInfoTypes["UNIT_WORKER"]
local unitArchaeologistID = GameInfoTypes["UNIT_ARCHAEOLOGIST"]
local civilizationID = GameInfoTypes["CIVILIZATION_INDONESIA"]
function TraitFreePromotion(playerID, unitID)
local pPlayer = Players[playerID]
if pPlayer and pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civilizationID then
local unit = pPlayer:GetUnitByID(unitID)
if unit:GetUnitType() == unitSettlerID or unit:GetUnitType() == unitWorkerID or unit:GetUnitType() == unitArchaeologistID then
unit:SetHasPromotion(promotionID, true)
end
end
end
GameEvents.SerialEventUnitCreated.Add(TraitFreePromotion)