HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Looping Flight

08-30-2006, 03:13 PM#1
Zoxc
Collapse JASS:
function Trig_Flight_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A08S' )
endfunction

function Trig_Flight_Move takes nothing returns nothing
    local timer exp = GetExpiredTimer()
    local unit caster = GetAttachedUnit(exp, "caster")
    local unit diver = GetAttachedUnit(exp, "diver")

    local real targetx = GetAttachedReal(exp, "locx")
    local real targety = GetAttachedReal(exp, "locy")

    local real x = GetUnitX(diver)
    local real y = GetUnitY(diver)
    
    local real dx = targetx - x
    local real dy = targety - y
    
    local real distance = dx * dx + dy * dy
    
    if distance < 100000 then
    
        if not GetAttachedBoolean(exp, "landing") then
            
            call AttachBoolean(exp, "landing", true)
            
            call SetUnitFlyHeight( caster, 0.00, 600.00 )
            call SetUnitFlyHeight( diver, 0.00, 600.00 )
            call SetUnitAnimation( caster, "Attack" )
            
        endif
        
    endif
    
    if distance > 200 then
        
        call SetUnitX(caster, x)
        call SetUnitY(caster, y)
        

    else
        call CleanAttachedVars(exp)
        call PauseTimer(exp)
        call DestroyTimer(exp)
        
        call PauseUnit( caster, false )
        
        call SetUnitInvulnerable(caster ,false)
 
        call AddAreaDamagerForUnit(caster, "Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl", "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl", "origin", GetUnitX(caster), GetUnitY(caster), 100.00 + ( 50.00 * I2R(GetUnitAbilityLevelSwapped('A08S', caster)))  , 1, 2, 220, false, 0)
        
        call SetUnitFlyHeight( diver, 2000.00, 900.00 )
        
        call TriggerSleepAction( 0.60 )

        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" , caster, "origin" ))
  
        call TriggerSleepAction( 1.00 )
        
        
        call RemoveUnit( diver )
                
    endif
    
    set caster = null
    set diver = null
    set exp = null
endfunction

function Trig_Flight_Actions takes nothing returns nothing
    local location target = GetSpellTargetLoc()
    local real targetx = GetLocationX(target)
    local real targety = GetLocationY(target)
    local unit caster = GetSpellAbilityUnit()
    local real casterlocx = GetUnitX(caster)
    local real casterlocy = GetUnitY(caster)
    local real angle = Atan2(targety - casterlocy, targetx - casterlocx)
    local unit diver =  CreateUnit( GetOwningPlayer(caster), 'n01C', GetUnitX(caster), GetUnitY(caster), angle*bj_RADTODEG )
    local timer move = CreateTimer()

    call BJDebugMsg("start")

    call PauseUnit( caster, true )
    call SetUnitInvulnerable(caster ,true)
    call UnitAddAbility( caster, 'Amrf' )
    call UnitRemoveAbility( caster, 'Amrf' )
    
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl" , caster, "origin"))
    
    call SetUnitFacingTimed( caster, angle*bj_RADTODEG, 1.00 )

    call SetUnitAnimation( caster, "Spell Channel" )
    
    call SetUnitFlyHeight( caster, 450.00, 700.00 )
    call SetUnitFlyHeight( diver, 400.00, 700.00 )
    
    call TriggerSleepAction( 0.6 )
    
    call IssuePointOrderLoc( diver, "move", target)
    
    call AttachObject(move, "caster", caster)
    call AttachObject(move, "diver", diver)
    call AttachReal(move, "locx", targetx)
    call AttachReal(move, "locy", targety)
    
    call RemoveLocation(target)
    
    call TimerStart(move, 0.05, true, function Trig_Flight_Move)
    
    set move = null
    set caster = null
    set target = null
    set diver = null
    
endfunction

//===========================================================================
function InitTrig_Flight takes nothing returns nothing
    set gg_trg_Flight = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Flight, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Flight, Condition( function Trig_Flight_Conditions ) )
    call TriggerAddAction( gg_trg_Flight, function Trig_Flight_Actions )
endfunction

call TriggerSleepAction( 0.60 ) seems to exit then function and return to Trig_Flight_Actions and makes a nice loop firework... the con is that you can't move your hero :/

EDIT: Every sleep action exits the function and recalls Trig_Flight_Actions. If there is no sleep actions Trig_Flight_Actions is called when the function ends.
08-30-2006, 03:48 PM#2
Rising_Dusk
Yeah, TriggerSleepAction()s cause returns in timer callbacks.
Remove them and it should run properly assuming nothing else is wrong.
08-30-2006, 03:52 PM#3
Zoxc
Quote:
Originally Posted by Zoxc
If there is no sleep actions Trig_Flight_Actions is called when the function ends.

:(
08-30-2006, 03:59 PM#4
blu_da_noob
Fixing it is pretty simple. Make your timer callback function like this:

Collapse JASS:
function TimerCallBack takes nothing returns nothing
call ExecuteFunc("Youractualfunctionname")
endfunction

This even keeps event response (GetExpiredTimer()) and allows for waits.
08-30-2006, 04:23 PM#5
Zoxc
Using ExecuteFunc makes the function recall TimerCallBack instead of Trig_Flight_Actions.
09-25-2006, 05:31 PM#6
Zoxc
*bump* *dance*