Warcraft III resources & community, 2003–2006 · archived

AddSpecialEffectTargetUnitWithTimer

not rated
Submitted by AltSubmitterFunctions0 downloads
This lets you create a special effect that will automatically delete itself after a period of time. This way you don't have to worry about going back and deleting it. Although the AddSpecialEffectTargetUnitWithTimer_Child function is necessary for this to work, you should only call AddSpecialEffectTargetUnitWithTimer, which takes the same parameters as the normal special effect function except you also have to pass it duration. The reason a separate trigger is created is because without it, the wait would cause whichever trigger is calling the function to pause until the special effect was deleted.

Source

//Ignore this function, just make sure it comes first in script
function AddSpecialEffectTargetUnitWithTimer_Child takes nothing returns nothing
    local effect tempeffect = bj_lastCreatedEffect
    local real duration     = bj_enumDestructableRadius
    call PolledWait( duration )
    call DestroyEffect( tempeffect )
endfunction

function AddSpecialEffectTargetUnitWithTimer takes string whichAttach, unit whichUnit, string whichEffect, real duration returns nothing
    local trigger dispatcher = CreateTrigger()
    local real temp = bj_enumDestructableRadius 
    set bj_enumDestructableRadius = duration
    call AddSpecialEffectTargetUnitBJ(whichAttach, whichUnit, whichEffect)
    call TriggerAddAction( dispatcher, function AddSpecialEffectTargetUnitWithTimer_Child )
    call TriggerExecute( dispatcher )
    call DestroyTrigger( dispatcher)
    set bj_enumDestructableRadius = temp
endfunction

Comments

1
Wouldn't this realisation be simplier?
function AddEffectForDuration takes string Attach, unit Target, string Effect, real Duration returns nothing
   local effect e
   call AddSpecialEffectTargetUnitBJ( Attach, Target, Effect)
   set e = GetLastCreatedEffectBJ()
   call TriggerSleepAction( Duration )
   call DestroyEffectBJ( e )
endfunction
Or there is some hidden dangers?