How do I make a unit start with a certain Promotion?

Sharkman Briton

Chieftain
Joined
Feb 26, 2017
Messages
3
Hi, I'm trying to make an Insurgent unit that has the Guerilla promotion which allows it to move after attacking. How would I go about making the unit start with that promotion?
 
search “MONT_ST_MICHEL_GRANT_MARTYR” in buildings.xml,it uses MODIFIER_PLAYER_UNITS_GRANT_PROMOTION to grant promotion.but seems this modifier can only grant promotion that fits the unit class.
If this way doesn't work, there is a painful way:direct write a new ability same as the promotion,using "MODIFIER_PLAYER_UNIT_ADJUST_ATTACK_AND_MOVE", and grant it to your unit.
 
EDIT: ONE OPTION:

FORGET XML, it doesn't work. I can't remember for the life of me how I did it last time with XML. I must have converted the promotion into a full-fledged ability. Just use the LUA method.

(2) The short way. With LUA (as LeeS kindly showed me earlier. You can use the following code and insert it into the LUA component of Lee's mod that you can find here: LINK.

Code:
function OnInsurgentAddedToMap( playerID : number, unitID : number )
    local pPlayer = Players[playerID]
    if pPlayer ~= nil then
        local pUnit = pPlayer:GetUnits():FindID(unitID)
        if pUnit:GetType() == GameInfo.Units["UNIT_INSURGENT"].Index then
            local unitPromotion = GameInfo.UnitPromotions["PROMOTION_GUERILLA"].Index
            pUnit:GetExperience():SetPromotion(unitPromotion)
        end
    end
end
Events.UnitAddedToMap.Add(OnInsurgentAddedToMap)

EDIT: Make sure you customize the bolded parts above.

Good luck!
 
Last edited:
Back
Top Bottom