MZ Need Help Replacing Actor's Name in Battle Status Window

Hello,

I'm trying to make some updates to the Battle Status Window. Currently, I looking to replace the Actor's name in the Battle Status window, with their current class.

So instead of this:
1730221769459.png


I'd like it to show like this instead:
1730221869064.png


Can anyone help me pinpoint what code exactly makes this change? I've been poking around and I think its this set of code:

JavaScript:
Window_StatusBase.prototype.placeActorName = function(actor, x, y) {
    const key = "actor%1-name".format(actor.actorId());
    const sprite = this.createInnerSprite(key, Sprite_Name);
    sprite.setup(actor);
    sprite.move(x, y);
    sprite.show();
};

However, I can't figure out what code will bring up the current class.

I've tried using the .currentClass().name (actor.actorId().currentClass().name) to pull the code, but it procs errors.

As you can probably tell, I'm not so great at this, so looking for some help.

Thank you for taking the time to browse this!
MZ's status windows generally use sprites rather than drawing text directly to the window. Sprites are able to manage their own updates internally, so when one piece of information changes, the sprite can change rather than MZ needing to redraw everything on the entire window.

Look at Sprite_Name in rmmz_sprites.js.

The clue is in the code you provided:

JavaScript:
const sprite = this.createInnerSprite(key, Sprite_Name);
MZ's status windows generally use sprites rather than drawing text directly to the window. Sprites are able to manage their own updates internally, so when one piece of information changes, the sprite can change rather than MZ needing to redraw everything on the entire window.

Look at Sprite_Name in rmmz_sprites.js.

The clue is in the code you provided:

JavaScript:
const sprite = this.createInnerSprite(key, Sprite_Name);

That all makes sense. So, just for my knowledge, what is the purpose of the "key?".

Looking through the Sprite_Name portion of the Sprites code, I'm going to have to play around and figure out how the Actor's name is drawn.

Spoiler: Sprite_Name
JavaScript:
//-----------------------------------------------------------------------------
// Sprite_Name
//
// The sprite for displaying a status gauge.

function Sprite_Name() {
    this.initialize(...arguments);
}

Sprite_Name.prototype = Object.create(Sprite.prototype);
Sprite_Name.prototype.constructor = Sprite_Name;

Sprite_Name.prototype.initialize = function() {
    Sprite.prototype.initialize.call(this);
    this.initMembers();
    this.createBitmap();
};

Sprite_Name.prototype.initMembers = function() {
    this._battler = null;
    this._name = "";
    this._textColor = "";
};

Sprite_Name.prototype.destroy = function(options) {
    this.bitmap.destroy();
    Sprite.prototype.destroy.call(this, options);
};

Sprite_Name.prototype.createBitmap = function() {
    const width = this.bitmapWidth();
    const height = this.bitmapHeight();
    this.bitmap = new Bitmap(width, height);
};

Sprite_Name.prototype.bitmapWidth = function() {
    return 128;
};

Sprite_Name.prototype.bitmapHeight = function() {
    return 24;
};

Sprite_Name.prototype.fontFace = function() {
    return $gameSystem.mainFontFace();
};

Sprite_Name.prototype.fontSize = function() {
    return $gameSystem.mainFontSize();
};

Sprite_Name.prototype.setup = function(battler) {
    this._battler = battler;
    this.updateBitmap();
};

Sprite_Name.prototype.update = function() {
    Sprite.prototype.update.call(this);
    this.updateBitmap();
};

Sprite_Name.prototype.updateBitmap = function() {
    const name = this.name();
    const color = this.textColor();
    if (name !== this._name || color !== this._textColor) {
        this._name = name;
        this._textColor = color;
        this.redraw();
    }
};

Sprite_Name.prototype.name = function() {
    return this._battler ? this._battler.name() : "";
};

Sprite_Name.prototype.textColor = function() {
    return ColorManager.hpColor(this._battler);
};

Sprite_Name.prototype.outlineColor = function() {
    return ColorManager.outlineColor();
};

Sprite_Name.prototype.outlineWidth = function() {
    return 3;
};

Sprite_Name.prototype.redraw = function() {
    const name = this.name();
    const width = this.bitmapWidth();
    const height = this.bitmapHeight();
    this.setupFont();
    this.bitmap.clear();
    this.bitmap.drawText(name, 0, 0, width, height, "left");
};

Sprite_Name.prototype.setupFont = function() {
    this.bitmap.fontFace = this.fontFace();
    this.bitmap.fontSize = this.fontSize();
    this.bitmap.textColor = this.textColor();
    this.bitmap.outlineColor = this.outlineColor();
    this.bitmap.outlineWidth = this.outlineWidth();
};
The key is used by the window to track which sprites it has already created.

The method that determines the text displayed by the name sprite is:

JavaScript:
Sprite_Name.prototype.name = function() {
    return this._battler ? this._battler.name() : "";
};

It will get the name of the battler that has been assigned to the sprite. If no battler has been assigned, it sets the name to "".

You can adjust this._battler.name()to get some other data about the actor, like the name of their current class.

You can check out Window_StatusBase in rmmz_windows.js for a clue:

JavaScript:
Window_StatusBase.prototype.drawActorClass = function(actor, x, y, width) {
    width = width || 168;
    this.resetTextColor();
    this.drawText(actor.currentClass().name, x, y, width);
};

You may need to add some additional logic to Sprite_Name.prototype.nameto verify that the battler is an actor before fetching their class name. I'm not sure if the default UI uses Sprite_Name for enemies or not.

Anyway, that should give you an idea.
JavaScript:
Sprite_Name.prototype.name = function() {
    return this._battler ? this._battler.name() : "";
};

It will get the name of the battler that has been assigned to the sprite. If no battler has been assigned, it sets the name to "".

You can adjust this._battler.name()to get some other data about the actor, like the name of their current class.

You may need to add some additional logic to Sprite_Name.prototype.nameto verify that the battler is an actor before fetching their class name. I'm not sure if the default UI uses Sprite_Name for enemies or not.

Anyway, that should give you an idea.

Thank you, this helps me out a lot.

I was able to get the name changed

Through testing, I can confirm that the default Sprite_Name is used by both Players and Enemies.

I think I could probaly use a statement like this to make it work, no? :

JavaScript:
Sprite_Name.prototype.name = function() {
if (!this._battler.isEnemy()) {
    return this._battler ? this._battler.currentClass().name : "";
} else {
    return this._battler ? this._battler.name() : "";
}
};

Edit:

I can confirm that this code works:


JavaScript:
if (this._battler) {   
    if ("insert code here to distinguish player from enemy"){
        return this._battler ? "insert code here for battler name" : "";
        } else {
            return this._battler ? this._battler.name() : "";
        }
    }
};

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-replacing-actors-name-in-battle-status-window.172899/