HUD Party member stats on screen

Hello guys!
I found this plugin that @Trihan did for me, and I would like to change it to show the HP, MP, LV, and "to next level" gauges bars of the second member of the party. Yes, only the second member. (taking into account that the leader is the first member)

If I change the second member of the party, It would change the HP, MP and LV information to the other actor.

It´s possible?

Thanks in advance!!


Code:
//=============================================================================
// MapHUD.js
//=============================================================================

/*:
 * @plugindesc Simple HUD plugin for thalesgal.
 * @author John Clifford (Trihan)
 *
 * @param X
 * @desc The x coordinate of the window
 * @default 0
 *
 *
 * @param Y
 * @desc The y coordinate of the window
 * @default 0
 *
 * @help
 *
 * Just puts a HUD on the screen that shows the level/HP/MP of the party leader.
 *
 */

(function() {
    var parameters = PluginManager.parameters('MapHUD');
    
    function Window_HUD() {
        this.initialize.apply(this, arguments);
    }
    
    Window_HUD.prototype = Object.create(Window_Base.prototype);
    Window_HUD.prototype.constructor = Window_HUD;
    
    Window_HUD.prototype.initialize = function() {
        Window_Base.prototype.initialize.call(this, parameters['X'], parameters['Y'], 350, 150);
        this.opacity =0;
    };
    
    Window_HUD.prototype.update = function() {
        this.contents.clear();
        this.drawLeaderHUD();
    };
    
 Window_HUD.prototype.drawLeaderLevel = function(leader, x, y) {
        var color1 = this.hpGaugeColor1();
        var color2 = this.hpGaugeColor2();
        this.drawGauge(10, 0, 150, (leader.currentExp() - leader.expForLevel(leader._level)) / (leader.nextLevelExp() - leader.expForLevel(leader._level)), color1, color2);
        this.changeTextColor(this.systemColor());
        this.drawText("Lv", 10, 0, 20);
        this.resetTextColor();
        this.drawText(leader.level, 40, 0, 10, 'right');

    };
    
    Window_HUD.prototype.drawLeaderHUD = function() {
        var leader = $gameParty.members()[0];
        this.drawLeaderLevel(leader, 50, 0);
    this.opacity =0;
        this.drawActorHp(leader, 10, this.lineHeight(), 150);
        this.drawActorMp(leader, 10, this.lineHeight() * 2, 150);       
    };
    
    _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        this._hudWindow = new Window_HUD();
        this.addChild(this._hudWindow);
    };
        
})();
Replace the 0 with 1 here:
var leader = $gameParty.members()[0];
Hi! Thank you for reply!
It didn´t work :/

I think the problem is in it:
Code:
Window_HUD.prototype.drawLeaderHUD = function() {
        var leader = $gameParty.members()[0];
        this.drawLeaderLevel(leader, 50, 0);
    this.opacity =0;
        this.drawActorHp(leader, 10, this.lineHeight(), 150);
        this.drawActorMp(leader, 10, this.lineHeight() * 2, 150);

There are a lot of ''leader'' mentions, but I don´t know for what name I have to change.
Could you help me?

Thanks in advance!
Up
Does anyone can help me with this please? :LZScheeze::LZScheeze:
What @Poryg suggested should work. If it doesn't something else is causing a problem.

The word "leader" is being used because this is the name that was chosen for the variable. This line here defines the variable:

Code:
var leader = $gameParty.members()[0];

By changing this line to:

Code:
var leader = $gameParty.members()[1];

We are referencing the second member of the party, but the name of the variable stays the same. This variable could have been called almost anything and it would make no difference to how the plugin functioned, to change it now would be unnecessary.
Thank you for the explanation. But it didn´t work:
error.jpg

I´m realy bad with code, even if it is something very easy to fix I probably would not see it at all.

Here is the whole script. I made the arrows where I changed to 1, and where the error "currentexp" is.
plugin error.jpg
Are you testing the suggested changes while having a party without a second member?
If so, try this:
Code:
var leader = $gameParty.members()[1] || return;

You are getting an error at currentExp() because you don't have a character at slot 2 to be classified as a leader. Your error doesn't says currentExp() is undefined. It says leader is undefined thus it can't access a currentExp() from a non-existent object.
The only reason why that could be is, your party is a size of one. Is that true?
Btw. Thanks for the mention, I didn't get an alert of a new message previously.
@CaRa_CrAzY Thank you for your help!
When I put the ''return'' as you said the error message did not happen anymore.
But the HUD did not show up! Even with the [0] to show the leader, it did not appear anymore.

@CaRa_CrAzY , @Poryg
Yes! I was starting without a second party member! If I start the game with a second member, with this parameter
var leader = $gameParty.members()[1], it works nicely!
But, if I remove the second member it shows the "currentexp" message error again.

Could you guys help me? The ''Return'' didn´t work.
Moved to: Javascript/Plugin Support
And what exactly are you trying to achieve with the return?
All right. In my arrogance I tried to write it just in one line, but it looks like it doesn't work that way in Javascript.
Anyways, I think this will do the trick. The method will run only if there is a second party member.

Code:
var leader = $gameParty.members()[1];
if(!leader) return;
@CaRa_CrAzY Thank you so much!! It works perfectly!

Thank you bro!!!

Original thread: https://forums.rpgmakerweb.com/threads/hud-party-member-stats-on-screen.105246/