MZ Swap Actors on Menu Screen outside of Equip/Skill

While making custom UI (and by extension separate inventories for different actors) I found that I need a script which would allow to swap actors on menu screen outside of the equip/skill selection. I believe it would be keyboard only, with pressing <- or -> resulting in switching between actors. It won't conflict with menu buttons selection, because it's done by UP and DOWN buttons instead.
I was trying to make a script like that on my own, but I was having some problems with that, and while I'm working on other stuff I decided to try and search for help here.
How do you want it to work? In base code if you select a command that needs character selection, it activates the status window and then when you press space does stuff depending on what command is selected. So do you want the ok key and up/down to still react to the command menu?

You can overwrite the command window cursor right and cursor left methods and make it select next/previous index in the statuswindow. That will show the highlight automatically I think. You might also make it so then that it automatically selects 1st index at start and also change it so that it doesn't deselect to index -1 when you leave the statuswindow.
Yeah, ok, up and down keys should still work, it's just that pressing left or right will change the index of the character similar to how the status window handles it. And when menu screen initially appears it should deffault to first character present. I believe that's how I was trying to implement it, but it was really inconsistent and sometimes didn't work in multiple button presses. I think I should send whatever I was left with at that point, but I'm not sure how well it works.
This seemed to work for me.
Though there might be some windows that inherit from that Window_MenuCommand, so you'd want to change their cursorRight and cursorLeft methods back to the original ones.

Window_MenuCommand.prototype.cursorRight = function() {
const statusWindow = SceneManager._scene._statusWindow;
if (statusWindow) {
const maxIndex = $gameParty.battleMembers().length - 1;
statusWindow._index += 1;
if (statusWindow._index > maxIndex)
statusWindow._index = 0;
statusWindow.refreshCursor();
}
};

Window_MenuCommand.prototype.cursorLeft = function() {
const statusWindow = SceneManager._scene._statusWindow;
if (statusWindow) {
const maxIndex = $gameParty.battleMembers().length - 1;
statusWindow._index -= 1;
if (statusWindow._index < 0)
statusWindow._index = maxIndex;
statusWindow.refreshCursor();
}
};

const _myEdit1_WindowMenuStatus_initialize = Window_MenuStatus.prototype.initialize;
Window_MenuStatus.prototype.initialize = function(rect) {
_myEdit1_WindowMenuStatus_initialize.call(this, rect);
this._index = 0;
this.refreshCursor();
};

Scene_Menu.prototype.onPersonalCancel = function() {
// this._statusWindow.deselect();
this._commandWindow.activate();
};
Sadly, it doesn't seem to work (despite changing something on input, it still calls the status menu when pressing equip/skill, and disabling that doesn't make it work). Altough I'm curious what 'cursorRight' and 'cursorLeft' means, because I never saw them before.
I tested it quickly earlier and all basic functions seemed to work for me. I didn't quite understand what you mean isn't working for you? Are you using other plugins that affect menu? Did you disable the plugin above that you made yourself?

Though if you want the selection to always stay on the current actor when you select a menu command that needs a selection, you'd need to add the left/right move save the last actor also.

EDIT:
Though I'm probably still not understanding what you want to do in the end. The code I provided makes you just able to place the selection on the status window characters with left/right even when in command menu (you can add code to make something happen when you place the selection on them).
Here, I made a video demonstration with just this plugin installed. It swaps between actors, but when equip menu is called, it deffaults to the first actor again. Well, that's basically what you said at the end of the reply.
Put in the end of the cursor left/right methods that:

const actor = statusWindow.actor(statusWindow.index());
$gameParty.setMenuActor(actor);

You might also want to put in the initialize method that it uses the menuactor index if available. Depending on how you want it to work.
I tried it with this fix, and it seems to work almost perfect now. The only thing that bothers me a bit is that leaving the menu deffaults to first actor - it would be nice to make it so it stays on the last selected one. Also, it's a bit on a theory side, but is it possible to track actor ID during switching? I planned to use this system for separate inventories, so that would be handful. Thanks.

P.S. Oh, I tried to make it so it skips the status window of the equip window, but now it prevents me from exiting the menu screen.

Code:
const Alias_ForceEquip = Scene_Menu.prototype.createCommandWindow = function() {
  const rect = this.commandWindowRect();
  const commandWindow = new Window_MenuCommand(rect);
      commandWindow.setHandler("equip", this.commandEquip.bind(this));
      this.addWindow(commandWindow);
      this._commandWindow = commandWindow;
};

Scene_Menu.prototype.commandEquip = function() {
      SceneManager.push(Scene_Equip);
};

P.S.S. It seems to actually be kinda bugged when I turn off the equip status window? Sometime it stays on same actor after changing to the other one. It works fine with status window still being on, but I wanted to get rid of it.
Yeah, you can put in the initialize that:
this._index = $gameParty.menuActor().index() || 0;

Then in Scene_Menu.prototype.createCommandWindow change the equip line from commandPersonal to:
this.commandEquip.bind(this)(and add a method for that which pushes the equip scene, so imitating what it does with item).

So below is everything. But if you want this stuff to work perfectly with formation changes, you might need to add even more stuff.
Oh and you can get the dude selected with $gameParty.menuActor() or id with $gameParty.menuActor().actodId();

Window_MenuCommand.prototype.cursorRight = function() {
const statusWindow = SceneManager._scene._statusWindow;
if (statusWindow) {
const maxIndex = $gameParty.battleMembers().length - 1;
statusWindow._index += 1;
if (statusWindow._index > maxIndex)
statusWindow._index = 0;
statusWindow.refreshCursor();
}
const actor = statusWindow.actor(statusWindow.index());
$gameParty.setMenuActor(actor);
};

Window_MenuCommand.prototype.cursorLeft = function() {
const statusWindow = SceneManager._scene._statusWindow;
if (statusWindow) {
const maxIndex = $gameParty.battleMembers().length - 1;
statusWindow._index -= 1;
if (statusWindow._index < 0)
statusWindow._index = maxIndex;
statusWindow.refreshCursor();
}
const actor = statusWindow.actor(statusWindow.index());
$gameParty.setMenuActor(actor);
};

const _myEdit1_WindowMenuStatus_initialize = Window_MenuStatus.prototype.initialize;
Window_MenuStatus.prototype.initialize = function(rect) {
_myEdit1_WindowMenuStatus_initialize.call(this, rect);
this._index = $gameParty.menuActor().index() || 0;
this.refreshCursor();
};

Scene_Menu.prototype.onPersonalCancel = function() {
// this._statusWindow.deselect();
this._commandWindow.activate();
};

Scene_Menu.prototype.createCommandWindow = function() {
const rect = this.commandWindowRect();
const commandWindow = new Window_MenuCommand(rect);
commandWindow.setHandler("item", this.commandItem.bind(this));
commandWindow.setHandler("skill", this.commandPersonal.bind(this));
commandWindow.setHandler("equip", this.commandEquip.bind(this));
commandWindow.setHandler("status", this.commandPersonal.bind(this));
commandWindow.setHandler("formation", this.commandFormation.bind(this));
commandWindow.setHandler("options", this.commandOptions.bind(this));
commandWindow.setHandler("save", this.commandSave.bind(this));
commandWindow.setHandler("gameEnd", this.commandGameEnd.bind(this));
commandWindow.setHandler("cancel", this.popScene.bind(this));
this.addWindow(commandWindow);
this._commandWindow = commandWindow;
};

Scene_Menu.prototype.commandEquip = function() {
SceneManager.push(Scene_Equip);
};
Wow, it works perfectly now. Huge thanks, I'll try to look into it and figure out how this works to get better in the coding in future. I should even save this page so I can look into it in the future. And for it to also get marked as solved.

Original thread: https://forums.rpgmakerweb.com/threads/swap-actors-on-menu-screen-outside-of-equip-skill.184003/