Don't know if this will help aor not.
I've been trying to do exactly what you have had problems with. The script above is the one I designed for choppers, and with variation it can be made to work with AI and auto pilot.
I disabled the gearRetracting = true; to gearRetracting = false; then used custom scripts to raise and lower the gear.
An intitial script was run first to either raise or lower the gear when the addon initializes. This script checks if the plane is flying or on the ground. This works with both AI and the player.
Then this script runs 2 scripts.
1. An AI script for autolanding and take off gear raising or lowering as the case maybe. This script loops until the ai plane crashes (I haven't figured out how to detect the AI yet)
2. An Autoland script which detects the player's position and speed. If above a certain height or speed the gear stays up otherwise it automatically comes down. The only issue with this is on take offs so far as it won't allow the gear to go up untill it reaches the height/speed etc.
The idea for the above is good and I have it working on the Harrier for the Falklands mod and the next version of the A4 but it needs a little more work.
Just experiment, thats all you can do really.