The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Tutorials and Eventing => Topic started by: pacdiggity on July 12, 2011, 09:06:27 AM

Title: [VX/XP] How to swap actors around.
Post by: pacdiggity on July 12, 2011, 09:06:27 AM
Yo, I'm going to show you how to change the order of actors in the party whenever you feel like it. It's pretty dang easy.

You're going to want a common event if you want the player to be able to switch the order around whenever. Set it to parallel process, and set the trigger switch to anything you want, and activate it whenever you want them to be able to switch actors, and turn it off whenever you want it fixed.
Inside the event, place a conditional branch. This branch can be one of two things:
1. The (whatever) button is being pressed
2. Script: Input.trigger?(Input::Whatever)
Note that whatever must be Down, Left, Right, Up, A, B, C, X, Y, Z, L or R. Unless you're using a custom input script; if so just follow the instructions of that.
Inside the branch, use a script command. Have the command say this:
FOR VX
Code: [Select]
id = $game_party.members[0]
$game_party.remove_actor(id)
$game_party.add_actor(id)
FOR XP
Code: [Select]
id = $game_party.actors[0].id
$game_party.remove_actor(id)
$game_party.add_actor(id)
And the actor in the first position will now be in the last position, and all the others will have moved up one position. Why?
When you add an actor to the party, it automatically goes to the last position. When you remove an actor from the party, all others in positions further up than theirs go down. What we did was remove the actor in the first position from the party, then add it so it's at the last index. Why did we use 0 as the index? Because in Game_Party, the members/actors constant is an array, the indexes of which begin at 0.
After that script call, add, in the conditional branch, a wait command of 4-10 frames. This will keep the player from having to guess when to stop pressing the button, because common events run each frame and it's quite difficult to hold down a button for a sixtieth of a second.

It's all pretty dang simple. If anyone has a problem or wants screenshots, just ask.