MV Enemy Danger Effect

Hey y'all,

I'm trying to create an effect when enemies pulse red when they're at low HP.

Spoiler
JavaScript:
Sprite_Enemy.prototype.update = function() {
    Sprite_Battler.prototype.update.call(this);
    if (this._enemy) {
        this.updateEffect();
        this.updateStateSprite();
        this.updateDangerEffect();
    }
};

Sprite_Enemy.prototype.updateDangerEffect = function() {
    var target = this._effectTarget;
    var opacity = 0;
    if (this._battler.hp <= Math.floor(this._battler.mhp * 0.3)){
        this._dangerEffectCounter += 10;
        if (this._dangerEffectCounter % 80 < 80){
            opacity = this._dangerEffectCounter;
        }
        else if (this._dangerEffectCounter % 160 < 160){
            opacity = -(this._dangerEffectCounter - 160);
        }
        target.setBlendColor([255, 0, 0, opacity]);
    }
    else if (opacity > 0){
        opacity = 0;
        target.setBlendColor([255, 0, 0, 0]);
    }
}

I based this on the updateSelectionEffect function in rpg_sprites.js, but so far, I'm not getting any results with this. Any help would be appreciated.
I'm confused by what you're going for with these lines.
JavaScript:
        if (this._dangerEffectCounter % 80 < 80){
...
        else if (this._dangerEffectCounter % 160 < 160){
A number modulo by a value will always have a result less than that value. If it would ever be 80, it would produce 0.

So that's always going to be true, and the second one will never run (which would also always be true).
I'm confused by what you're going for with these lines.

A number modulo by a value will always have a result less than that value. If it would ever be 80, it would produce 0.

So that's always going to be true, and the second one will never run (which would also always be true).
OK, thanks for pointing that out! I can't believe I missed that 😛

Anyway, the idea is that this serves as a visual indicator for when an enemy's at low HP.

EDIT: After some tweaks, I noticed that the enemy reddened slightly when the requirements for my plugin were met. It's not quite what I was going for, but it's a good start. Question is, how do I make the red fade in and out?

Original thread: https://forums.rpgmakerweb.com/threads/enemy-danger-effect.168947/