MZ SRD Hud Maker Ultra (Checking who is leader and checking for other members)

I wondered how I would check who the leader is in SRD HUD Maker Ultra. I want to make a certain image appear if Actor 1 is the leader and he is the only one in the party. I placed the normal code that checks which character is the leader.
Code:
$gameParty.leader().actorId() === 2
However, inserting this code in the conditions in Hud Maker doesn't make the picture appear.
I am also wondering how I would also check if Actor 1 is the only character in the party. I plan to have other characters join the party, so I am asking this question.
Moved to: Plugin Support
I tried with this code, and it worked:

JavaScript:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
return leaderID === 2 && partySize === 1;

Edit: Party Size is obviously 1, I just was testing something on my end and forgot it to 2, now edited to be 1.
I tried with this code, and it worked:

JavaScript:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
return leaderID === 2 && partySize === 1;

Edit: Party Size is obviously 1, I just was testing something on my end and forgot it to 2, now edited to be 1.
Thanks for help it worked just like you said it would.
I know this wasn't in the original post or I thought it was but didn't clarify but, how would you check what party members are in the other party slots? I will have a maximum of 3 party members.
JavaScript:
const partySlot = 1;
const memberID = $gameParty.members()[partySlot-1]?.actorId() || 0;

You replace the partySlot with your desired slot number, starting from 1 (the leader). If there is such party member, to memberID would be assigned its ID, otherwise would be assigned 0.

That memberID still have to be compared to your desired value, and the result to be returned with the return statement.

For example, if you want to check both the party leader id to be 2, second member id to be 1, as well the party to be exactly of 2 members
JavaScript:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
const partySlot = 2;
const secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
return leaderID === 2 && partySize === 2 && secondMemberID === 1;
I got two members to appear on screen, but they are drawing from Acter 1's stats
Spoiler: Actor 1 Code
Code:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
const partySlot = 2;
const secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 1;
return leaderID === 1 && partySize === 2 && secondMemberID === 2;

Spoiler: Actor 2 Code
Code:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
const partySlot = 2;
const secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 1;
return leaderID === 1 && partySize === 2 && secondMemberID === 2;
;
JavaScript:
const partySlot = 1;
const memberID = $gameParty.members()[partySlot-1]?.actorId() || 0;

You replace the partySlot with your desired slot number, starting from 1 (the leader). If there is such party member, to memberID would be assigned its ID, otherwise would be assigned 0.

That memberID still have to be compared to your desired value, and the result to be returned with the return statement.

For example, if you want to check both the party leader id to be 2, second member id to be 1, as well the party to be exactly of 2 members
JavaScript:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
const partySlot = 2;
const secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
return leaderID === 2 && partySize === 2 && secondMemberID === 1;
I got the two-party member setup to work.
When I tried to move on to the three-party setup the hud elements didn't show up. I changed the code to this
Code:
const leaderID = $gameParty.leader().actorId();
const partySize = $gameParty.size();
const partySlot = 3;
const secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
const thirdMemberID = $gameParty.members()[partySlot-2]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;
Hmm, maybe better use "let" instead "const", because const declaration won't allow you to change variable value.

The code you wrote above, the "secondMemberID" is in fact third member too, because you set partySlot value to 3.
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let partySlot = 2;
let secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
partySlot = 3; //partySlot is already declared, here we assign new value to it.
let thirdMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;

It can be written shorter, with less variables, I simply tried to make it more readable.

For shorter version:
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let secondMemberID = $gameParty.members()[1]?.actorId() || 0;
let thirdMemberID = $gameParty.members()[2]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;

If doing it this way, only need to remember the index of party member is with one less than its actual position, so 4 th member is index 3, and leader is index 0.

Hope didn't do typo on my coding, as this time I wrote it directly on the reply box, without testing it.

The code can be optimized further, actually.

Spoiler
JavaScript:
if ($gameParty.leader().actorId() !== 1) return false; //leader not ID 1
if ($gameParty.size() !== 3) return false;// party size different than 3;
if (($gameParty.members()[1]?.actorId() || 0) !== 2) return false; //second member id not 2
if (($gameParty.members()[2]?.actorId() || 0) !== 3) return false; //third member id not 3
return true;//meets all criteria, return true (which shows the HUD component).

Or even further:
Spoiler
JavaScript:
return (
   $gameParty.leader().actorId() === 1 &&
   $gameParty.size() === 3 &&
   ($gameParty.members()[1]?.actorId() || 0) === 2 &&
   ($gameParty.members()[2]?.actorId() || 0) === 3
);
Since $gameParty.members()[2]?.actorId() gives undefined, if there is no such actor, the check undefined === 3 would be false too, can be writen like that too:
JavaScript:
return (
   $gameParty.leader().actorId() === 1 &&
   $gameParty.size() === 3 &&
   $gameParty.members()[1]?.actorId() === 2 &&
   $gameParty.members()[2]?.actorId() === 3
);

What important is, which of those you are most comfortable of using, and would be easier to edit to your liking.
Hmm, maybe better use "let" instead "const", because const declaration won't allow you to change variable value.

The code you wrote above, the "secondMemberID" is in fact third member too, because you set partySlot value to 3.
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let partySlot = 2;
let secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
partySlot = 3; //partySlot is already declared, here we assign new value to it.
let thirdMemberID = $gameParty.members()[partySlot-2]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;

It can be written shorter, with less variables, I simply tried to make it more readable.

For shorter version:
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let secondMemberID = $gameParty.members()[1]?.actorId() || 0;
let thirdMemberID = $gameParty.members()[2]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;

If doing it this way, only need to remember the index of party member is with one less than its actual position, so 4 th member is index 3, and leader is index 0.

Hope didn't do typo on my coding, as this time I wrote it directly on the reply box, without testing it.

The code can be optimized further, actually.

Spoiler
JavaScript:
if ($gameParty.leader().actorId() !== 1) return false; //leader not ID 1
if ($gameParty.size() !== 3) return false;// party size different than 3;
if (($gameParty.members()[1]?.actorId() || 0) !== 2) return false; //second member id not 2
if (($gameParty.members()[2]?.actorId() || 0) !== 3) return false; //third member id not 3
return true;//meets all criteria, return true (which shows the HUD component).

Or even further:
Spoiler
JavaScript:
return (
   $gameParty.leader().actorId() === 1 &&
   $gameParty.size() === 3 &&
   ($gameParty.members()[1]?.actorId() || 0) === 2 &&
   ($gameParty.members()[2]?.actorId() || 0) === 3
);
Since $gameParty.members()[2]?.actorId() gives undefined, if there is no such actor, the check undefined === 3 would be false too, can be writen like that too:
JavaScript:
return (
   $gameParty.leader().actorId() === 1 &&
   $gameParty.size() === 3 &&
   $gameParty.members()[1]?.actorId() === 2 &&
   $gameParty.members()[2]?.actorId() === 3
);

What important is, which of those you are most comfortable of using, and would be easier to edit to your liking.
The second one you provided is definitely a lot easier to edit. Thanks for helping me out with this.
[partySlot-2]
When commenting you selected same second and third member, so didn't seen this part 😀, that you actually subtract 2.

On this line, 3-2 =1, so you selected actually the second member, thinking is the third. And in the previous line, 3-1 = 2, you selected the third member, thinking is the second. I talk about the code of your previous post.

Will edit the first example in my reply too, because I copy pasted it and that part evaded my gaze 😀.

Also, glad I been helpful.

Original thread: https://forums.rpgmakerweb.com/threads/srd-hud-maker-ultra-checking-who-is-leader-and-checking-for-other-members.155063/