Do you mean all the steps or are you just asking literally just which function do you use to generate the reference point to add into the patrol or support mission?
The latter is ScenEdit_AddReferencePoint(...), then you update the reference points for the patrol mission involved with ScenEdit_SetMission(...), the
patrolmission or supportmission options which has a sub-table of RP names in the patrolzone and prosecutionZone properties. Keep in mind you'll need 1146.1 or higher that corrects a bug if you're trying to update the patrolzone and prosecutionZone simultaneously in a single call, otherwise you'll need to make two calls one to update the patrolzone, and a separate call to update only prosecutionZone. In figuring out where said location points should be you want to look at World_GetPointFromBearing(table) - 'table' isn't documented in terms of all it's parameters but I've provided the parameters below in some additional comments.
If the former (detailed steps), there are probably 1/2 dozen different approaches you can take for this depending on how much effort you want to put into it, what you're goal is, and how much intelligence you want embed.
-
I'll throw out some unasked for thoughts, they assume however you want\need at some point to revert back to the original mission state at some point, and that this just involves trying to either better classify the contact and\or are trying to pickup a particular new contact (the e-2's carrier?) based on moving closer to the first contact.
Instead of creating new rp's you can probably just adjust the existing one's locations to extend toward the contact, you'll have to figure out which one(s) are best to adjust first though, probably by just measuring all associated with the mission and finding the one or two closest to the contact. In doing that though you'll need to remember where the original positions where so you can restore them later after you've made better detection\classification of whatever it is you want the bear-D to accomplish with moving closer, so store that\those locations in a key (to preserve across play sessions if needed).
Another approach is to create a temporary new mission to go get closer to the target and then once a certain classification\detection level is made on said target to a certain level flip them back to the old mission and remove the new one - keep in mind though if you have multiple available aircraft for that mission once you assign the bearD to the new one the game may launch it's replacement for the old one - so either you have to manage or otherwise plan around it. All depends on what you're going for or works best for your particular situation. Though creating a new mission might be easier than trying to create new rp's and figuring out in what order the existing + new rp's need to be in for the zone to stay valid. I've never tried to figure out correct order via lua and geometry, probably can be done, but off hand it seems like a challenge.
A third method that comes to mind is not even play around with the mission or RP's and just directing the unit out of it's patrol\support area temporarily via manual course waypoint to close closer to the specific contact. So if contact is say detected something like < 500nm out but > 100nm out, and say at bearing 265'ish, just get a point say 1/3rd (or whatever) the distance at that bearing via World_GetPointFromBearing({LATITUDE=BearDUnit.latitude,LONGITUDE=BearDUnit.longitude,BEARING=TheBearing,DISTANCE=(TheDistance *.33)}) and set a waypoint toward that location. Optionally then activate\create another event or script that's checking say every 5 seconds for the detection of whatever it is you want (be it further classification on the e-2 or detection of particulate new contacts like a carrier). When said detection matches whatever it is you want, remove the waypoint\course on the Bear D and it should automatically turn around and go back into it's patrol zone a few seconds later. Then delete or disable the associated detection tracking (be it an event or your own custom script working off a contactguid or be it looking for a specific contact\ship etc).
As for avoiding it being engaged, there are probably a half dozen approaches there as well depending on how complex you want to get, but I'm assuming you just meant you want to keep it a generic xxx nm away from the contact, which you can control to fair degree with the waypoint or patrol\support mission zone locations.
Err I already got way more verbose than intended, so I'll stop there.