A problem you might find with the lock on code is that if there is more than one lock on object in range, if you press right click you might not lock on to the closest object.

To rectify this, find this code:

temp.pan = 360;
temp.tilt = 50;
temp.z = lockon_min;
scan_entity (my.x, temp);

and place it before "IF (locked_on == 0) {" instead of after.