I have a script here:
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?
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?