LeeS
Imperator
That's a bit more complex but still do-able.
I'll try to whomp something up this evening.
I'll try to whomp something up this evening.
--=================================================================================================================================
-- Set Up Needed Info
--=================================================================================================================================
local tUnitTypes = {"UNIT_WARRIOR", "UNIT_SLINGER"}
local bByUnitTypes = true
local bByUnitPromotionClass = false
local bByUnitAbilityClass = false
local iTurnIncrement = 1
local iXP_Amount = 1
local bAllowCityStates = true
local bAllowBarbarians = false
--=================================================================================================================================
-- Set Up Needed Info
--=================================================================================================================================
local tUnitTypes = {"UNIT_AIRCRAFT_CARRIER" }
local bByUnitTypes = true
local bByUnitPromotionClass = false
local bByUnitAbilityClass = false
local iTurnIncrement = 1
local iXP_Amount = 1
local bAllowCityStates = true
local bAllowBarbarians = false
local tUnitTypes = {"UNIT_WARRIOR", "UNIT_SLINGER", "UNIT_AIRCRAFT_CARRIER"}
function TestPlayerUnits(iPlayer, bIsFirstTime)
local pPlayer = Players[iPlayer]
if pPlayer:IsHuman() then
local pPlayerUnits = pPlayer:GetUnits()
for i, pUnit in pPlayerUnits:Members() do
if pUnit:GetType() ~= nil then
if pUnit:GetType() == GameInfo.Units["UNIT_AIRCRAFT_CARRIER"].Index and pUnit:GetMilitaryFormation() == MilitaryFormationTypes.CORPS_FORMATION and pUnit:GetAirSlots() == 2 then
pUnit:GetExperience():SetPromotion(GameInfo.UnitPromotionsTypes["PROMOTION_FLIGHT_DECK"].Index)
end
end
end
end
end
Events.PlayerTurnActivated.Add(TestPlayerUnits)
function CorpsUpgrade( playerID : number, unitID : number )
local pPlayer = Players[ playerID ]
if pPlayer ~= nil then
local pUnit = pPlayer:GetUnits():FindID(unitID);
if pUnit:GetType() == GameInfo.Units["UNIT_AIRCRAFT_CARRIER"].Index then
pUnit:GetExperience():SetPromotion(1)
end
end
end
Events.UnitFormCorps.Add(CorpsUpgrade)
function ArmyUpgrade( playerID : number, unitID : number )
local pPlayer = Players[ playerID ]
if pPlayer ~= nil then
local pUnit = pPlayer:GetUnits():FindID(unitID);
if pUnit:GetType() == GameInfo.Units["UNIT_AIRCRAFT_CARRIER"].Index then
pUnit:GetExperience():SetPromotion(2)
end
end
end
Events.UnitFormArmy.Add(ArmyUpgrade)
So, I found a workaround for Corps and Army in Lua. Instead of querying a unit's MilitaryFormation, I simply used the Event that referred to a change in MilitaryFormationType, using the template that Lee provided.
Code:function CorpsUpgrade( playerID : number, unitID : number ) local pPlayer = Players[ playerID ] if pPlayer ~= nil then local pUnit = pPlayer:GetUnits():FindID(unitID); if pUnit:GetType() == GameInfo.Units["UNIT_AIRCRAFT_CARRIER"].Index then pUnit:GetExperience():SetPromotion(1) end end end Events.UnitFormCorps.Add(CorpsUpgrade)
and
Code:function ArmyUpgrade( playerID : number, unitID : number ) local pPlayer = Players[ playerID ] if pPlayer ~= nil then local pUnit = pPlayer:GetUnits():FindID(unitID); if pUnit:GetType() == GameInfo.Units["UNIT_AIRCRAFT_CARRIER"].Index then pUnit:GetExperience():SetPromotion(2) end end end Events.UnitFormArmy.Add(ArmyUpgrade)
It works whether a unit is created as an Army/Corps or merged into one!![]()