MV Skill Animation Layer Order help

I've been trying to tackle this one for a while. I would like to find a way for a Skills animation to play in front or behind of a target depending on its position. Currently the animations play on a layer above everything. For example, if there were two enemies, Target 1 and Target 2 and you attacked Target 2 which was in the back, the Skill animation would still play on Target 2 but the animation would play in front of both targets. When it actually would look more accurate if it played on top of Target 2 but behind Target 1.

I found this forum post:

They had some success by altering this code:

Code:
Sprite_Battler.prototype.setupAnimation = function() {
    while (this._battler.isAnimationRequested()) {
        var data = this._battler.shiftAnimation();
        var animation = $dataAnimations[data.animationId];
        var mirror = data.mirror;
        var delay = animation.position === 3 ? 0 : data.delay;
        this.startAnimation(animation, mirror, delay);
        for (var i = 0; i < this._animationSprites.length; i++) {
            var sprite = this._animationSprites[i];
            sprite.visible = this._battler.isSpriteVisible();

        //New stuff added
        if (animation.position < 3) { this.addChild(sprite); };  
        //New Stuff Added

        }
    }
};

And like the original poster said, it worked perfectly for the Actors, but it no longer lines up the animations on enemies that are targeted. Does anyone have any ideas how I could fix that? Alternatively, if I could make it so the added code only affects actors, I could make the work too. Something along the line of:
"If animation is for actor do if (animation.position < 3) { this.addChild(sprite); }; else do nothing."
In a perfect world I would love to have it work for both but I'll take what I can get.
As always, thanks in advance for any help of advice you can give. It's greatly appreciated.
I was just looking for slightly similar information, I leave you the link, maybe it will help you.

https://forums.rpgmakerweb.com/inde...nimations-can-be-changed.128942/#post-1136005
I appreciate the response. I am already using that bit of code and it does get me a small part of the way there. However, I'm trying to get animations to play on and enemy or actor between two other enemies or actors so the animation would be above certain sprites and below others. But I genuinly appreciate the help.
I appreciate the response. I am already using that bit of code and it does get me a small part of the way there. However, I'm trying to get animations to play on and enemy or actor between two other enemies or actors so the animation would be above certain sprites and below others. But I genuinly appreciate the help.
I think what you'd need to do is set the z axis of the animation to the z axis of the target battler sprite +1. Since the code I shared in the other thread just sets it to -1, it ends up behind all battler sprites (err, I think anyway). You'd need to modify it so that it detects the z axis of the target and then repositions itself above only that layer.
The only thing is that I'm not sure if each battler sprite is ever actually on its own layer, or if they all share the same layer. If all battlers are on the same layer, then stuffing an animation in between two of them might be completely impossible. You'd need to look at something like YEP_BattleEngineCore, which allows you to dynamically set battler sprite priority and see how Yanfly did that.
I managed to get it to work for actors which does about 75% of what I need.

I did this with:
Code:
        if (this._battler.isActor()) {
        if (animation.position < 3) { this.addChild(sprite); };   
        };

If I ever figure out how to do it with Enemies, I will definitely share. I think its because Enemy animations play on a layer that fills the whole screen and use some different method to tell where the sprites are positioned in the Database. So when you add child the enemy animations it no longer knows where to put them. I could be totally wrong there, as my coding knowledge is incredibly limited. But that's my theory so far.

Original thread: https://forums.rpgmakerweb.com/threads/skill-animation-layer-order-help.129728/