If I read correctly the codes all working, and you just want to optimize it some right? I'll have a look through it when I have the time.
For it to still react to the player when his object index is changed by the battle system, you could either store the player's id to a global variable that the AI uses, or create a 'parent' object for the player. I'd probably go with the latter so if I decide later that I want the AI to attack other objects the same way it does the player I can just use the parent object.
To create a 'parent' object for things the AI attack:
1) Create a new object, but don't give it any events. Name it something like obj_AItarget or whatever you want, as long as you know what it's for.
2) Under the object properties for all of the objects you want the AI to attack, theres an option "Parent" with a drop-down box on the left side of the window. Under this select the object you just created.
3) Edit your AI code to go after the parent object.
One of the many uses of parents. Be aware though that if you do give the parent object events any object that has them as a parent inherits those events unless they have their own of the same type. This can be a very useful if you have several objects that use most of the same code, but it can also be confusing, and cause odd, hard to find bugs if you don't realize it's happening.