function GetBestUnit takes group g returns unit
local unit bestUnit = FirstOfGroup(g) //Doing this to have a unit to compare with.
local unit u = null
loop
set u = FirstOfGroup(g)
exitwhen u == null
if SomeValueOf(u) > SomeValueOf(bestUnit) then
set u = bestUnit
endif
call GroupRemoveUnit(g, u)
endloop
set u = null
return bestUnit
endfunction