Solved - Pokémon like - battle (with suggestion)

I would like to have a battle system like pokémon, where the first actor goes in battle and, when he dies, the next alive one goes in battle, while the first one is moved from the first position of the party to the last one. Can someone help me? 


(I don't know much about MV libraries... this is all I can do for the moment)


*NOT WORKING EXAMPLE*

Code:
//There will be only one member in battle (the first one)
Game_Party.prototype.maxBattleMembers = function() {
    return 1;
};

//when the first member dies, it doesn't mean it's gameover
Game_Unit.prototype.isAllDead = function() {
    var temp=$gameParty.allMembers();
	var i=;
	//if the first member is dead, i have to...
	if ($gameParty.allMembers()[].isDead())
	{
	//...check if someone is alive
	while ($gameParty.allMembers()[i].isDead())
	{
	i++;
	//if all members are dead, it's gameover
	if (i>=$gameParty.allMembers().length) 
	{
	return true;
	}
	}
	//member i is alive
	//I need to set him as first member to show him as a battler
	var j;
	//remove all party members
	for (j=;j<$gameParty.allMembers().length;j++)
	{
	$gameParty.removeActor(temp[j]);
	}
	//add the alive member as first
	$gameParty.addActor(temp[i]);
	//add all the other members...
	for (j=;j<$gameParty.allMembers().length;j++)
	{
	//...except the one already added
	if (j!=i) $gameParty.addActor(temp[j]);
	}
	}
	$gameParty.battleMembers()[]=temp[i];
	return false;
};
I'm working on this currently. I'll update you when it's finished or close to.
I found one! HERE you go!
I found one! HERE you go!

🤘

Original thread: https://forums.rpgmakerweb.com/threads/solved-pokemon-like-battle-with-suggestion.59840/