MZ Displaying states over enemies in battle (without Visustella)

Hello everybody, I'm in a bit of a predicament right now, I'm looking for a plugin that would draw states icons over an enemy when afflicted.
I'm using Akea animated battlers so I can't use Visustella battle core to display them.
The only specification needed would be that the position of the states should be customizable for each enemy type in the database (I'm using Akea custom gauges, that allows to use differents gauges for each enemy, sometimes displaying MP or others).
No need to do anything about actors states, cause it's already handled by MOGhunter battle HUD.
Any help would be greatly welcome!
Thanks a lot.
(() => {
const parseNum = (val, def) => {
const n = Number(val);
return isNaN(n) ? def : n;
};

// Extend Sprite_Enemy
const _Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
Sprite_Enemy.prototype.initMembers = function() {
_Sprite_Enemy_initMembers.call(this);
this.createStateIconSprite();
};

Sprite_Enemy.prototype.createStateIconSprite = function() {
this._stateIconSprite = new Sprite_StateIcon();
this.addChild(this._stateIconSprite);
};

const _Sprite_Enemy_update = Sprite_Enemy.prototype.update;
Sprite_Enemy.prototype.update = function() {
_Sprite_Enemy_update.call(this);
this.updateStateIconSprite();
};

Sprite_Enemy.prototype.updateStateIconSprite = function() {
if (!this._stateIconSprite || !this._enemy) return;

const meta = this._enemy.enemy().meta;
const baseX = parseNum(meta.StateIconX, 0);
const baseY = parseNum(meta.StateIconY, -40);
const scale = parseNum(meta.StateIconScale, 1.0);
const anchor = (meta.StateIconAnchor || "auto").toLowerCase();

// Default placement
let posX = baseX;
let posY = baseY;

// Adaptive positioning: check gauges
if (this._enemy._akeaGauges) {
const gauges = this._enemy._akeaGauges;
let overlap = false;

for (const g of gauges) {
const gx = g.x;
const gy = g.y;
const gw = g.width || 100;
const gh = g.height || 20;

// Simple bounding box overlap check
const iconBox = {
x: posX + this.x,
y: posY + this.y,
w: this._stateIconSprite.width || 32,
h: this._stateIconSprite.height || 32
};

const gaugeBox = { x: gx + this.x, y: gy + this.y, w: gw, h: gh };

const intersects =
iconBox.x < gaugeBox.x + gaugeBox.w &&
iconBox.x + iconBox.w > gaugeBox.x &&
iconBox.y < gaugeBox.y + gaugeBox.h &&
iconBox.y + iconBox.h > gaugeBox.y;

if (intersects) {
overlap = true;
break;
}
}

if (overlap) {
if (anchor === "top") posY = baseY - 40;
else if (anchor === "bottom") posY = baseY + 40;
else {
// auto: shift upward by default
posY = baseY - 40;
}
}
}

this._stateIconSprite.x = posX;
this._stateIconSprite.y = posY;
this._stateIconSprite.scale.x = scale;
this._stateIconSprite.scale.y = scale;

this._stateIconSprite.setup(this._enemy);
};

// Ensure actors are ignored (MOG handles them)
const _Sprite_Actor_update = Sprite_Actor.prototype.update;
Sprite_Actor.prototype.update = function() {
_Sprite_Actor_update.call(this);
if (this._stateIconSprite) this._stateIconSprite.visible = false;
};
})();

Enemy note-tag
<StateIconX: 20>
<StateIconY: -50>
<StateIconScale: 1.2>
<StateIconAnchor: auto>

This should fix your issue but i dont use Akea so i just used there code as basis.
This works with native rmmz but it gives chasis.

Tested it with attack down debuff. Adjust the states accordingly.
Dude, weren't you already told that AI replies are considered spam 😀
(() => {
const parseNum = (val, def) => {
const n = Number(val);
return isNaN(n) ? def : n;
};

// Extend Sprite_Enemy
const _Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
Sprite_Enemy.prototype.initMembers = function() {
_Sprite_Enemy_initMembers.call(this);
this.createStateIconSprite();
};

Sprite_Enemy.prototype.createStateIconSprite = function() {
this._stateIconSprite = new Sprite_StateIcon();
this.addChild(this._stateIconSprite);
};

const _Sprite_Enemy_update = Sprite_Enemy.prototype.update;
Sprite_Enemy.prototype.update = function() {
_Sprite_Enemy_update.call(this);
this.updateStateIconSprite();
};

Sprite_Enemy.prototype.updateStateIconSprite = function() {
if (!this._stateIconSprite || !this._enemy) return;

const meta = this._enemy.enemy().meta;
const baseX = parseNum(meta.StateIconX, 0);
const baseY = parseNum(meta.StateIconY, -40);
const scale = parseNum(meta.StateIconScale, 1.0);
const anchor = (meta.StateIconAnchor || "auto").toLowerCase();

// Default placement
let posX = baseX;
let posY = baseY;

// Adaptive positioning: check gauges
if (this._enemy._akeaGauges) {
const gauges = this._enemy._akeaGauges;
let overlap = false;

for (const g of gauges) {
const gx = g.x;
const gy = g.y;
const gw = g.width || 100;
const gh = g.height || 20;

// Simple bounding box overlap check
const iconBox = {
x: posX + this.x,
y: posY + this.y,
w: this._stateIconSprite.width || 32,
h: this._stateIconSprite.height || 32
};

const gaugeBox = { x: gx + this.x, y: gy + this.y, w: gw, h: gh };

const intersects =
iconBox.x < gaugeBox.x + gaugeBox.w &&
iconBox.x + iconBox.w > gaugeBox.x &&
iconBox.y < gaugeBox.y + gaugeBox.h &&
iconBox.y + iconBox.h > gaugeBox.y;

if (intersects) {
overlap = true;
break;
}
}

if (overlap) {
if (anchor === "top") posY = baseY - 40;
else if (anchor === "bottom") posY = baseY + 40;
else {
// auto: shift upward by default
posY = baseY - 40;
}
}
}

this._stateIconSprite.x = posX;
this._stateIconSprite.y = posY;
this._stateIconSprite.scale.x = scale;
this._stateIconSprite.scale.y = scale;

this._stateIconSprite.setup(this._enemy);
};

// Ensure actors are ignored (MOG handles them)
const _Sprite_Actor_update = Sprite_Actor.prototype.update;
Sprite_Actor.prototype.update = function() {
_Sprite_Actor_update.call(this);
if (this._stateIconSprite) this._stateIconSprite.visible = false;
};
})();

Enemy note-tag
<StateIconX: 20>
<StateIconY: -50>
<StateIconScale: 1.2>
<StateIconAnchor: auto>

This should fix your issue but i dont use Akea so i just used there code as basis.
This works with native rmmz but it gives chasis.

Tested it with attack down debuff. Adjust the states accordingly.
Hey thanks a lot for the quick response !
Unfortunately I get a "syntax error: unexpected identifier"
I quickly looked through it but I couldn't find what was causing it.
The battle system is this https://raizen884.itch.io/akea-animated-battle-system-2?

The Syntax error is caused by note-tag issue that the only thing that could cause that. Or cause i did not make specifically for AKEA2.
<StateIconX: 20>
<StateIconY: -50>
<StateIconScale: 1.2>
<StateIconAnchor: auto> These noteags have to be precise as written.

Can you confirm the note-tags are correct and that your using ABS2? if so ill make a few tweaks.
Note: Cloudflare is for Itch.io is down so i cant DL ABS2 atm :/
The battle system is this https://raizen884.itch.io/akea-animated-battle-system-2?

The Syntax error is caused by note-tag issue that the only thing that could cause that. Or cause i did not make specifically for AKEA2.
<StateIconX: 20>
<StateIconY: -50>
<StateIconScale: 1.2>
<StateIconAnchor: auto> These noteags have to be precise as written.

Can you confirm the note-tags are correct and that your using ABS2? if so ill make a few tweaks.
Note: Cloudflare is for Itch.io is down so i cant DL ABS2 atm :/
It's all good, I stupidely pasted the notetags into the plugin.
the only thing is that the states appears mirrored.

EDIT: I tried making the icon scale notetag negative but it flipped it vertically instead.
1763478957443.png
(() => {
const parseNum = (val, def) => {
const n = Number(val);
return isNaN(n) ? def : n;
};

// Extend Sprite_Enemy
const _Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
Sprite_Enemy.prototype.initMembers = function() {
_Sprite_Enemy_initMembers.call(this);
this.createStateIconSprite();
};

Sprite_Enemy.prototype.createStateIconSprite = function() {
this._stateIconSprite = new Sprite_StateIcon();
this.addChild(this._stateIconSprite);
};

const _Sprite_Enemy_update = Sprite_Enemy.prototype.update;
Sprite_Enemy.prototype.update = function() {
_Sprite_Enemy_update.call(this);
this.updateStateIconSprite();
};

Sprite_Enemy.prototype.updateStateIconSprite = function() {
if (!this._stateIconSprite || !this._enemy) return;

const meta = this._enemy.enemy().meta;
const baseX = parseNum(meta.StateIconX, 0);
const baseY = parseNum(meta.StateIconY, -40);
const scale = parseNum(meta.StateIconScale, 1.0);
const anchor = (meta.StateIconAnchor || "auto").toLowerCase();
const fixMirror = String(meta.StateIconMirrorFix || "").toLowerCase() === "true";

let posX = baseX;
let posY = baseY;

// Adaptive positioning: check gauges
if (this._enemy._akeaGauges) {
const gauges = this._enemy._akeaGauges;
let overlap = false;

for (const g of gauges) {
const gx = g.x;
const gy = g.y;
const gw = g.width || 100;
const gh = g.height || 20;

const iconBox = {
x: posX + this.x,
y: posY + this.y,
w: this._stateIconSprite.width || 32,
h: this._stateIconSprite.height || 32
};

const gaugeBox = { x: gx + this.x, y: gy + this.y, w: gw, h: gh };

const intersects =
iconBox.x < gaugeBox.x + gaugeBox.w &&
iconBox.x + iconBox.w > gaugeBox.x &&
iconBox.y < gaugeBox.y + gaugeBox.h &&
iconBox.y + iconBox.h > gaugeBox.y;

if (intersects) {
overlap = true;
break;
}
}

if (overlap) {
if (anchor === "top") posY = baseY - 40;
else if (anchor === "bottom") posY = baseY + 40;
else posY = baseY - 40;
}
}

this._stateIconSprite.x = posX;
this._stateIconSprite.y = posY;

// Mirror fix logic
const parentScaleX = this.scale?.x || 1;
this._stateIconSprite.scale.x = fixMirror ? scale * Math.sign(parentScaleX) : scale;
this._stateIconSprite.scale.y = scale;

this._stateIconSprite.setup(this._enemy);
};

// Ensure actors are ignored (MOG handles them)
const _Sprite_Actor_update = Sprite_Actor.prototype.update;
Sprite_Actor.prototype.update = function() {
_Sprite_Actor_update.call(this);
if (this._stateIconSprite) this._stateIconSprite.visible = false;
};
})();

---------------------------------
I put a separation line so you donèt copy the note-tags into the plugin 🙂
New note-tag
<StateIconMirrorFix:true>

Use this one inverted the icon states. As when i run it (the previous one) it does not do that for me. When i run this one it does make them inverted lol so now base rmmz has the issue but since you have the inversion it should fix it.
It worked!
Thanks a lot for your help and time, I greatly appreciate it !

Original thread: https://forums.rpgmakerweb.com/threads/displaying-states-over-enemies-in-battle-without-visustella.181076/