Set your animation names to "0" (right), "45", "90" (down), "135", "180" (left), "-135", "-90" (up), and "-45".
Then use the following event to determine the animation to play:
+ LOSObject: Has LineOfSight to Target image point 0
-> LOSObject: Set animation to str(round(angle(LOSObject.X,LOSObject.Y,Target.X,Target.Y)÷45)×45) (play from beginning)
Here's a small c3p to illustrate: 1drv.ms/u/s!AhWRm9FAXcyGlbN5aRgM0vDfW9wzpg