I understand, it's fine.
Ok, so, no, better doing everything in one state as you're doing, I'll help you.
So the first thing I notice is, your varset for var(13) will ALWAYS be 2, here is why:
Spoiler, click to toggle visibilty
Now try using this in your State 0:
type = S
physics = S
sprpriority = 0
[State 0, Anim]
type = changeanim
trigger1 = anim != var(10)
trigger1 = anim != 5
trigger2 = anim = 5 && !animtime
value = var(10)
You can delete everything else from state 0.
Although I think it will still have some issues but at least this will clean your code. Try it and tell me what happened.