• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Why this trigger sometimes work sometimes not? Thanks for the help

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
The following trigger works most of the time, but sometimes it does not fire. I can't figure out why... please help

JASS:
function lichking1_actions takes nothing returns nothing
    local group g=CreateGroup()
    local real x=GetSpellTargetX()
    local real y=GetSpellTargetY()
    local unit u
    local integer level=GetUnitAbilityLevel(gg_unit_U00X_0001,'A421')*5
    local real level1=I2R(level)*0.01
    local real life
    if GetSpellAbilityId() == 'A421' then
        call BJDebugMsg("start")
        //call GroupEnumUnitsInRange(g,x,y,800.,null)
        call GroupEnumUnitsInRange(g,x,y,800.,Condition(function Group_TrgU_Filter))
        //set lichking1=CreateGroup()
        call GroupAddGroup(g,lichking1)
        loop
            set u=FirstOfGroup(g)
            exitwhen u==null
            call GroupRemoveUnit(g,u)
            call SetUnitInvulnerable(u,false)
            set life=GetUnitState(u,UNIT_STATE_LIFE)
            call SetUnitState(u, UNIT_STATE_LIFE, life-life*level1)
            //set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call BJDebugMsg("add group")
            if GetRandomInt(1,100)<=level then
                call IssueTargetOrder(u,"attack",GroupPickRandomUnit(lichking2))
                call BJDebugMsg("attack")
            endif
            call GroupClear(lichking2)
        endloop
        call GroupClear(lichking1)
        call DestroyGroup(g)
    endif
    set g=null
    //return false
endfunction

function InitTrig_lichking1 takes nothing returns nothing
    set gg_trg_lichking1=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_lichking1, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    //call TriggerAddCondition(gg_trg_lichking1, Condition(function lichking1_actions))
    call TriggerAddAction(gg_trg_lichking1,function lichking1_actions)
endfunction

I have tried to replace GroupClear with DestroyGroup, the result is the same. The spell is based on channel and it is an AOE spell, if that matters. "lichking1" and "lichking2" are global variables.
 
Does this display anything?

JASS:
function lichking1_actions takes nothing returns nothing
    local group g
    local real x    
    local real y
    local unit u
    local integer level
    local real level1
    local real life
    
     call BJDebugMsg("lichking1_actions started")
     
    if GetSpellAbilityId() == 'A421' then
        call BJDebugMsg("Correct Spell has been cast.")
        set g      = CreateGroup()
        set x      = GetSpellTargetX()
        set y      = GetSpellTargetY()
        set level  = GetUnitAbilityLevel(gg_unit_Hmkg_0000,'A421')*5
        set level1 = I2R(level)*0.01
        
        call BJDebugMsg("start spell")
        //call GroupEnumUnitsInRange(g,x,y,800.,null)
        call GroupEnumUnitsInRange(g,x,y,800.,Condition(function Group_TrgU_Filter))
        //set lichking1=CreateGroup()
        call GroupAddGroup(g,lichking1)
        loop
            set u=FirstOfGroup(g)
            exitwhen u==null
            call GroupRemoveUnit(g,u)
            call SetUnitInvulnerable(u,false)
            set life=GetUnitState(u,UNIT_STATE_LIFE)
            call SetUnitState(u, UNIT_STATE_LIFE, life-life*level1)
            //set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call BJDebugMsg("add group")
            if GetRandomInt(1,100)<=level then
                call IssueTargetOrder(u,"attack",GroupPickRandomUnit(lichking2))
                call BJDebugMsg("attack")
            endif
            call GroupClear(lichking2)
        endloop
        call GroupClear(lichking1)
        call DestroyGroup(g)
    endif
    set g=null
    //return false
endfunction

function InitTrig_lichking1 takes nothing returns nothing
    set gg_trg_lichking1=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_lichking1, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    //call TriggerAddCondition(gg_trg_lichking1, Condition(function lichking1_actions))
    call TriggerAddAction(gg_trg_lichking1,function lichking1_actions)
endfunction
 
Level 11
Joined
Oct 11, 2012
Messages
711
Does this display anything?

JASS:
function lichking1_actions takes nothing returns nothing
    local group g
    local real x    
    local real y
    local unit u
    local integer level
    local real level1
    local real life
    
     call BJDebugMsg("lichking1_actions started")
     
    if GetSpellAbilityId() == 'A421' then
        call BJDebugMsg("Correct Spell has been cast.")
        set g      = CreateGroup()
        set x      = GetSpellTargetX()
        set y      = GetSpellTargetY()
        set level  = GetUnitAbilityLevel(gg_unit_Hmkg_0000,'A421')*5
        set level1 = I2R(level)*0.01
        
        call BJDebugMsg("start spell")
        //call GroupEnumUnitsInRange(g,x,y,800.,null)
        call GroupEnumUnitsInRange(g,x,y,800.,Condition(function Group_TrgU_Filter))
        //set lichking1=CreateGroup()
        call GroupAddGroup(g,lichking1)
        loop
            set u=FirstOfGroup(g)
            exitwhen u==null
            call GroupRemoveUnit(g,u)
            call SetUnitInvulnerable(u,false)
            set life=GetUnitState(u,UNIT_STATE_LIFE)
            call SetUnitState(u, UNIT_STATE_LIFE, life-life*level1)
            //set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call BJDebugMsg("add group")
            if GetRandomInt(1,100)<=level then
                call IssueTargetOrder(u,"attack",GroupPickRandomUnit(lichking2))
                call BJDebugMsg("attack")
            endif
            call GroupClear(lichking2)
        endloop
        call GroupClear(lichking1)
        call DestroyGroup(g)
    endif
    set g=null
    //return false
endfunction

function InitTrig_lichking1 takes nothing returns nothing
    set gg_trg_lichking1=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_lichking1, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    //call TriggerAddCondition(gg_trg_lichking1, Condition(function lichking1_actions))
    call TriggerAddAction(gg_trg_lichking1,function lichking1_actions)
endfunction

I will try this, thnx. I updated my post, only "start" got executed if using my code.
 
Level 11
Joined
Oct 11, 2012
Messages
711
The group may be getting destroyed, try adding some more debug messages making sure variables aren't null.

Maybe tryset bj_wantDestroyGroup = falsein the beginning.

Does"lichking1_actions started"display?

Yes, it was displayed and also the "start spell" message, but not the following.

Edit:
@TriggerHappy, alright, I will try that, thnx a lot. +Rep
 
Status
Not open for further replies.
Top