Ninja Errors

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright so here is the code for one of my spells.

JASS:
scope Meatshield initializer Init

globals
    private group MSG = CreateGroup()
    private timer tim = CreateTimer()
    private group msg = CreateGroup()
    private player p
    private group TempGroup = CreateGroup()
    private MS array MSs
    private integer total = 0
endglobals

struct MS
unit Caster
unit Target
endstruct

private function filter takes nothing returns boolean
    local boolean Verdict
    local integer i = 0
    local Xot xot
    set Verdict = IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()),p)
    
    if Verdict == true then
        set Verdict = not(IsUnitAffectedBy(GetFilterUnit(),"MS"))
    endif
    return Verdict
endfunction
    
private function tick takes nothing returns nothing
    local unit u
    local unit uu
    local boolexpr b = Condition(function filter)
    local real angle
    call GroupAddGroup(MSG,TempGroup)
    loop
        set u = FirstOfGroup(TempGroup)
        set p = GetOwningPlayer(u)
        exitwhen u == null
        call GroupClear(msg)
        call GroupEnumUnitsInRange(msg,GetUnitX(u),GetUnitY(u),250,b)
        loop
            set uu = FirstOfGroup(msg)
            exitwhen uu == null
            set angle = bj_RADTODEG * Atan2(GetUnitY(uu) - GetUnitY(u), GetUnitX(uu) - GetUnitX(u))
            call UnitDamageTarget(u,uu,(-10+20*GetUnitAbilityLevel(u,'A00A'))+GetHeroStr(u,true),true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            call CreateXot(u,uu,3,.03,2,"Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl","origin",ATTACK_TYPE_HERO,angle,"MS",false,3)
            call GroupRemoveUnit(msg,uu)
        endloop
        call GroupRemoveUnit(TempGroup,u)
    endloop
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local MS ms
    if GetSpellAbilityId() == 'A00A' then
        set MSs[total] = MS.create()
        set ms = MSs[total]
        set ms.Target = GetSpellTargetUnit()
        set ms.Caster = GetTriggerUnit()
        set total = total + 1
        call SetUnitPathing(u,false)
        call IssueTargetOrder(u,"attack",GetSpellTargetUnit())
        call UnitAddAbility(u,'A00B')
        call GroupAddUnit(MSG,u)
        call TimerStart(tim,.5,true,function tick)
        call TriggerRegisterUnitEvent(Trg,GetSpellTargetUnit(),EVENT_UNIT_ATTACKED)
    endif
endfunction
    
private function Order takes nothing returns nothing
    local integer i = 0
    local integer I = 0
    local unit u
    local unit TU = GetTriggerUnit()
    local MS ms
    call GroupClear(TempGroup)
    call GroupAddGroup(MSG,TempGroup)
    set u = FirstOfGroup(TempGroup)
    loop
        set u = FirstOfGroup(TempGroup)
        exitwhen u == null
        if u == TU then
            call GroupRemoveUnit(MSG, TU)
            set u = null
            call SetUnitPathing(TU,true)
            call UnitRemoveAbility(TU,'A00B')
            call UnitRemoveAbility(TU,'B001')
            loop
                exitwhen I == total
                set ms = MSs[I]
                if ms.Caster == GetTriggerUnit() then
                    set ms.Caster = null
                    set ms.Target = null
                    set total = total - 1
                    set MSs[I] = MSs[total]
                endif
                set I = I + 1
            endloop
        else
            call GroupRemoveUnit(TempGroup,u)
        endif
    endloop
endfunction

private function Attacked takes nothing returns nothing
    local integer i = 0
    local MS ms
    call BJDebugMsg("hon")
    loop
        exitwhen i == total
        set ms = MSs[i]
        if ms.Caster == GetAttacker() then
            call DDAdd(GetTriggerUnit(),6,1)
            call CreateXot(GetTriggerUnit(),GetTriggerUnit(),0,6,6,"","",null, 0,"MSTimer",false,5)
            call GroupRemoveUnit(MSG, GetAttacker())
            call SetUnitPathing(GetAttacker(),true)
            call UnitRemoveAbility(GetAttacker(),'A00B')
            call UnitRemoveAbility(GetAttacker(),'B001')
            set ms.Caster = null
            set ms.Target = null
            set total = total - 1
            set MSs[i] = MSs[total]
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger tt = CreateTrigger()
    local trigger Trg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Actions)
    call TriggerAddAction(Trg,function Attacked)
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddAction(tt,function Order)
    call TimerStart(tim,.5,true,function tick)
endfunction
endscope

The line where I add an event to the trigger Trg errors out when compiling saying that Trg is an undeclared variable. But I declare when I declare all the other triggers ><.

What stupid mistake am I missing.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright w/e I got the trigger name working but now there is a new problem. The function Attacked (which is the action for the ugh_Trg trigger) is never called upon the target getting attacked. I clearly add the event in the actions function, but it never calls the Attack function. I added a test event as well to see if the trigger was even working, and when I hit esc it did call Attacked so.... there is something wrong with trying to add that event but I am not sure what =/.

JASS:
scope Meatshield initializer Init

globals
    private group MSG = CreateGroup()
    private timer tim = CreateTimer()
    private group msg = CreateGroup()
    private player p
    private group TempGroup = CreateGroup()
    private MS array MSs
    private integer total = 0
endglobals

struct MS
unit Caster
unit Target
endstruct

private function filter takes nothing returns boolean
    local boolean Verdict
    local integer i = 0
    local Xot xot
    set Verdict = IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()),p)
    
    if Verdict == true then
        set Verdict = not(IsUnitAffectedBy(GetFilterUnit(),"MS"))
    endif
    return Verdict
endfunction
    
private function tick takes nothing returns nothing
    local unit u
    local unit uu
    local boolexpr b = Condition(function filter)
    local real angle
    call GroupAddGroup(MSG,TempGroup)
    loop
        set u = FirstOfGroup(TempGroup)
        set p = GetOwningPlayer(u)
        exitwhen u == null
        call GroupClear(msg)
        call GroupEnumUnitsInRange(msg,GetUnitX(u),GetUnitY(u),250,b)
        loop
            set uu = FirstOfGroup(msg)
            exitwhen uu == null
            set angle = bj_RADTODEG * Atan2(GetUnitY(uu) - GetUnitY(u), GetUnitX(uu) - GetUnitX(u))
            call UnitDamageTarget(u,uu,(-10+20*GetUnitAbilityLevel(u,'A00A'))+GetHeroStr(u,true),true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            call CreateXot(u,uu,3,.03,2,"Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl","origin",ATTACK_TYPE_HERO,angle,"MS",false,3)
            call GroupRemoveUnit(msg,uu)
        endloop
        call GroupRemoveUnit(TempGroup,u)
    endloop
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local MS ms
    if GetSpellAbilityId() == 'A00A' then
        set MSs[total] = MS.create()
        set ms = MSs[total]
        set ms.Target = GetSpellTargetUnit()
        set ms.Caster = GetTriggerUnit()
        set total = total + 1
        call SetUnitPathing(u,false)
        call IssueTargetOrder(u,"attack",GetSpellTargetUnit())
        call UnitAddAbility(u,'A00B')
        call GroupAddUnit(MSG,u)
        call TimerStart(tim,.5,true,function tick)
        call BJDebugMsg("1")
        call TriggerRegisterUnitEvent(udg_Trg,GetSpellTargetUnit(),EVENT_UNIT_ATTACKED )
        call TriggerRegisterPlayerEventEndCinematic(udg_Trg, Player(0) )
        call BJDebugMsg("2")
    endif
endfunction
    
private function Order takes nothing returns nothing
    local integer i = 0
    local integer I = 0
    local unit u
    local unit TU = GetTriggerUnit()
    local MS ms
    call GroupClear(TempGroup)
    call GroupAddGroup(MSG,TempGroup)
    set u = FirstOfGroup(TempGroup)
    loop
        set u = FirstOfGroup(TempGroup)
        exitwhen u == null
        if u == TU then
            call GroupRemoveUnit(MSG, TU)
            set u = null
            call SetUnitPathing(TU,true)
            call UnitRemoveAbility(TU,'A00B')
            call UnitRemoveAbility(TU,'B001')
            loop
                exitwhen I == total
                set ms = MSs[I]
                if ms.Caster == GetTriggerUnit() then
                    set ms.Caster = null
                    set ms.Target = null
                    set total = total - 1
                    set MSs[I] = MSs[total]
                endif
                set I = I + 1
            endloop
        else
            call GroupRemoveUnit(TempGroup,u)
        endif
    endloop
endfunction

private function Attacked takes nothing returns nothing
    local integer i = 0
    local MS ms
    call BJDebugMsg("Barney")
    loop
        exitwhen i == total
        set ms = MSs[i]
        if ms.Caster == GetAttacker() then
            call DDAdd(GetTriggerUnit(),6,1)
            call CreateXot(GetTriggerUnit(),GetTriggerUnit(),0,6,6,"","",null, 0,"MSTimer",false,5)
            call GroupRemoveUnit(MSG, GetAttacker())
            call SetUnitPathing(GetAttacker(),true)
            call UnitRemoveAbility(GetAttacker(),'A00B')
            call UnitRemoveAbility(GetAttacker(),'B001')
            set ms.Caster = null
            set ms.Target = null
            set total = total - 1
            set MSs[i] = MSs[total]
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================

private function Init takes nothing returns nothing
    local trigger Trg = CreateTrigger()
    local trigger t = CreateTrigger()
    local trigger tt = CreateTrigger()
    set udg_Trg = Trg
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Actions)
    call TriggerAddAction(udg_Trg,function Attacked)
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddAction(tt,function Order)
    call TimerStart(tim,.5,true,function tick)
endfunction
endscope
 
Last edited:
Status
Not open for further replies.
Top