Spell Help: Stacking Armor Debuff

AceLegend90

New Member
Reaction score
6
Hello, I have a bit of a problem with this code right here. I'm not sure what's wrong with it but it's completely freezing my WC game (like an infinite loop?). Can anyone help spot the problem?

What the Spell Does: The spell increases the caster's attack speed to max for one attack. Then, the unit that gets hit receives an armor debuff and will continually get armor debuffed the more the unit gets hurt.
Level 1: -1 armor per hit. Lasts 3 seconds (on the enemy).
Level 2: -1 armor per hit. Lasts 4 seconds (on the enemy).
Level 3: -2 armor per hit. Lasts 4 seconds (on the enemy).
Level 4: -2 armor per hit. Lasts 5 seconds (on the enemy).

Code:
struct PowerBeat
    unit attacker
    unit attacked
    integer level
    trigger effects
    timer debuff
    timer active
endstruct

function Power_Beat_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), 'B027') > 0
endfunction

function Power_Beat_Debuff takes nothing returns nothing
    local PowerBeat s = GetCSData(GetExpiredTimer())
    
    call UnitRemoveAbility(s.attacker, 'B027')
    call ReleaseTimer(s.debuff)
endfunction

function Power_Beat_Effects takes nothing returns boolean
    local PowerBeat s = GetCSData(GetTriggeringTrigger())
    local unit dummy = CreateUnit(GetOwningPlayer(s.attacker), 'h004', GetUnitX(s.attacker), GetUnitY(s.attacker), 0.)
    
    set s.level = s.level + (GetUnitAbilityLevel(s.attacker, 'A08L') + 3) / 3
    call UnitAddAbility(dummy, 'A08M')
    call SetUnitAbilityLevel(dummy, 'A08M', s.level)
    call IssueTargetOrder(dummy, "acidbomb", s.attacked)
    
    call RemoveUnit(dummy)
    set dummy = null
    return false
endfunction

function Power_Beat_End takes nothing returns nothing
    local PowerBeat s = GetCSData(GetExpiredTimer())
    
    call UnitRemoveAbility(s.attacked, 'B028')
    call ReleaseTimer(s.active)
    call s.destroy()
endfunction

function Power_Beat_Actions takes nothing returns nothing
    local PowerBeat s = PowerBeat.create()
    
    set s.attacker = GetAttacker()
    set s.attacked = GetTriggerUnit()
    set s.level = 0
    set s.effects = CreateTrigger()
    set s.debuff = NewTimer()
    set s.active = NewTimer()
    
    call SetCSData(s.debuff, s)
    call TimerStart(s.debuff, .4, false, function Power_Beat_Debuff)
    call SetCSData(s.effects, s)
    call TriggerRegisterUnitEvent(s.effects, s.attacked, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(s.effects, Condition(function Power_Beat_Effects))
    call SetCSData(s.active, s)
    call TimerStart(s.active, I2R((GetUnitAbilityLevel(s.attacker, 'A08M') + 6) / 2), false, function Power_Beat_End)
endfunction

function InitTrig_Power_Beat takes nothing returns nothing
    set gg_trg_Power_Beat = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Power_Beat, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Power_Beat, Condition(function Power_Beat_Conditions))
    call TriggerAddAction(gg_trg_Power_Beat, function Power_Beat_Actions)
    call PreloadSpell('A08M')
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
maybe acidbomb is considered damage.
If it is, it would explain the infinite EVENT_UNIT_DAMAGED loop
 

the Immortal

I know, I know...
Reaction score
51
The local trigger runs infinite cuz of the dummy's 'acidbomb' (the trigger runs again since it deals damage and the condition - unit has the debuff - is true)

To fix this just remove the (de)buff caused by the attacking unit in the triggeractions the first time the trigger is ran:
> call UnitRemoveAbility(s.attacker, 'B027')
in Power_Beat_Effects
 

Faust

You can change this now in User CP.
Reaction score
123
0 damage is damage, it doesn't matter what spell you use, if it deals damage normally, even if you set it to 0, it will be still considered as damage.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top