Change Party Leader

I was wondering if there's a way to change the position of an actor when he's added to the party, and make him the leader. I couldn't find any method to do it, so i hope that someone can help me
Thank you in advance.
there are probably scriptcalls, but I dont know them, but do you want it to be forced or
in which way?

In battle or out battle (on the map) because those things can matter to the set up.
As default - if you don't use plugins that may alter this behavior -, when you add an actor It's added on the last position of your party.
So, after using the event command for adding a new party member, you can try to use this script call:

Code:
$gameParty.swapOrder(0, $gameParty.members().length - 1)

This way, you will swap the order of the Party Leader (Index O) with the last member of the party.

Or, a more complex version - if the script above does not work as you want -:

Code:
var all_members = $gameParty.allMembers();
var actor_id_to_find = 2; // This is the actor ID of the actor you have added and you want to swap;
var position_to_swap = 0;
for(var i = 0; i < all_members.length; i++) {
if(all_members[i].actorId() === actor_id_to_find) {
position_to_swap = i;
break;
}
}
$gameParty.swapOrder(0, position_to_swap);
Code:
$gameParty.swapOrder(0, $gameParty.members().length - 1)

Thanks! That's just what I needed! I'm sorry If I haven't answered before but I couldn't test the code until today.
Thank you, you were my private Jesus Christ.

naomex1, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/change-party-leader.114641/