Ok, so you'll need the findunit.sqf function, which can be found on OFPEC or just copy and paste this in a "findunit.sqf" script file :
Spoiler:
/*findUnits.sqf
By General Barron
11/15/03
This script returns an array of all units within a specified distance
of another unit that are in the passed array. The result is sorted
in acsending order of distance to the calling unit. Will never return the
unit originally passed to the function. To call:
[unit, range, [unit array]] call findUnits
Usage example: make a trigger, covering entire map, activation = once, "east present". On activation = "east_units = thisList"
Make another trigger. Condition = "count ([player, 50, east_units] call findUnits) > 0". On activation = "hint "the enemy is near" "
The hint will appear once the player comes within 50 meters of an east unit.
*/
/*-----------------------------------------------------------------------------------
Start bubble sort (sort units from closest to farthest)
Code taken from sortBubble.sqf
By bn880 2/24/2003
(slightly modified to fit in this function)
-----------------------------------------------------------------------------------*/