My spell gives every unit on map a debuff. The debuff stores all incoming damage within the next 8 seconds, and then deals 2x stored damage. So, if the unit received 100 dmg, then by the end of 8 seconds it gets another 200. If 0 was dealt, it receives 0. However, the spell does not work as intended. How should I fix it?
This code requires Damage Engine.
This code requires Damage Engine.
Lua:
function spell()
local damage_collected = 0
local trigevent = CreateTrigger()
TriggerRegisterVariableEvent(trigevent, 'udg_DamageModifierEvent', EQUAL, 1)
TriggerAddAction(trigevent, function ( )
if GetUnitAbilityLevel(udg_DamageEventTarget, FourCC('A01Z')) > 0 and IsUnitEnemy(udg_DamageEventTarget, GetOwningPlayer(udg_DamageEventSource)) then
damage_collected = damage_collected + udg_DamageEventAmount
end
end)
local trig = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
TriggerAddAction(trig, function()
if GetSpellAbilityId() ~= FourCC('A019') then return end
local u = GetTriggerUnit()
local p = GetOwningPlayer(u)
local angle = GetUnitFacing(u)
local x = GetUnitX(u)
local y = GetUnitY(u)
local duration = 8
local group = CreateGroup()
GroupEnumUnitsInRange(group, x, y, 999999, Condition(function()
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 and GetFilterUnit() ~=u
end))
for index = BlzGroupGetSize(group) - 1, 0, -1 do
local t = BlzGroupUnitAt(group, index)
UnitAddAbility(t, FourCC('A01Z'))
end
TimerStart(CreateTimer(), duration, false, function()
for index = BlzGroupGetSize(group) - 1, 0, -1 do
local t = BlzGroupUnitAt(group, index)
UnitRemoveAbility(t, FourCC('A01Z'))
UnitDamageTarget(u, t, damage_collected * 2)
print(damage_collected)
damage_collected = 0
end
PauseTimer(GetExpiredTimer())
DestroyTimer(GetExpiredTimer())
end)
end)
end