OnlyHeStandsHere
Chieftain
- Joined
- May 4, 2018
- Messages
- 46
So I've got some working code that lowers a unit's combat strength when in enemy territory... continuously and permanently. I'm not confused by the outcome, since it's doing what I intended for the time being. But is there a way to reverse the penalty when the unit leaves enemy territory (without, for example, continuously buffing the unit every turn)?
Here's what I got by the way:
One thought I had to at least stop the "continuously" part of the problem would be to make another promotion that is given to the unit when entering enemy territory. Then I'd add a bit of code to check if the unit already has the penalty promotion. But, my understanding is that you cannot make a unit lose its promotion, so it'd still be permanently debuffed.
Here's what I got by the way:
Code:
function NeutralityPromotion(iPlayer, iUnitID, iX, iY)
local pPlayer = Players[iPlayer]
local pUnit = pPlayer:GetUnitByID( iUnitID );
local pPlot = Map.GetPlot(iX, iY)
local Promotion = GameInfoTypes["PROMOTION_NEUTRALITY"]
local iBaseStrength = pUnit:GetBaseCombatStrength()
local iOurTeam = pPlayer:GetTeam()
if pUnit:IsHasPromotion(Promotion) and pPlot:GetOwner() ~= iPlayer then
if (Teams[iOurTeam]:IsAtWar(pPlot:GetTeam())) then
pUnit:SetBaseCombatStrength(iBaseStrength * .75) --Neutrality penalty
end
end
end
GameEvents.UnitSetXY.Add(NeutralityPromotion)
One thought I had to at least stop the "continuously" part of the problem would be to make another promotion that is given to the unit when entering enemy territory. Then I'd add a bit of code to check if the unit already has the penalty promotion. But, my understanding is that you cannot make a unit lose its promotion, so it'd still be permanently debuffed.