animmax=any number greater then the number of animations you have.
The reason your script failed is because you dont tell it to go to state=1. so its just sitting there at frame 40 just as instructed.
Try this:
;Check players distance
:state=0,plrdistwithin=50:state=1
:state=0,plrdistfurther=50:state=10
;OpenRegister Door
:state=1:setframe=0,state=2
:state=2:incframe=0,state=3
:state=3,frameatend=0:state=0
;Close Register Door
:state=10:setframe=1,state=11
:state=11:incframe=1,state=12
:state=12,frameatend=1:state=0
making the state go back to 0 will allow the routine to work over again. If this is a one shot deal then in the state=12 line send it to any other state not listed.
Hope this helps.
Nothing but coffee in my veins 'Insomnia is Coming'