It's certainly possible to script that, although I don't really have a ready-to-use script for that. Here's a modified and trimmed-down version of a similar script I have though, which can at least serve as a starting point:
#Conditional Hooks
$Application: FS2_Open
$On Game Init: [
ai_ship_meta = {}
avoid_ground = function(ship, altitude)
ship_pos = ship.Position
ship_forward_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, 0, 400))
ship_down_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, -400, 0))
ship_up_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, 400, 0))
ship_left_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(-400, 0, 0))
ship_right_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(400, 0, 0))
if ship_forward_pos["y"] < altitude or ship_pos["y"] < altitude then
if ai_ship_meta[ship.Name] == nil or not ai_ship_meta[ship.Name].evading_ground then
ai_ship_meta[ship.Name] = { evading_ground = true, direction = "nowhere" }
if ship_up_pos["y"] > altitude then
ship:doManeuver(1000, 0, -1.0, 0, true, 0, 0, 1.0, false)
ai_ship_meta[ship.Name].direction = "up"
elseif ship_down_pos["y"] > altitude then
ship:doManeuver(1000, 0, 1.0, 0, true, 0, 0, 1.0, false)
ai_ship_meta[ship.Name].direction = "down"
elseif ship_left_pos["y"] > altitude then
ship:doManeuver(1000, -1.0, 0, 0, true, 0, 0, 1.0, false)
ai_ship_meta[ship.Name].direction = "left"
elseif ship_right_pos["y"] > altitude then
ship:doManeuver(1000, 1.0, 0, 0, true, 0, 0, 1.0, false)
ai_ship_meta[ship.Name].direction = "right"
else
ai_ship_meta[ship.Name].direction = "nowhere"
end
end
return true
else
if ai_ship_meta[ship.Name] == nil then
ai_ship_meta[ship.Name] = { evading_ground = false, direction = "nowhere" }
else
if ai_ship_meta[ship.Name].evading_ground then
ai_ship_meta[ship.Name] = { evading_ground = false, direction = "nowhere" }
ship:doManeuver(4000, 0, 0, 0, true, 0, 0, 1.0, true)
end
end
return false
end
end
]
#End
You'd just need to call the avoid_ground() function on all AI ships every frame (or maybe just once per second) in an $On Frame hook or from a mission event and hope it actually works as intended (I might have messed up something when adapting it to this purpose).
The ships might also end up doing a funny up-down-up-down-up-down bobbing motion close to the ground if they for some reason really want to go below the given altitude, but you can do something like change their current goal to remedy that. You'll also want to change the magic value of 400; the avoidance behavior kicks in when the distance along the ship's forward vector to the given altitude becomes less than that value.