• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] Why won't this work

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
I'm trying to make a spell that will target an area, and make all units in the area invulnerable and unable to move/attack/anything for 4,5,6,7 seconds. As of now the units become invulnerable and unable to do anything, but the effects are permanent and the special effect that's created is never destroyed and I don't know why. Can anyone help?

Here's the Trigger:


JASS:
function Trig_Stasis_Field_New_Copy_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A018'
endfunction

function Trig_Stasis_Field_New_Copy_Func003Func005Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A018', GetTriggerUnit()) == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Stasis_Field_New_Copy_Func003Func005Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A018', GetTriggerUnit()) == 3 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Stasis_Field_New_Copy_Func003Func005Func001C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A018', GetTriggerUnit()) == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Stasis_Field_New_Copy_Func003Func005C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A018', GetTriggerUnit()) == 1 ) ) then
        return false
    endif
    return true
endfunction

function CheckLevel takes nothing returns nothing
    local unit TempUnit = GetEnumUnit()
    local effect spfx
    call SetUnitInvulnerable( TempUnit, true )
    call PauseUnit( TempUnit, true )
    set spfx = AddSpecialEffectTargetUnitBJ( "origin", TempUnit, "Abilities\\Spells\\Human\\ManaShield\\ManaShieldCaster.mdl" )
    if ( Trig_Stasis_Field_New_Copy_Func003Func005C() ) then
        call TriggerSleepAction( 4.00 )
    else
        if ( Trig_Stasis_Field_New_Copy_Func003Func005Func001C() ) then
            call TriggerSleepAction( 5.00 )
        else
            if ( Trig_Stasis_Field_New_Copy_Func003Func005Func001Func001C() ) then
                call TriggerSleepAction( 6.00 )
            else
                if ( Trig_Stasis_Field_New_Copy_Func003Func005Func001Func001Func001C() ) then
                    call TriggerSleepAction( 7.00 )
                else
                endif
            endif
        endif
    endif
    call SetUnitInvulnerable( TempUnit, false )
    call PauseUnit( TempUnit, false )
    call DestroyEffect( spfx )
    set spfx = null
    set TempUnit = null
endfunction

function Trig_Stasis_Field_New_Copy_Actions takes nothing returns nothing
    local location TempPoint = GetSpellTargetLoc()
    local group TempGroup = GetUnitsInRangeOfLocAll(300.00, TempPoint)
    call ForGroup( TempGroup, function CheckLevel )
    call RemoveLocation(TempPoint)
    call DestroyGroup(TempGroup)
endfunction

//===========================================================================
function InitTrig_Stasis_Field_New_Copy takes nothing returns nothing
    set gg_trg_Stasis_Field_New_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stasis_Field_New_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stasis_Field_New_Copy, Condition( function Trig_Stasis_Field_New_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Stasis_Field_New_Copy, function Trig_Stasis_Field_New_Copy_Actions )
endfunction
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You are using call ForGroup( TempGroup, function CheckLevel )
Not that is wrong, but you should not use TriggerSleepAction inside it.
The logic behind it:
Trigger fires, for group is called, goes to the first unit of the group, than calls the CheckLevel function for the first unit. And then it waits. And waits. Then unpauses it.Then goes to the second unit and waits and waits. And so on ...
Here is how to do it:
JASS:
function Trig_Stasis_Field_New_Copy_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A018'
endfunction


function CheckLevel2 takes nothing returns nothing
    local unit TempUnit = GetEnumUnit()
    local effect spfx
    call SetUnitInvulnerable( TempUnit, false )
    call PauseUnit( TempUnit, false )
    set TempUnit = null
endfunction

function CheckLevel takes nothing returns nothing
    local unit TempUnit = GetEnumUnit()
    local effect spfx
    call SetUnitInvulnerable( TempUnit, true )
    call PauseUnit( TempUnit, true )
    set TempUnit = null
endfunction

function Trig_Stasis_Field_New_Copy_Actions takes nothing returns nothing
    local location TempPoint = GetSpellTargetLoc()
    local group TempGroup = GetUnitsInRangeOfLocAll(300.00, TempPoint)
    call ForGroup( TempGroup, function CheckLevel )
    call TriggerSleepAction(GetUnitAbilityLevelSwapped('A018', GetTriggerUnit())+3)
    call ForGroup( TempGroup, function CheckLevel2 )
    call RemoveLocation(TempPoint)
    call DestroyGroup(TempGroup)
    set TempGroup=null
    set TempPoint=null
endfunction

//===========================================================================
function InitTrig_Stasis_Field_New_Copy takes nothing returns nothing
    set gg_trg_Stasis_Field_New_Copy = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stasis_Field_New_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stasis_Field_New_Copy, Condition( function Trig_Stasis_Field_New_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Stasis_Field_New_Copy, function Trig_Stasis_Field_New_Copy_Actions )
endfunction
If you want to add special effect, then this would have to be done in a different manner:
JASS:
function Trig_Stasis_Field_New_Copy_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A018'
endfunction

function Trig_Stasis_Field_New_Copy_Actions takes nothing returns nothing
    local location TempPoint = GetSpellTargetLoc()
    local group TempGroup = GetUnitsInRangeOfLocAll(300.00, TempPoint)
    local group TempGroup2 = CreateGroup()
    local unit u
    local effect array efs
    local integer i=0
    loop
    set u=FirstOfGroup(TempGroup)
    exitwhen u==null
    call SetUnitInvulnerable( TempUnit, true )
    call PauseUnit( TempUnit, true )
    set efs[i] = AddSpecialEffectTarget( u, "Abilities\\Spells\\Human\\ManaShield\\ManaShieldCaster.mdl", "origin" )
    call GroupRemoveUnit(TempGroup,u)
    call GroupAddUnit(TempGroup2,u)
    set i=i+1
    endloop
    call TriggerSleepAction(GetUnitAbilityLevelSwapped('A018', GetTriggerUnit())+3)
    set i=0
    loop
    set u=FirstOfGroup(TempGroup)
    exitwhen u==null
    call SetUnitInvulnerable( TempUnit, false )
    call PauseUnit( TempUnit, false )
    call DestroyEffect( efs[i])
    set efs[i]=null
    call GroupRemoveUnit(TempGroup,u)
    set i=i+1
    endloop
    call RemoveLocation(TempPoint)
    call DestroyGroup(TempGroup)
    set TempGroup=null
    set TempPoint=null
endfunction
 
Status
Not open for further replies.
Top