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

[vJASS] GroupEnumUnits not including AI units

Status
Not open for further replies.
Level 2
Joined
Jun 5, 2014
Messages
11
I have a script here:

JASS:
scope Refresh initializer Init

    globals
        private unit HeroPickup
        group Targets
    endglobals

    function Filter_Hero takes nothing returns boolean
        return IsUnitType( GetFilterUnit(), UNIT_TYPE_HERO )
    endfunction

    function Filter_Item takes nothing returns boolean
        return GetWidgetLife( GetFilterItem() ) > 0
    endfunction

    private function Hero_Pickup takes nothing returns nothing
        call UnitAddItem( HeroPickup, GetEnumItem() )
    endfunction

    private function Auto_Pickup takes nothing returns nothing
        set HeroPickup = GetEnumUnit()
        call MoveRectTo( gg_rct_Pickup_Range, GetUnitX(GetEnumUnit()), GetUnitY(GetEnumUnit()) )
        call EnumItemsInRect( gg_rct_Pickup_Range, Condition( function Filter_Item), function Hero_Pickup )
        set HeroPickup = null
    endfunction
    
    private function TimerLoop takes nothing returns nothing
        call GroupClear( Targets )
        call GroupEnumUnitsInRect( Targets, bj_mapInitialPlayableArea, Condition( function Filter_Hero ) )
        call ForGroup( Targets, function Auto_Pickup )
    endfunction

    private function Init takes nothing returns nothing
     local timer T = NewTimer()
     local timer T_Slow = NewTimer()
        call TimerStart( T, 0.02, true, function TimerLoop )
        set T = null
    endfunction
    
endscope

This script runs every 0.02 seconds, grabs all heroes in the map, moves a temporary rect, checks if there are any items in the rect, and gives those items to the hero.

It runs fine on player-controlled units, however it does not work on computer-controlled units. I used BJDebugMsg() to print out the names those affected by the function and it includes the units. It just doesnt do its job. Any help?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
There is no way it works for any units.In globals block you must initialize Targets like this.

group Targets = CreateGroup()

and you don't need to call GroupClear before GroupEnumUnits, just extra.
 
Status
Not open for further replies.
Top