Can't give you the code you want without a copy of your game code to play with, however I can point in a seemingly random direction and hope you can work it out from there.
Let’s say you have 8 party members divided between two teams
First it will need to know who is where, so
If chara1 is on team1
Yes: set variable "#chara1 location" to 1
No: If chara1 is on team2
Yes: set variable "#chara1 location" to 2
No: set variable "#chara1 location" to 0
Do this for each chara
It will also need to know how many on each team, so with a slight mod
Set variable "#team1" to 0 < these are only at the beginning, don’t replicate for each chara
Set variable "#team2" to 0 < these are only at the beginning, don’t replicate for each chara
If chara1 is on team1
Yes: set variable "#chara1 location" to 1
set variable “#team1” +1
No: If chara1 is on team2
Yes: set variable "#chara1 location" to 2
set variable “#team2” +1
No: set variable "#chara1 location" to 0
Now it knows whose where and how many on each team.
If “#chara1 location” is equal to 0
Yes: If “#team1” is less then 4
Yes: Add Chara1 to team1
Set “#team1” +1
Set “#chara1 location” to 1
Repeat this for each chara, then
If “#chara1 location” is equal to 0
Yes: If “#team2” is less then 4
Yes: Add Chara1 to team2
Set “#team2” +1
Set “#chara1 location” to 2
Repeat that for each chara
And that’s it.
Enjoy!
Hmm... Just looking back over the pseudo code I wrote, and I think I could write a rather simple team switching system, and with a little modification the teams could be in separate places at once. Sweet I might just use it too, in one form or another.