globals
group ReturnGroup = null
endglobals
function GetUnitsOfType takes integer unitid returns group
local group g = CreateGroup()
local unit FoG
local integer index = 0
set ReturnGroup = CreateGroup()
loop
call GroupEnumUnitsOfPlayer(g, Player(index), null)
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
call GroupRemoveUnit(g, FoG)
if GetUnitTypeId(FoG) == unitid then
call GroupAddUnit(ReturnGroup, FoG)
endif
endloop
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call DestroyGroup(g)
set g = null
return ReturnGroup
endfunction