This can be done by using the knowsAbout command. As it returns a numerical value it can easily be used in combination with count to check a whole array of units. KnowsAbout is useful because it doesn't increase instantly (as for example checking for nearby shots would) and thus allows for a "grace period" where players can dispose of a unit without alerting enemies.
Examples:
For each playable unit we check if the vehicle VehCSAT_AH1 knows about it (>0). If it knows about any unit (the second > 0) the line of code will return true.
This can be extended easily:(({VehCSAT_AH1 knowsAbout _x > 0} count PlayableUnits) > 0
Now it adds the knowsAbout values for both VehCSAT_AH1 and VehCSAT_AH2 and if any of them knowsAbout (total value > 0), it returns true.((({VehCSAT_AH1 knowsAbout _x > 0} count PlayableUnits) + (({VehCSAT_AH2 knowsAbout _x > 0} count PlayableUnits))) > 0
But what if we wanted to check for a whole group of units?
This line loops through all units of the group named GrpAAF_Patrol and checks the knowsAbout value. If at least one of them knowsAbout players (second >0) then it returns true.({_u = _x; {_u knowsAbout _x > 0} count PlayableUnits} forEach units GrpAAF_Patrol) > 0
Neatly, knowsAbout can also be used with SIDE instead of a unit:
In this case it would check for all independent units.(INDEPENDENT knowsAbout _x > 0} count PlayableUnits) > 0;
Implementation
The easiest way to use this is in a trigger (that isn't activated otherwise) and use the "On Activation" field to have happen whatever should happen if the players are detected. With a timeout value you can also increase the "grace period" for the players.
Example:
Again, using the code for the AAF Patrol:
And in the on-act field:({_u = _x; {_u knowsAbout _x > 0} count PlayableUnits} forEach units GrpAAF_Patrol) > 0
This would cause the entire group to go full alert. You can also use the reveal command to update their knowledge of targets to make them engage actively.{_x setCombatMode "RED"; } forEach (units GrpAAF_Patrol);
Tip
KnowsAbout is a fluent value. You don't need to check if it's > 0 but can use all the values on the "scale". Freshly spotted units will always have at least 1.5 but from there on out it varies depending on distance, weather and time of day. Only units within 400m on a clear day will have the highest "knowsAbout value" of 4. I suggest using the debug console to monitor AI's knowsAbout state if you want to tweak the values.