Try the following ideas. Note that I didn't test it, so it might need some fixing.
First, execute your script with the following code:
player exec "DetectNearest.sqs"
Then, create the DetectNearest.sqs script with the following code:
; Give the local variable _player the value of _this, which is the passed
; unit.
_player = _this
; Initialize an array with the object names of each East soldier type.
; Note that in my example code here, I didn't include *EVERY* existing
; East soldier, as I don't recall the names of all of them. Also note that
; this code is universal in that you can use it to detect the proximity of
; *ANY* unit type (east or west, infantry or vehicle), not just east soldiers.
_unitTypes = ["OfficerE","SoldierEMG","SoldierEB","SoldierEG","SoldierELAW"]
; Get the size of the _unitTypes array.
_i = count _unitTypes
#Check
; Decrement _i.
_i = _i - 1
; Get the nearest unit of a particular type.
_nearObj = NearestObject [_player,(_unitTypes select _i)]
; Check if _i < 1, and if so, reset its value.
? (_i < 1) : _i = count _unitTypes
; Check if the nearest unit of the indicated type is less than 50m from
; _player. If so, then take some kind of action.
? _player distance _nearObj < 50 : goto "TakeAction"
; If we got here, then loop to check the next unit type.
goto "Check"
#TakeAction
; Put your code to make them respond here.
; When done, loop to "Check" to check for the next unit type.
goto "Check"