Cat-du-fromage
Warlord
- Joined
- Nov 17, 2018
- Messages
- 189
Hi,
Trying to rework a promotion from TCM's Austria-Hungary i had some problem when the bonus of +1 combat strenght stack every time i pick a promotion:
Zum Beispiel: Unit base combat strenght = 31,
Have Base 3 promotion
= Combat strenght = 34
Add 1 more promotion
= combat strenght = 38 WTF?????
In the base code, the strenght of the Unit was taken directly on [UNIT_TCM_GRENZER]
But now i try to use the ID to select the unit baseCombatStrength, since the promotion should not be lose on upgrade but it doesn't seem to work
Note: the "pUnit:GetBaseCombatStrength()" doesn't work, it works only if i write "unit:GetBaseCombatStrength()"
Does someone see the error^^?
Trying to rework a promotion from TCM's Austria-Hungary i had some problem when the bonus of +1 combat strenght stack every time i pick a promotion:
Zum Beispiel: Unit base combat strenght = 31,
Have Base 3 promotion
= Combat strenght = 34
Add 1 more promotion
= combat strenght = 38 WTF?????
In the base code, the strenght of the Unit was taken directly on [UNIT_TCM_GRENZER]
But now i try to use the ID to select the unit baseCombatStrength, since the promotion should not be lose on upgrade but it doesn't seem to work
Code:
--------------------------------------------------------------
-- GE_Grenzer from TCM's Austria-Hungary
--------------------------------------------------------------
function GE_GetNumPromotions(unit)
local numPromotions = 0
if unit:IsHasPromotion(GameInfoTypes.PROMOTION_GRENZSCHUTZ) then
for promotion in GameInfo.UnitPromotions() do
if unit:IsHasPromotion(promotion.ID) then
numPromotions = numPromotions + 1
end
end
end
return numPromotions
end
local bonusPerPromotion = 1
local unitGrenzerID = GameInfoTypes["UNIT_TCM_GRENZER"]
local GEPromotion = GameInfoTypes["PROMOTION_GRENZSCHUTZ"]
local UnitGun = GameInfoTypes["UNITCOMBAT_GUN"]
function GE_Grenzer(playerID)
local player = Players[playerID]
if (player:GetCivilizationType() == civilisationID and player:IsEverAlive()) then
for unit in player:Units() do
if unit:IsHasPromotion(GameInfoTypes.PROMOTION_GRENZSCHUTZ) then
local pUnit = unit:GetID() --Select Unit ID
local baseCombatStrength = pUnit:GetBaseCombatStrength() --Use Get base combat strenght from ID
if baseCombatStrength < (baseCombatStrength + bonusPerPromotion*GE_GetNumPromotions(unit)) then
unit:SetBaseCombatStrength(baseCombatStrength + bonusPerPromotion*GE_GetNumPromotions(unit))
end
end
end
end
end
if JFD_IsCivilisationActive(civilisationID) then
GameEvents.UnitPromoted.Add(GE_Grenzer)
GameEvents.UnitUpgraded.Add(GE_Grenzer)
--GameEvents.PlayerDoTurn.Add(GE_Grenzer)
end
Note: the "pUnit:GetBaseCombatStrength()" doesn't work, it works only if i write "unit:GetBaseCombatStrength()"
Does someone see the error^^?