MV Row Formation (YEP) - Limiting max row size?

Hi all,

I'm having some trouble figuring out how to do this with Yanfly's Row Formation plug in. Maybe it will end up requiring a custom plug in, but I figure I'd ask here first.

Quite simply, I want to limit how many characters can be in a row. Like Etrian Odyssey, I would like a 3 person front row and a 2 person back row.

For such a robust plug in, I find it a little baffling that this isn't already one of the default options, unless I'm missing something.
The plugin otherwise meets all my needs, allowing attacks to shift rows and apply states based on row, but I do not want a player to be able to place all characters in the front or back row.

Any suggestions? Thank you.
Pop this below the YEP plugin, didn't test it, though. Should only let you leave the scene when the rows have equal to or less than the desired number of actors.

JavaScript:
(function() {

const MAX_ACTORS_PER_ROW = 3;

var _Scene_Row_create = Scene_Row.prototype.create;
Scene_Row.prototype.create = function() {
    _Scene_Row_create.call(this);
    this._rowFormationWindow.setHandler('cancel', this.onRowFormationCancel.bind(this));
};

Scene_Row.prototype.onRowFormationCancel = function() {
    if (this.areActorRowsValid()) {
        this.popScene();
    } else {
        SoundManager.playBuzzer();
        this._rowFormationWindow.activate();
    }
};

Scene_Row.prototype.areActorRowsValid = function() {
    for (let i = 1; i <= Yanfly.Param.RowMaximum; i++) {
        if ($gameParty.rowSize(i) > MAX_ACTORS_PER_ROW) {
            return false;
        }
    }
    return true;
};

})();
Pop this below the YEP plugin, didn't test it, though. Should only let you leave the scene when the rows have equal to or less than the desired number of actors.

JavaScript:
(function() {

const MAX_ACTORS_PER_ROW = 3;

var _Scene_Row_create = Scene_Row.prototype.create;
Scene_Row.prototype.create = function() {
    _Scene_Row_create.call(this);
    this._rowFormationWindow.setHandler('cancel', this.onRowFormationCancel.bind(this));
};

Scene_Row.prototype.onRowFormationCancel = function() {
    if (this.areActorRowsValid()) {
        this.popScene();
    } else {
        SoundManager.playBuzzer();
        this._rowFormationWindow.activate();
    }
};

Scene_Row.prototype.areActorRowsValid = function() {
    for (let i = 1; i <= Yanfly.Param.RowMaximum; i++) {
        if ($gameParty.rowSize(i) > MAX_ACTORS_PER_ROW) {
            return false;
        }
    }
    return true;
};

})();
This looks promising, I will test this asap, likely by tomorrow and let you know if it works. Much appreciated!
Pop this below the YEP plugin, didn't test it, though. Should only let you leave the scene when the rows have equal to or less than the desired number of actors.

JavaScript:
(function() {

const MAX_ACTORS_PER_ROW = 3;

var _Scene_Row_create = Scene_Row.prototype.create;
Scene_Row.prototype.create = function() {
    _Scene_Row_create.call(this);
    this._rowFormationWindow.setHandler('cancel', this.onRowFormationCancel.bind(this));
};

Scene_Row.prototype.onRowFormationCancel = function() {
    if (this.areActorRowsValid()) {
        this.popScene();
    } else {
        SoundManager.playBuzzer();
        this._rowFormationWindow.activate();
    }
};

Scene_Row.prototype.areActorRowsValid = function() {
    for (let i = 1; i <= Yanfly.Param.RowMaximum; i++) {
        if ($gameParty.rowSize(i) > MAX_ACTORS_PER_ROW) {
            return false;
        }
    }
    return true;
};

})();
This mostly worked. It does, in fact, prevent you from leaving if there are over 3 members in either row. Do you think it would be possible to have the front row limit be 3 and the back row limit be 2? This is the team comp I am hoping to implement. Thank you.
JavaScript:
(function() {

var _Scene_Row_create = Scene_Row.prototype.create;
Scene_Row.prototype.create = function() {
    _Scene_Row_create.call(this);
    this._rowFormationWindow.setHandler('cancel', this.onRowFormationCancel.bind(this));
};

Scene_Row.prototype.onRowFormationCancel = function() {
    if (this.areActorRowsValid()) {
        this.popScene();
    } else {
        SoundManager.playBuzzer();
        this._rowFormationWindow.activate();
    }
};

Scene_Row.prototype.areActorRowsValid = function() {
    if ($gameParty.rowSize(1) > 3) return false;
    if ($gameParty.rowSize(2) > 2) return false;
    return true;
};

})();

This assumes your first row is the front row and your second row is the back row. If you have any more rows than that, or add them later, this won't affect them.

Original thread: https://forums.rpgmakerweb.com/threads/row-formation-yep-limiting-max-row-size.180849/