Why doesn't this work? (changing paint opacity)

I have this code which should draw some enemies grayed out in the target selection menu, but for some reason it doesn't do anything, even though the paint opacity is clearly still 160 when it reaches the draw text call. Any idea what I'm missing here?

JavaScript:
Window_BattleEnemy.prototype.isCurrentItemEnabled = function() {
    var canTarget = true, enemy = this.enemy();
    if(enemy) canTarget = enemy.tgr > 0;
    return canTarget && Window_Selectable.prototype.isCurrentItemEnabled.call(this);
};

const old_drawEnemyItem = Window_BattleEnemy.prototype.drawItem;
Window_BattleEnemy.prototype.drawItem = function(index) {
    this.changePaintOpacity(this.isCurrentItemEnabled());
    old_drawEnemyItem.call(this, index);
    this.changePaintOpacity();
};

(In case you're wondering, the use-case for this is an "invisible" state.)
It's because your drawItem alias only references the enemy that's currently selected at the time of drawing; you'll want to reference the appropriate index instead. Also, it may be worth noting that the window's items are only redrawn when the window is refreshed, e.g. when it initialises and when the list is scrolled. 😅

In short, try replacing this line:
JavaScript:
    this.changePaintOpacity(this.isCurrentItemEnabled());
...with this:
JavaScript:
    this.changePaintOpacity(this._enemies[index].tgr > 0);
😤

[Edit: me English better now. 😴]
Aha, that makes sense. How did I miss that... anyway it works now. Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/why-doesnt-this-work-changing-paint-opacity.123003/