Hi,
I am not able to test it but I think you should rotate back the orientation of the gizmo by all the bones parents orientation.

Code:
ANGLE aTemp1, aTemp2;
vec_set ( aTemp1, my.pan );
var hndParent = ent_boneparent ( you, NULL, (long)my.bone_handle );
while ( hndParent )
{
	ang_for_bone ( aTemp2 , you , (long)hndParent );
	vec_rotateback ( aTemp1, aTemp2 );
	hndParent = ent_boneparent ( you, NULL, (long)hndParent );
}
vec_rotateback ( aTemp1, you.pan );
ent_bonereset ( you , (long)my.bone_handle );
ent_bonerotate ( you , (long)my.bone_handle , aTemp1 );



Hope it helps,
salud!