• 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.

[Trigger] Spell Target Trigger not working

Status
Not open for further replies.
Level 2
Joined
Jun 14, 2018
Messages
9
Hey , I'm new to jass and still learning , I could make some triggers but this one is not working for me,

We have two groups of units , each group belongs to an player enemy to the other , the goal is that a random dragonhawk unit in the player (0) group will leash a random unit from the other player(1) group
, also keep in mind that I made aerial shackles (maigcleash) able to target ground units , I added the ("if") to make sure they do not cast it right away and added PolledWait to make a cooldown since there are more than one dragonhawk that can also cast the spell.

JASS:
Code (vJASS)

function targetcond5 takes nothing returns boolean
    return ( GetUnitTypeId(GetTriggerUnit()) == 'hdhw' )
endfunction
function targetcond1 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction
function targetcond2 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit() , Player(0)) == true )
endfunction
function cand takes nothing returns boolean
    return GetBooleanAnd( targetcond1(), targetcond2() )
endfunction
function targetcond3 takes nothing returns boolean
    return ( IsUnitOwnedByPlayer(GetFilterUnit(), Player(0)))
endfunction
function cand2 takes nothing returns boolean
    return GetBooleanAnd( targetcond3(), targetcond5() )
endfunction
function targetcond4 takes nothing returns boolean
    return ( IsUnitOwnedByPlayer(GetAttackedUnitBJ(), Player(0)))
endfunction
function Trig_Skywrath_Mage_Actions takes nothing returns nothing
    local group skms = CreateGroup()
    local group atrtempg = CreateGroup()
    local unit atemp = GetAttackedUnitBJ()
    local location temploc = GetUnitLoc(atemp)
    local real rcounter = GetRandomReal(1, 10)
    call GroupEnumUnitsInRangeOfLoc(skms, temploc, 500, Condition(function cand2))
    call GroupEnumUnitsInRangeOfLoc(atrtempg, temploc, 500, Condition(function cand))
        if rcounter < 2.5 then
        call IssueTargetOrderBJ(GroupPickRandomUnit(skms), "magicleash", GroupPickRandomUnit(atrtempg))
    call DestroyGroup(skms)
    call DestroyGroup(atrtempg)
        call DisableTrigger(gg_trg_Skywrath_Mage)
        call PolledWait(30)
        call EnableTrigger(gg_trg_Skywrath_Mage)
        endif
endfunction
function InitTrig_Skywrath_Mage takes nothing returns nothing
    set gg_trg_Skywrath_Mage = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Skywrath_Mage, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Skywrath_Mage, Condition(function targetcond4))
    call TriggerAddAction( gg_trg_Skywrath_Mage, function Trig_Skywrath_Mage_Actions )
endfunction[code=jass]
 
Level 42
Joined
Feb 27, 2007
Messages
5,306
targetcond5 uses GetTriggerUnit() instead of GetFilterUnit().

There is no reason to use GetBooleanAnd... just use the and keyword. You don’t have to use multiple filter functions for each condition, that’s just the dumb way GUI does it.
JASS:
function filtering takes nothing returns boolean
  local boolean a = something()
  local boolean b = somethingelse()
  local boolean c = somethirdthing()

  return a and b and c //or is also a keyword and you can use () to group expressions like “(a and b) or c”

  //you could also do this:
  return something() and somethingelse() and somethirdthing()
endfunction
 
Level 2
Joined
Jun 14, 2018
Messages
9
targetcond5 uses GetTriggerUnit() instead of GetFilterUnit().
I totally missed that , it was the problem and after fixing it the trigger now works!

There is no reason to use GetBooleanAnd... just use the and keyword. You don’t have to use multiple filter functions for each condition, that’s just the dumb way GUI does it.

ah I didn't think of that at all , thank you :) +rep
 
Status
Not open for further replies.
Top