HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What's wrong with this trigger?

11-26-2003, 08:40 PM#1
Oinkerwinkle
This trigger is intended to emulate the Land ability of Starcraft.
Code:
function Trig_Land_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00B' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Land_Actions takes nothing returns nothing
    local effect array dust
    local integer i
    local unit lifted = GetTriggerUnit()
    local location liftOffPoint = GetUnitLoc(lifted)
    call DisplayTextToForce( GetPlayersAll(), "Trigger starting" )
    call SetUnitFlyHeightBJ( lifted, 0.00, 40.00 )
    set i = 0
    loop
        call AddSpecialEffectLocBJ( PolarProjectionBJ(liftOffPoint, 
            [i]...[/i]GetRandomReal(170.00, 300.00), GetRandomDirectionDeg()), 
            [i]...[/i]"Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" )
        set dust[i]=GetLastCreatedEffectBJ()
        set i = i + 1
        exitwhen i>10
    endloop
    call PauseUnitBJ( true, lifted )
    call TriggerSleepAction( 3.00 )
    call PauseUnitBJ( false, lifted )
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00Q' ) then  //Command Center
        call UnitRemoveAbilityBJ( 'S001', lifted )
        call UnitAddAbilityBJ( 'S006', lifted )
    endif
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00S' ) then  //Barracks
        call UnitRemoveAbilityBJ( 'S000', lifted )
        call UnitAddAbilityBJ( 'S007', lifted )
    endif
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00T' ) then  //Factory
        call UnitRemoveAbilityBJ( 'S003', lifted )
        call UnitAddAbilityBJ( 'S008', lifted )
    endif
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00U' ) then  //Starport
        call UnitRemoveAbilityBJ( 'S004', lifted )
        call UnitAddAbilityBJ( 'S009', lifted )
    endif
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00V' ) then  //Science Facility
        call UnitRemoveAbilityBJ( 'S005', lifted )
        call UnitAddAbilityBJ( 'S00A', lifted )
    endif
    if ( GetUnitTypeId(GetTriggerUnit()) == 'h00R' ) then  //Engineering Bay
        call UnitRemoveAbilityBJ( 'S002', lifted )
        call UnitAddAbilityBJ( 'S00B', lifted )
    endif
    set i=0
    loop
        call DestroyEffectBJ( dust[i] )
        set i = i + 1
        exitwhen i>10
    endloop
    call IssuePointOrderLocBJ( lifted, "setrally", GetUnitLoc(lifted) )
endfunction

//===========================================================================
function InitTrig_Land takes nothing returns nothing
    set gg_trg_Land = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Land, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Land, Condition( function Trig_Land_Conditions ) )
    call TriggerAddAction( gg_trg_Land, function Trig_Land_Actions )
endfunction

It detects when a dummy ability, based off Tiny Blacksmith, is cast, and then adds the appropriate morphing ability, based off Chaos, to the unit. That if/then part chooses the right abilities. Here is the problem: Sometimes, the trigger works perfectly and it lands. Other times, it floats down to the ground, displaying its nice dust effect, and then loops. It seems to look infinitely until a ground unit walks under it. Does anyone have an idea as to what is wrong?

I can tell that it's looping because it keeps saying "Trigger starting" and the dust appears and disappears again and again.
11-26-2003, 09:01 PM#2
AIAndy
It might be the PauseUnit. Try to disable the trigger at the end of Trig_Land_Actions and then reenable it after a short time.

like

local timer t = CreateTimer()
...
call TimerStart(t, 0, false, function ReenableLandTrigger)

where ReenableLandTrigger is just a simple function that Enables the land trigger.
11-26-2003, 09:28 PM#3
Oinkerwinkle
Thank you very much, it worked!