• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

What is wrong with this trigger?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
There is no syntax error in this trigger, but war3 does not allow me to start game when I use this trigger.

JASS:
function lichking1_actions takes nothing returns nothing
    local group g=CreateGroup()
    local real x=GetSpellTargetX()
    local real y=GetSpellTargetY()
    local unit u
    if GetSpellAbilityId() == 'A421' then
        //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)
            if IsUnitInvulnerable(u) then //when I delete this "if..else..endif" lines, trigger can work. Why?
                call SetUnitInvulnerable(u,false)
            else
                call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u,UNIT_STATE_LIFE)*0.50)
            endif
            set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call IssueTargetOrder(u,"attackonce",GroupPickRandomUnit(lichking2))
            call DestroyGroup(lichking2)
        endloop
        call DestroyGroup(lichking1)
        call DestroyGroup(g)
    endif
    set g=null
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

If I delete the "if...else...endif" in the loop, the trigger can work and game can be started. Why is that? I also changed the"IsUnitVulnerable" to "IsUnitEnemy", still did not work.
I do not see any syntax error.... Help please. Thanks.
 
Level 11
Joined
Oct 11, 2012
Messages
711
hmm..

  • Is IsUnitInvulnerabledefined somewhere? (this is not a JASS native)
  • Try this on the if block: if IsUnitInvulnerable(u) then
Thanks for the reply.
I also tried "IsUnitEnemy" in the if block, it still did not work.

Do you want me to try if IsUnitInvulnerable(u) then ? I think I was using exactly what you want me to. Do I miss something?

Edit:
JassCraft gives me this:
JASS:
function IsUnitInvulnerable takes unit u returns boolean
    return (GetDamageFactor(u,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL)==0)
endfunction

Edit:
It seems "if...else....endif" can not be used in a loop? Only "if...endif" can be used in a loop?
 
Try this (I'm assuming you have the filter function);

JASS:
function IsUnitInvulnerable takes unit Unit returns boolean
    
    local real    Health_Current = GetWidgetLife(Unit)
    local real    Mana_Current   = GetUnitState(Unit,UNIT_STATE_MANA)
    local boolean Check_Health
    
    call SetWidgetLife(Unit,Health_Current + 0.001)    
    if Health_Current != GetWidgetLife(Unit) then
        call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null)
        set Check_Health = (GetWidgetLife(Unit) == Health_Current + 0.001)
    else
        call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null)
        set Check_Health = (GetWidgetLife(Unit) == Health_Current)
        call SetWidgetLife(Unit,Health_Current)
    endif
    
    if Check_Health then
        return not (GetUnitState(Unit,UNIT_STATE_MANA) != Mana_Current)
    endif
    return Check_Health
    
endfunction

function lichking1_actions takes nothing returns boolean
    local group g
    local real x
    local real y
    local unit u
    
    if GetSpellAbilityId() == 'A421' then
        set g = CreateGroup()
        set x = GetSpellTargetX()
        set y = GetSpellTargetY()
        
        //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)
            if IsUnitInvulnerable(u) then //when I delete this "if..else..endif" lines, trigger can work. Why?
                call SetUnitInvulnerable(u,false)
            else
                call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u,UNIT_STATE_LIFE)*0.50)
            endif
            set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call IssueTargetOrder(u,"attackonce",GroupPickRandomUnit(lichking2))
            call DestroyGroup(lichking2)
        endloop
        
        call DestroyGroup(lichking1)
        call DestroyGroup(g)
        
        set u = null
        set g = null
    endif
    
    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))
endfunction
I also STRONGLY suggest using vJass over JASS.
 
Level 11
Joined
Oct 11, 2012
Messages
711
Try this (I'm assuming you have the filter function);

JASS:
function IsUnitInvulnerable takes unit Unit returns boolean
    
    local real    Health_Current = GetWidgetLife(Unit)
    local real    Mana_Current   = GetUnitState(Unit,UNIT_STATE_MANA)
    local boolean Check_Health
    
    call SetWidgetLife(Unit,Health_Current + 0.001)    
    if Health_Current != GetWidgetLife(Unit) then
        call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null)
        set Check_Health = (GetWidgetLife(Unit) == Health_Current + 0.001)
    else
        call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null)
        set Check_Health = (GetWidgetLife(Unit) == Health_Current)
        call SetWidgetLife(Unit,Health_Current)
    endif
    
    if Check_Health then
        return not (GetUnitState(Unit,UNIT_STATE_MANA) != Mana_Current)
    endif
    return Check_Health
    
endfunction

function lichking1_actions takes nothing returns boolean
    local group g
    local real x
    local real y
    local unit u
    
    if GetSpellAbilityId() == 'A421' then
        set g = CreateGroup()
        set x = GetSpellTargetX()
        set y = GetSpellTargetY()
        
        //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)
            if IsUnitInvulnerable(u) then //when I delete this "if..else..endif" lines, trigger can work. Why?
                call SetUnitInvulnerable(u,false)
            else
                call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u,UNIT_STATE_LIFE)*0.50)
            endif
            set lichking2=CreateGroup()
            call GroupAddGroup(lichking1,lichking2)
            call GroupRemoveUnit(lichking2,u)
            call IssueTargetOrder(u,"attackonce",GroupPickRandomUnit(lichking2))
            call DestroyGroup(lichking2)
        endloop
        
        call DestroyGroup(lichking1)
        call DestroyGroup(g)
        
        set u = null
        set g = null
    endif
    
    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))
endfunction
I also STRONGLY suggest using vJass over JASS.

I want to use vJass but don't know how to, need a decent tutorial. LOL

I think your way works! Thanks a lot! Cannot add rep to you right now, will do that when I can.
 
Status
Not open for further replies.
Top