Party Rotation with Button Press

I have been searching around and I can't seem to find a solution to this, at least for MV. Basically, in the game I am creating, there are party members who can do various actions (e.g. one can break boulders, another has a light source, another moves fast, another can walk on ice tiles, etc.). You would need to rotate the party formation and have a certain member be the leader in order to do a certain action. However, I would like to rotate the party formation with the use of a button (e.g. the "S" key).

So for example, default party is structured like so at the start:
[A, B, C, D]

When pressing the "S" key, party structure becomes:
[B, C, D, A]

And likewise, if you press "S" again, party structure will be:
[C, D, A, B]

And so on, and so forth.

I tried looking for a plugin that could help out but PH Swap Party hasn't been working for me even when turning off my other plugins, and I've only seen scripts of this calibre be VX Ace only, so I tried thinking of scripting it myself instead.

So far, I thought of:
rotatepartyformationwithbutton.PNG


Then I'm kind of stuck on how to do the party rotation part. I would very much appreciate it if someone can help out.
This Thread has a list of many Scriptcommands to rebuild Event Commands but more flexible.

This seem to work on my end, but it is with the Page Up Button.
partyrotator15465652.png
Hi there!
In addition to what @Bex said, don't know if you can run into any problems using the "removeActor" function. But another solution would be something similar to what Bex did, but on the script call part you would do this:

JavaScript:
const firstActor = $gameParty._actors.shift()
$gameParty._actors.push(firstActor)
$gamePlayer.refresh() // You need to call that.

The proper function to do this, the same way the menu does, is that one:

JavaScript:
Game_Party.prototype.swapOrder = function(index1, index2) {
    const temp = this._actors[index1];
    this._actors[index1] = this._actors[index2];
    this._actors[index2] = temp;
    $gamePlayer.refresh();
};

I can see that it did not remove any actor id on the process, so don't know if either my solution or the Bex one could lead you into any trouble.
don't know if you can run into any problems using the "removeActor" function
Removing the last living actor causes a game over. A workaround for this with native functions only is having death be removed at the end of battle, or briefly giving the entire party death immunity, rearranging the party, then removing the death immunity.
The removing and adding of the Actor is directly executed after each other without any Waits or Page Changes, therfor it should not be possible to trigger a Game Over.
Edit2: Just tested it, no Game Over, works seemingly flawless.

What Bug i could think of but did not occur, is that the Event Command Add Actor, got a Box for "Initialise" , so a Char starts from Level 1 again, i dont know script equivalent for that, but thanks to
the PC gods the Script Command does add the Actor back like it was and does not initialise it again and again to LV1.

Edit: If the Mage is Dead, she could still be Selected as Map Char and run around.
That could be fixed with some more code Logic if needed.
@Bex - I'm pretty sure I've done it correctly as you've instructed but nothing happens when I press the PageUp key. Could a plugin be perhaps interfering somehow? That being said, thank you very much for the Script Call List! Definitely bookmarking and looking through that.
1659168896281.png


@Eliaquim - For your method, I assume it's a conditional branch then insert the first Javascript code (const firstActor etc.) as a Script Call?

@RianQuenlin - I actually won't be having battles at all in this project: it's all puzzles and you die if your HP goes to zero from obstacles such as spikes in the floor and poisonous gas, so...would that make things more difficult or easier? (Or even neither?)
Yes it could. No problem, you are Welcome.

Trouble shoot guesses:
Page Up Key = Q Button on Keyboard
Page Down Key = W Button on Keyboard
Normaly the Page Up Button should also work.

- Make sure no other Events or Common Events with trigger "Autorun" are active.
- Did you test it on the Correct Map, since you rebuild it as Map Event and not directly into Common Event.
- I would recomment testing it in a fresh Project, to exclude Project stuff interfering.
- Keyboard Button Plugins installed?
@Bex - I'm pretty sure I've done it correctly as you've instructed but nothing happens when I press the PageUp key. Could a plugin be perhaps interfering somehow? That being said, thank you very much for the Script Call List! Definitely bookmarking and looking through that.
View attachment 236147

@Eliaquim - For your method, I assume it's a conditional branch then insert the first Javascript code (const firstActor etc.) as a Script Call?

@RianQuenlin - I actually won't be having battles at all in this project: it's all puzzles and you die if your HP goes to zero from obstacles such as spikes in the floor and poisonous gas, so...would that make things more difficult or easier? (Or even neither?)
On my side you just need that:

if page up is pressed down
copy and paste this as a script call:
const firstActor = $gameParty._actors.shift()
$gameParty._actors.push(firstActor)
$gamePlayer.refresh() // You need to call that.

And maybe add a wait command of 10 frames, so the event does not repeat too fast.

Also, maybe the Page Up button is not working because it is detecting by pressing(holding for an amount of time) instead of triggered.

I have created a plugin for MZ in the past with the same functionality.
It is possible to port this plugin to MV, so please be patient.
@Bex - Just as you responded, I actually found the culprit as to why it didn't work - a plugin (YEP Party System). Turned it off, did input with the S key in a common event, and it wound up working. Thanks a lot again for the help!

Though just wondering - how would this method work if I wanted to assign say the A key to shuffle the party formation in the reverse order?
So if Key1 (S) is pressed, then order goes from A, B, C, D ---> B, C, D, A.
But when Key2 (A) is pressed, order goes from A, B, C, D ---> D, A, B, C.

@Eliaquim - I was able to make Bex's method work after turning off one of Yanfly's plugins. But thank you very much for your help regardless!

@siguren - While I've found out what was wrong on my end, that plugin would be amazing to see finished for MV: especially as I also wanted the A key to shuffle the party in reverse order. Take your time with it though. 🙂
Though just wondering - how would this method work if I wanted to assign say the A key to shuffle the party formation in the reverse order?
So if Key1 (S) is pressed, then order goes from A, B, C, D ---> B, C, D, A.
But when Key2 (A) is pressed, order goes from A, B, C, D ---> D, A, B, C.

Don't you just run the remove actor / add actor stuff three times?
Don't you just run the remove actor / add actor stuff three times?
Tried it out before as a Common Event but I wound up getting an error:
1659173239455.png


I could be implementing it wrong though. Here's what it looks like in the Common Event:
1659173306411.png

1659173352447.png
For the reverse change we have to check how many Party Members are in the Party.
Here a example for 4 Member Party, you have to make the other cases yourself, else it would not have fit the Picture.
If you run in trouble, you can get further help with this.
reversepartychange065465.png
Do you need 3 variables, because when you remove the first actor then the next becomes party member 1, right? And you can just use the same variable (edit: use the same command that gets the actor id of party member 1 to that same variable).
.
@Bex - I now have the A and S keys successfully shuffling the party leader back and forth. Again, thank you kindly for everything. 😀
Do you need 3 variables
In this setup, yes. Edit: Now while thinking more about it, iam not sure anymore.

@Bex - I now have the A and S keys successfully shuffling the party leader back and forth. Again, thank you kindly for everything. 😀
Good to hear that it helped you.
In case you need adjustments, let us know in the Thread.
Just as a quick note, another method for this without having to worry about the accidental game over stuff is to just use the built-in swapOrder() method.
I created RpgMakerMV version.
Adding plugin commands for MV.
There is almost no explanation in English, but I think it's okay because I don't do anything complicated.

I created RpgMakerMV version.
Adding plugin commands for MV.
There is almost no explanation in English, but I think it's okay because I don't do anything complicated.


While I've had the problem solved, thank you very much for taking the time to complete the plugin! I'm certain others will highly appreciate it. 😀

Original thread: https://forums.rpgmakerweb.com/threads/party-rotation-with-button-press.149937/