• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Spell] Deal damage but delayed

Status
Not open for further replies.
Level 3
Joined
Mar 10, 2018
Messages
32
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.

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
 
Level 3
Joined
Mar 10, 2018
Messages
32
I believe the problem is in the way I try to store damage that was dealt during the debuff. Because when the 8 seconds are over every single unit that had the debuff receives damage. Which is not the way it should work.

It was intended that only those who were damaged received that damage again but doubled.

Lua:
    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)
Lua:
...
UnitDamageTarget(u, t, damage_collected * 2)
...
 
Status
Not open for further replies.
Top