- Joined
- Jun 21, 2012
- Messages
- 431
I want to list a group of units and order them from low to high depending on the distance which are from the source unit, but for some reason something is wrong in the code ... I would like that someone help me with this because the LoL and my work keeps me busy guys :V
JASS:
call GroupEnumUnitsInRange(bj_lastCreatedGroup,sourcex,sourcey,AoE,null)
loop
set u[0]=FirstOfGroup(bj_lastCreatedGroup)
exitwhen(null==u[0])
call GroupRemoveUnit(bj_lastCreatedGroup,u[0])
if(target!=u[0] and IsUnitEnemy(u[0],p))then
set this.next=this.next+1
set dx=GetUnitX(u[0])-sourcex
set dy=GetUnitY(u[0])-sourcey
//We keep the distance of each unit
set d[this.next]=SquareRoot(dx*dx+dy*dy)
set u[this.next]=u[0]
if(this.next==maxCount)then
set u[0]=null
exitwhen true
endif
endif
endloop
loop
set i[1]=0
set i[0]=i[0]+1
loop
set i[1]=i[1]+1
//then we search the distance of each unit low to high
if(0==d[0] or (d[i[1]]<d[0] and null!=u[i[1]]))then
set d[0]=d[i[1]]
set i[2]=i[1]
endif
exitwhen(i[1]==this.next)
endloop
set this.data[i[0]].handle=u[i[2]]
set u[i[2]]=null
exitwhen(i[0]==this.next)
endloop