JohnTheBaba
Chieftain
- Joined
- Mar 20, 2019
- Messages
- 10
Hello dudes, first of all thank you for all the support and knowledge you provide to new members like me, who try to learn the basics of civ modding
I am trying to make a simple lua file that provides a certain effect for an air range attack: when a certain AIR unit with the ZeroDamageID promotion make an air strike, the defender will not lose any of its HP (despite unit's ranged combat strength) IN OTHER WORDS the dealing damage will be "0".
I think it is quite simple to do but I find myself struggling with lua coding so I want your help please.
Here is the code, it doesn't seem to work as it is now and I want someone to correct it:
function NewAttackEffectRanged(
iAttackingPlayer,
iAttackingUnit,
attackerDamage,
attackerFinalDamage,
attackerMaxHP,
iDefendingPlayer,
iDefendingUnit,
defenderDamage,
defenderFinalDamage,
defenderMaxHP,
plotX,
plotY
)
local pAttackingPlayer = Players[iAttackingPlayer];
local pDefendingPlayer = Players[iDefendingPlayer];
local pAttackingUnit = pAttackingPlayer:GetUnitByID(iAttackingUnit);
local pAttackingPlot = pAttackingUnit:GetPlot();
local pDefendingPlot = Map.GetPlot(plotX, plotY);
local pDefendingUnit = pDefendingPlayer:GetUnitByID(iDefendingUnit);
local ZeroDamageID = GameInfo.UnitPromotions["PROMOTION_ZERO_DAMAGE"].ID;
if pAttackingUnit:IsHasPromotion(ZeroDamageID) then
if (pDefendingUnit ~= nil) then
local DamageOri = pAttackingUnit:GetRangeCombatDamage(pDefendingUnit, nil, false)
local ZeroDamage = 0
pDefendingUnit:ChangeDamage(ZeroDamage, pAttackingPlayer)
print("Zero Damage Dealt!")
end
end
end
GameEvents.CombatResult.Add(NewAttackEffectRanged)
I am trying to make a simple lua file that provides a certain effect for an air range attack: when a certain AIR unit with the ZeroDamageID promotion make an air strike, the defender will not lose any of its HP (despite unit's ranged combat strength) IN OTHER WORDS the dealing damage will be "0".
I think it is quite simple to do but I find myself struggling with lua coding so I want your help please.
Here is the code, it doesn't seem to work as it is now and I want someone to correct it:
function NewAttackEffectRanged(
iAttackingPlayer,
iAttackingUnit,
attackerDamage,
attackerFinalDamage,
attackerMaxHP,
iDefendingPlayer,
iDefendingUnit,
defenderDamage,
defenderFinalDamage,
defenderMaxHP,
plotX,
plotY
)
local pAttackingPlayer = Players[iAttackingPlayer];
local pDefendingPlayer = Players[iDefendingPlayer];
local pAttackingUnit = pAttackingPlayer:GetUnitByID(iAttackingUnit);
local pAttackingPlot = pAttackingUnit:GetPlot();
local pDefendingPlot = Map.GetPlot(plotX, plotY);
local pDefendingUnit = pDefendingPlayer:GetUnitByID(iDefendingUnit);
local ZeroDamageID = GameInfo.UnitPromotions["PROMOTION_ZERO_DAMAGE"].ID;
if pAttackingUnit:IsHasPromotion(ZeroDamageID) then
if (pDefendingUnit ~= nil) then
local DamageOri = pAttackingUnit:GetRangeCombatDamage(pDefendingUnit, nil, false)
local ZeroDamage = 0
pDefendingUnit:ChangeDamage(ZeroDamage, pAttackingPlayer)
print("Zero Damage Dealt!")
end
end
end
GameEvents.CombatResult.Add(NewAttackEffectRanged)
Last edited: