kingchris20
Wisdom Seeker
To make the below LUA code damage nearby ENEMY units.
The code (from DJSHenninger) as it sits, will heal nearby friendly units (from its civ) +5 HP each turn.
What about it can I update to make it apply damage to nearby enemy units (aka we are at war with).
Also, can I update the code (as below) for my Alteration Mage to give all friendly units within 3 tiles a +5% defense modifier anywhere on land?
The code (from DJSHenninger) as it sits, will heal nearby friendly units (from its civ) +5 HP each turn.
What about it can I update to make it apply damage to nearby enemy units (aka we are at war with).
Spoiler :
Code:
--------------------------------------------------------------
include("PlotIterators")
---------------------------------------------------------------
function TES_MasterRestorationMage(playerID)
local player = Players[playerID]
for unit in player:Units() do
if unit:IsHasPromotion(GameInfoTypes["PROMOTION_MASTER_RESTORATION_MAGE"]) then
local unitX = unit:GetX()
local unitY = unit:GetY()
local plot = Map.GetPlot(unitX, unitY)
for loopPlot in PlotAreaSweepIterator(plot, 3, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
for iVal = 0,(loopPlot:GetNumUnits() - 1) do
local loopUnit = loopPlot:GetUnit(iVal)
if loopUnit:GetOwner() == playerID then
loopUnit:ChangeDamage(-5)
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(TES_MasterRestorationMage)
Also, can I update the code (as below) for my Alteration Mage to give all friendly units within 3 tiles a +5% defense modifier anywhere on land?
Spoiler :
Code:
--------------------------------------------------------------
include("PlotIterators")
---------------------------------------------------------------
function TES_MasterAlterationMage(playerID)
local player = Players[playerID]
for unit in player:Units() do
if unit:IsHasPromotion(GameInfoTypes["PROMOTION_MASTER_ALTERATION_MAGE"]) then
local unitX = unit:GetX()
local unitY = unit:GetY()
local plot = Map.GetPlot(unitX, unitY)
for loopPlot in PlotAreaSweepIterator(plot, 3, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
for iVal = 0,(loopPlot:GetNumUnits() - 1) do
local loopUnit = loopPlot:GetUnit(iVal)
if loopUnit:GetOwner() == playerID then
loopUnit:[COLOR="Red"]RoughDefenseModifier[/COLOR](5)
loopUnit:[COLOR="Red"]OpenDefenseModifier[/COLOR](5)
loopUnit:[COLOR="Red"]HillsDefenseModifier[/COLOR](5)
loopUnit:[COLOR="Red"]FortifyDefenseModifier[/COLOR](5)
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(TES_MasterAlterationMage)