MV Issues when using Game_Party.prototype.maxBattleMembers to limit battling party members

Hey, I've been using a plugin which edits Game_Party.prototype.maxBattleMembers to only let the first two characters enter battle.
Code:
Game_Party.prototype.maxBattleMembers = function() {    return 2;
So let's say the party has 4 members: John, Vincent, Patsy and Marshall. With the plugin on, only John and Vincent take part in the battle. Outside of battle, Patsy and Marshall are still in the team.
Now things get complicated because I'm trying to setup a way to change one of the two battling members with the other two mid-battle.
I have no idea how the engine handle these things but maxBattleMembers set to 2 doesn't really remove Patsy and Marshall entirely from the party during the battle. In fact, running a script mid-battle (via a Skill that calls a Common Event)
Code:
$gameParty.swapOrder(x, y)
where x is John and y is Marshall, does indeed swap John for Marshall.
But there are some things which don't work the same way, as if maxBattleMembers actually removed these characters from the game.
Let's say I want to bring up a choice between Patsy and Marshall when I want to kick John out of the battle.
I setup a Show Choice with /P[1], /P[2], /P[3] and /P[4] as options but only John and Vincent names appear on the window. Choice n°3 and 4 work, but are empty for some reason. Disabling the plugin gives me Patsy and Marshall names.
Setting up Conditional Variables for each party member to check if they are available or not before running the swap script also doesn't work in battle. If I make it an event in the overworld, it works as intended. So it has to be that maxBattleMembers plugin that removes some info regarding the characters.

What I need is a way to force the game to "return" all the necessary info about non-battling characters when making a switch during battle, until the switch is made. Or an alternative to the plugin I have been using. Thanks for your attention.
I don't know how battle part exactly does, but there is a plugin
to swap actors in battle, one of YEP plugins.

if you want to avoid that, the entire party may be inside the an array,
to check the party length.

than swap those order correctly to show only the first 2 inside the array.

think you need a bit more coding to save the party members you had in party.
as length of battle = 2, so anything outside may be removed.
so you need to safe guard your party members length as well to make them
as reserve if you obtain them.

there is a few plugins that does that, but I can't point out to them currently.
The problem is most likely the initialisation of the battlers, especially if you're changing the battlesystem from default.

many battle plugins need additional data on the battlers to handle their mechanics, and these values are usually added on battlesetup for the battlemembers - which means that actor 3 & 4 do not get that initialisation because they are in the reserve party at battlestart.

and then you swap them into the battleparty without adding the required initializations for your plugins...
that is known to cause problems depending on which battle plugins you use, and is the same reason why you need a summoning plugin compatible with your battlesystem as well if you want to summon actors instead of swapping them..
Setting up Conditional Variables for each party member to check if they are available or not before running the swap script also doesn't work in battle. If I make it an event in the overworld, it works as intended. So it has to be that maxBattleMembers plugin that removes some info regarding the characters.
thats actually a base engine behavior. what Game_Party.members returns is context sensitive. If its in battle, its specifically the party members in battle, else its all the actors in the party.

I setup a Show Choice with /P[1], /P[2], /P[3] and /P[4] as options but only John and Vincent names appear on the window. Choice n°3 and 4 work, but are empty for some reason. Disabling the plugin gives me Patsy and Marshall names.
try this
Code:
Window_Base.prototype.partyMemberName = function (n) {
    var actor = n >= 1 ? $gameParty.allMembers()[n - 1] : null;
    return actor ? actor.name() : '';
};
Hey,

Many operations that work on party members will only consider the battle party during battle. It is a feature baked into the default code base.

If you want party names to consider all party members, you could copy the respective function into a new plugin and replace $gameParty.members() with $gameParty.allMembers():
Code:
Window_Base.prototype.partyMemberName = function(n) {
    var actor = n >= 1 ? $gameParty.allMembers()[n - 1] : null;
    return actor ? actor.name() : '';
};

If you don't want to use an extra plugin, an alternative might be to store the party member names in variables first (through the Script option in Control Variables; replace "ID" with the position of the party member, starting at 0):
let actor = $gameParty.allMembers()[ ID ]; actor ? actor.name() : ""


As for initialization, I do not think this is the issue here, but by default MV does have some issues where battle start- and end effects are only applied to the active party:
States that are supposed to disappear at the end of a fight are not removed if the actor is not in the party at the end of battle. Likewise TP is not properly initialized for actors joining the party after the battle has started.
So this may be something to keep in mind.
Edit3: This can be a problem when adding/removing actors from the party mid fight, this is not a problem for reserve party members, as Solar_Flare points out below.

Edit: Too slow.
Edit2: Fixed the script line
Likewise TP is not properly initialized for actors joining the party after the battle has started.
As someone who was recently doing something similar, I'm glad you brought this up, because I completely forgot about TP initialization.
I am not doing any changes to the battle system other than limiting the battlers, Andar. I thank Robro and Another Fen for their help, now Show Choice brings up the other party members.
If you don't want to use an extra plugin, an alternative might be to store the party member names in variables first (through the Script option in Control Variables; replace "ID" with the position of the party member, starting at 0):
You mean I would need to add that at the start of each battle, right? If that's the case, I think using a plugin is preferable here.
Regarding the TP inizialitation and status issues...ehhh that's a problem for another day :hswt:
As someone who was recently doing something similar, I'm glad you brought this up, because I completely forgot about TP initialization.
Regarding the TP inizialitation and status issues...ehhh that's a problem for another day :hswt:
everyone forgot something, its mostly is the smallest details to look over.

but it's mostly sooner than later ^^
It turns out that TP initialization runs on the entire party (that is to say, it happens before the "in battle" flag is turned on), so I didn't need to do anything, as my use-case was swapping in reserve members on TPK. At least, it does that in my project – I didn't check if that may be caused by another plugin I'm using.
It turns out that TP initialization runs on the entire party (that is to say, it happens before the "in battle" flag is turned on), so I didn't need to do anything, as my use-case was swapping in reserve members on TPK
Oh, wow. I did remember running into this problem when adding party members mid fight, I didn't notice this was taken care of for reserve party members.
Thanks for sharing.

You mean I would need to add that at the start of each battle, right? If that's the case, I think using a plugin is preferable here.
I was originally thinking that the best way to do this would probably right before the "Show Choice" command.
If you don't mind the extra plugin then using that is probably the easier solution anyways.
Ah, yes, if you were adding a completely new member in the middle of the fight, certainly you'd still need to init their TP.

Original thread: https://forums.rpgmakerweb.com/threads/issues-when-using-game_party-prototype-maxbattlemembers-to-limit-battling-party-members.180645/