Civ-specific promotions for civilians

cstarra

Chieftain
Joined
Oct 5, 2022
Messages
3
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.

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)

 
Sounds like the Lua file isn't set up correct, see the link in my sig. Otherwise, attach the mod (see link in my sig), much easier to debug than blocks of code
 
Sorry for the delay. In further tests I've run I have been able to find print text I added in the log, but the units still don't have the promotion and can't embark. As for file set up, I've run it with and without VFS on the .lua file; neither worked. I don't think this mod would require an InGameUIAddin entry, and I assume it's not a map script. I'm open to being wrong on either of those points, though.
 

Attachments

  • IndonesiaCivilEmbark (v 1).zip
    1.4 KB · Views: 22
Sounds like the Lua file isn't set up correct, see the link in my sig. Otherwise, attach the mod (see link in my sig), much easier to debug than blocks of code
Sorry for the delay. In further tests I've run I have been able to find print text I added in the log, but the units still don't have the promotion and can't embark. As for file set up, I've run it with and without VFS on the .lua file; neither worked. I don't think this mod would require an InGameUIAddin entry, and I assume it's not a map script. I'm open to being wrong on either of those points, though.
@ whoward69 Any word on this? I forgot to reply, whoops
 
Top Bottom