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).
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