HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Groups in JASS

11-04-2006, 12:53 PM#1
n13astra
Hey guys,

I was just optimising code in JASS when i came across something i didnt know how to do.

Basically, its the ForGroupBJ function.

Collapse JASS:
call ForGroupBJ(GetUnitsInRangeOfLocMatching(400.00, GetUnitLoc(un_CastingUnit), Condition(Trig_Star_Shower_Func006Func008001003)), function Trig_Star_Shower_Func006Func008002 )

That is the function call and as you can see it calls another function as a condition check. The problem i'm having is that the other function calls use a local variable which stores the casting unit. Obviously, i cannot pass it into the function within the ForGroupBJ function, so how do i actaully do that without having those extra functions??


FULL CODE
Collapse JASS:
function Trig_Star_Shower_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A06G' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Star_Shower_Func006Func008001003 takes unit un_CastingUnit returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(un_CastingUnit)) == true )
endfunction

//function Trig_Star_Shower_Func006Func008002 takes nothing returns nothing
//    call UnitDamageTargetBJ( un_CastingUnit, GetEnumUnit(), 500.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
//endfunction

function Trig_Star_Shower_Actions takes nothing returns nothing
    local unit un_CastingUnit = GetSpellAbilityUnit()
    local integer i = 50
    local group G = CreateGroup()

    call PauseUnitBJ( true, un_CastingUnit)
    call UnitAddAbilityBJ( 'Amrf', un_CastingUnit)
    call SetUnitFlyHeightBJ(un_CastingUnit, 600.00, 1000.00 )
    call TriggerSleepAction( 1.00 )
    loop
        exitwhen i <= 0
        call SetUnitFacingTimed(un_CastingUnit, ( GetUnitFacing(un_CastingUnit) + 20.00 ), 0 )
        call CreateNUnitsAtLoc( 1, 'h022', Player(PLAYER_NEUTRAL_PASSIVE), PolarProjectionBJ(GetUnitLoc(un_CastingUnit), 10.00, GetUnitFacing(un_CastingUnit)), GetUnitFacing(un_CastingUnit) )
        call IssuePointOrderLocBJ( GetLastCreatedUnit(), "move", PolarProjectionBJ(GetUnitLoc(GetLastCreatedUnit()), GetRandomReal(100.00, 400.00), GetUnitFacing(GetLastCreatedUnit())) )
        call UnitApplyTimedLifeBJ( 1.30, 'BTLF', GetLastCreatedUnit() )
        call SetUnitFlyHeightBJ( GetLastCreatedUnit(), 0.00, 522.00 )
        call TriggerSleepAction( 0.02 )
//        call ForGroupBJ(GetUnitsInRangeOfLocMatching(400.00, GetUnitLoc(un_CastingUnit), Condition(Trig_Star_Shower_Func006Func008001003)), function Trig_Star_Shower_Func006Func008002 )
        set i = i - 1
    endloop
    call SetUnitFlyHeightBJ(un_CastingUnit, 0.00, 1000.00 )
    call UnitRemoveAbilityBJ( 'Amrf', un_CastingUnit)
    call TriggerSleepAction( 0.20 )
    call PauseUnitBJ( false, un_CastingUnit)
endfunction

//===========================================================================
function InitTrig_Star_Shower takes nothing returns nothing
    set gg_trg_Star_Shower = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Star_Shower, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Star_Shower, Condition( function Trig_Star_Shower_Conditions ) )
    call TriggerAddAction( gg_trg_Star_Shower, function Trig_Star_Shower_Actions )
endfunction

11-04-2006, 12:55 PM#2
DioD
use globals for data transfer
11-04-2006, 12:56 PM#3
The)TideHunter(
You can pass it, all the event responses are still there because its Condition(), its still in that functions code. If you had a wait in your code, that would break the event responses, so just dont use waits when calling other functions from the triggering function.

EDIT: Oh, you did use a wait in your loop, that would cause it to not work, remove the wait, and it should work.
11-04-2006, 01:06 PM#4
blu_da_noob
GetTriggerUnit() should work after a wait, so change your condition to:
Collapse JASS:
function Trig_Star_Shower_Func006Func008001003 takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
endfunction
and you can then use that ForGroup line (mind your extra bracket you have in there somewhere).
11-04-2006, 10:40 PM#5
n13astra
Super, worked well.

Want to avoid globals as much as i can.

Thanks Guys!