<- CRPL reference <- Unit Commands

GetAllUnitsInRange

(or GAUIR)

ArgumentsResultNotation
Coordinates, range, square?Number of units in range x1 y1 f1 b1 – u1 u2… un n

Description

Returns the unit UID's of all units (including player/enemy and flying/landed) that are within range. The function pushes the n UID's onto the stack followed by the integer n, where n is the number of units.

If “square?” is set to TRUE, the command uses a square range instead of the usual circular one.

Examples

Find all CRPL cores on the map

#Standard Notation
once
	0 0 9999 TRUE GetAllUnitsInRange 0 do
		->unit

		<-unit GetUnitType "CRPLCORE" eq if
			"Found a CRPL core: " <-unit Trace2
		endif
	loop
endonce
#Warp Notation
once
	GetAllUnitsInRange(0 0 9999 TRUE) 0 do
		->unit
		if(GetUnitType(<-unit) "CRPLCORE" eq)
			Trace2("Found a CRPL core: " <-unit)
		endif
	loop
endonce

Destroy every unit in range of the core this script is attached to

#Standard Notation
CurrentCoords 10 FALSE GetAllUnitsInRange 0 do
	->unit

        <-unit CONST_DESTROYMODE GetUnitAttribute ->destroyMode

        <-unit <-destroyMode Destroy
loop

After 10 seconds, on coordinates (50, 50), if there is an Emitter there, destroy it, even if there are multiple units occupying that cell.

once
	300 SetTimer0
endonce

GetTimer0 eq0 if
	once
		50 50 0 TRUE GetAllUnitsInRange 0 do
			->unit

			<-unit GetUnitType "EMITTER" eq if
				<-unit CONST_DESTROYMODE GetUnitAttribute ->destroyMode
				<-unit <-destroyMode Destroy
			endif
		loop
	endonce
endif