How to bring back quadcopter in one piece

I am looking for some piece of code within firmware which i can use as lua binding something like RC override which can help in bringing quadcopter in one piece if something goes wrong, this scenario already happened to me on one of my quads recently. I am not doubting current failsafes and safety measures in ardupilot, i just want double ensurance in case if there will be some hardware fault during flight.

I generally fly my quads in guided mode and i fly multiple drones at a time that’s why i am looking how lua scripting can continuously keep all quads in check during the flight, i can set certain conditions but i am not sure what i should trigger from lua scripting to bring those quads on ground safely with minimum damage and not require to use flight termination.