• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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