i took a quick look. try this i haven't tested it
;artificial intelligence script
;desc =ally main script
;this ally script makes the ally fully automated, no keyboard commands
;the targetting of the enemy is done in the shoot script
:always:globalvar=41
:state=0,varequal=1:activate=0,state=10
:state=0:state=16
:vargreater=2,activated=0:state=20,activate=1
:state=1,plrdistfurther=60,plrcanbeseen:lookatplr,rotatetoplr,resethead,settarget,animate=5,movetotarget
:state=1,plrdistfurther=60,plrcannotbeseen:state=10
:state=1,plrdistwithin=61:freeze,animate=1,state=2
:state=2:timerstart,rotatehead=10,state=3
:state=2,plrdistfurther=70:state=10
:state=3,timergreater=2000:state=4
:state=3,plrdistfurther=70:state=10
:state=4:timerstart,state=5
:state=4,plrdistfurther=70:state=10
:state=5,timergreater=2000:rotatehead=-30,timerstart,state=6
:state=5,plrdistfurther=70:state=10
:state=6,timergreater=2000:rotatehead=30,state=4
:state=6,plrdistfurther=70:state=10
:state=10:lookatplr,rotatetoplr,resethead,state=11
:state=11,plrcanbeseen:settarget,state=1
:state=11,plrcannotbeseen:lookatplr,rotatetoplr,resethead,state=12
:state=12,plrcanbeseen:settarget,state=1
:state=12,plrcannotbeseen:movetotarget,state=13
:state=13,reachtarget:animate=1,state=10
:state=13:state=10
:state=16:animate=31,state=17
:state=17:setvar=0,state=18
:state=18,plrcanbeseen:setvar=1,state=10
:state=20:freeze,animate=1,lookatplr,state=21
:state=21,plrcanbeseen:settarget,rotatetoplr,resethead,animate=5,movetotarget,state=23
:state=21,plrcannotbeseen:state=20
:state=23,reachtarget:state=24,freeze,animate=1,shootplr
:state=24:activate=0,state=10
And i do see the reachtarget command which isn't the best to use
]