Dynamically changing the maximum number of followers and battlers

Hello, RPG Maker noob here.

I've been searching for around two days for an answer to this question, but I can't find it answered clearly or properly anywhere.
I am using many of the Yanfly's plugins, (including YEP_PartySystem), I've searched around for many plugins to see if any of them have this functionality, but they're all locked to the value you set in the plugin configuration, and doesn't seem to offer an option to change it on the fly through events (either script calls or plugin commands).

I am trying to make sections of the game where, although you have your full party in the party screen, only the first member of the party shows up in the battle. It would be good to be able to change the number of followers dynamically as well, and then other sections where it shows the full party, both followers and battle. So far, I haven't found any way to achieve this, events or plugins.

Any help would be appreciated, as searching always gives me the same results.
I haven't tested any of this, but I'm fairly sure this will work. Save this as a .js file and add it as a plugin --> change the X to the variable ID that you want to use for the # of battle members. Now you can just change the variable and the number of party members that appear in battle should change.
Code:
Game_Party.prototype.maxBattleMembers = function() {
    return $gameVariables.value(X) || 4;
};

For the followers part, I'm less sure about. But you can try adding this into the plugin --> change the X to the variable ID you want to use for the # of followers.
Code:
Game_Followers.prototype.initialize = function() {
    this._visible = $dataSystem.optFollowers;
    this._gathering = false;
    this._data = [];
    for (var i = 1; i < $gameVariables.value(X) || $gameParty.maxBattleMembers(); i++) {
        this._data.push(new Game_Follower(i));
    }
};

Game_Follower.prototype.actor = function() {
    return $gameParty.members()[this._memberIndex];
};

This is all from the base engine and no guarantees that it works with whatever other plugins you have installed.
Oh wow, you arrived to save the day again!

I just had a quick test without any plugins. On the battler part, it works pretty well. Unfortunately on the followers part, if I add that section of code, the game doesn't even reach the menu. (It stays black for a while then crashes to desktop).

Now, something very odd and funny happens. With only adding the battler section of code, I did try it with a few Yanfly's plugins. (Many of the cores and also party system and row formations). Not sure which one is doing it, but as soon as I move, the number of followers changes to the number of battlers. Although it would have been nice to keep those separate, it still works for the purpose I was looking for, haha.

Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/dynamically-changing-the-maximum-number-of-followers-and-battlers.97567/