Problems with BattleManager (MV)

Hi,

I have been trying to use "BattleManager" to display a portrait of the active battler during a fight (then when it's the next actor's turn to choose an action, the portrait changes.. etc).
I can't seem to be able to display even the first portrait tho.

For now, I am using this troop to try and display the portrait when actor 1 is choosing an action :

1698115988136.png


But this doesn't work.

What is wrong with it ?

Thank you all in advance.
I'd love for an event wizard to jump in here and correct me, but I don't know that this can be done with troop events. Ideally, you would have a plugin that displays the portraits based on the actor that is currently inputting.

I did some googling and found this one, which you could maybe try. I'd be willing to bet there's also at least one Japanese plugin to do this, but it'd be difficult to track down via Google.
For now, I am using this troop to try and display the portrait when actor 1 is choosing an action :
Well, the first thing that looks off to me is your Span of Turn. That means it's only going to run once each turn and at the beginning of the turn there is no inputting actor (and it certainly won't necessarily be actor 1).

You only have a hope of this working if the Span is Moment, so it's checked constantly.

I agree with @Kenen that it would be more efficient and probably easier to use a plugin for this.
Ok, I'll try it this instant and keep you updated.
The downside of Span: Moment is that it'll continually run, trying to re-display the same image for as long as that actor is inputting their turn.

So if you do get any kind of result from that, I think you're going to have to encapsulate it in a switch:
If this actor is inputting
- If this switch is OFF
-- display the image
-- turn the switch ON
- else turn switch OFF

But, again, I think all of this is probably an inefficient approach.
Thank you for your replies.

So i've tried the plugin and it works as intended, but by using this plugin it also changes what I had originally planned.

The plugin is this one :
Spoiler: Plugin BattlePortrait
//==============================================================================
// BattlePortrait.js
//==============================================================================

var Imported = Imported || {};
Imported.BattlePortrait = true;

/*:
* @plugindesc Show portraits during battle.
* @Author mjshi
*
* @param Auto Adjust
* @desc (y/n) Automatically align images along the bottom right. Turn off if you want to manually position images using transparent PNGs.
* @Default y
*
* @param Opacity
* @desc 0 to 255. 0 = transparent, 255 = opaque
* @Default 255
*
* @param X Offset
* @desc Relative to the bottom right corner.
* @Default 0
*
* @param Y Offset
* @desc Relative to the bottom right corner.
* @Default 0
*
* @param Hide during item and skill selection
* @desc (y/n)
* @Default y
*
* @param Hide during enemy target selection
* @desc (y/n)
* @Default y
*
* @param Hide during ally target selection
* @desc (y/n)
* @Default y
*
* @param Image Filename
* @desc Code that will be evaluated to determine what image to use for each actor.
* @Default 'Actor' + actor.actorId()
*
* @Help
* ------------------------------------------------------------------------------
* BattlePortrait v1.1 by mjshi
* Free for both commercial and non-commercial use, with credit.
* ------------------------------------------------------------------------------
* Installation: Place all bust images in img/system.
* Images should be named "Actor#.png", where # is the corresponding actor ID.
*
* ------------------------------------------------------------------------------
* Advanced usage
* ------------------------------------------------------------------------------
* The Image Filename parameter could be modified to change what image should
* be loaded. For example, if you wanted to change the actor's battle portrait
* when their class changes, you could set it to:
* 'Actor' + actor.actorId() + '_' + actor._classId
*
* That way, images would be named "Actor#_#.png" where the first # is the
* actor's ID and the second # is the class's ID.
*
* ------------------------------------------------------------------------------
* > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
* try my best to help you!
*/

(function () {
/* BEGIN */

function param(str) {
return parseInt(PluginManager.parameters('BattlePortrait')[str]);
}

function boolp(str) {
return (PluginManager.parameters('BattlePortrait')[str] === "y");
}

var portraitOpacity = param("Opacity") || 255;
var xOffset = param("X Offset") || 0;
var yOffset = param("Y Offset") || 0;
var hide1 = boolp("Hide during item and skill selection");
var hide2 = boolp("Hide during enemy target selection");
var hide3 = boolp("Hide during ally target selection");
var autoAdjust = boolp("Auto Adjust");
var imageFilename = PluginManager.parameters('BattlePortrait')["Image Filename"];

//===========================================================
// Scene_Battle
//
var alias_scene_battle_creation = Scene_Battle.prototype.createSpriteset;
Scene_Battle.prototype.createSpriteset = function() {
alias_scene_battle_creation.call(this);
this._battlePortraitWindow = new Window_BattlePortrait();
this.addChild(this._battlePortraitWindow);
};

var alias_scene_battle_actorcmdselect = Scene_Battle.prototype.startActorCommandSelection;
Scene_Battle.prototype.startActorCommandSelection = function() {
alias_scene_battle_actorcmdselect.call(this);
this._battlePortraitWindow.setActor(BattleManager.actor());
};

var alias_scene_battle_update = Scene_Battle.prototype.update;
Scene_Battle.prototype.update = function() {
alias_scene_battle_update.call(this);

// Update Battle Portrait Visibility
this._battlePortraitWindow.visible = this._actorCommandWindow.isOpen() && !this._actorCommandWindow.isClosing();
if (autoAdjust) this._battlePortraitWindow.visible = this._battlePortraitWindow.visible && !(this._battlePortraitWindow.x === 0 && this._battlePortraitWindow.y === 0);
if (hide1) this._battlePortraitWindow.visible = this._battlePortraitWindow.visible && !(this._skillWindow.active || this._itemWindow.active);
if (hide2) this._battlePortraitWindow.visible = this._battlePortraitWindow.visible && !this._enemyWindow.active;
if (hide3) this._battlePortraitWindow.visible = this._battlePortraitWindow.visible && !this._actorWindow.active;
};

//===========================================================
// Window_BattlePortrait
//
function Window_BattlePortrait() {
this.initialize.apply(this, arguments);
}

Window_BattlePortrait.prototype = Object.create(Window_Base.prototype);
Window_BattlePortrait.prototype.constructor = Window_BattlePortrait;

Window_BattlePortrait.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, 0, 0, Graphics.boxWidth, Graphics.boxHeight);
this.opacity = 0;
this._image = new Sprite();
this._image.opacity = portraitOpacity;
this.addChild(this._image);
};

Window_BattlePortrait.prototype.setActor = function(actor) {
this._image.bitmap = ImageManager.loadSystem(eval(imageFilename));
};

Window_BattlePortrait.prototype.update = function() {
if (!autoAdjust) return;
if (!this.visible && !this.x === 0 && !this.y === 0) return;

if (this._image.bitmap && this._image.bitmap.width !== 0) {
this.x = Graphics.width - this._image.bitmap.width - xOffset;
this.y = Graphics.height - this._image.bitmap.height - yOffset;
}
}

/* END */
})();

The thing is I have 2 portraits for each of my actors, depending on them wearing "equipment type 4" or not.
If equipment type 4 is worn : display portrait 1
If equipment type 4 is not worn : display portrait 2
I had planned on using this : $gameActors.actor(x).equips()[4] === null

Do you think it's possible to implement this in the plugin in some way ? via the "advanced usage" part or by changing the code ?

With the way the Plugin works, maybe something like this for the filename :
'actor' + actor.actorId() + '_' + actor.EquipmentType4()

I've messaged the creator of the plugin but I am also asking here.

Thanks in advance.
Please don't put full plugins into your posts, many authors prohibit redistribution.

Just link to where we can read them (as @Kenen already did).

But yes, isn't your question answered right in the instructions for the plugin?

It says the Image filename parameter is a formula and even gives an example of using code.

If you want to put a conditional inline, you can just use a ternary operator.
Code:
"Actor" + actor.actorId() + (actor.equips()[4] ? "_1" : "_2")

So you'd have
Actor4_1
for wearing the equipment and
Actor4_2
for not wearing it.
Noted for the full plugin.

As for the code, I had no idea how to write it properly in this context, or if it was even right.
I'm gonna go try it right away.
Note I had a small typo with an extra plus sign. In case you were copy/pasting that line, I've corrected it.
It's finally working.
A huge thanks

Original thread: https://forums.rpgmakerweb.com/threads/problems-with-battlemanager-mv.162329/