Pre-Game Team Balancing Strategy : Seeking Expert Insights

Hello everyone, :slight_smile:

I am developing a game mode where I want to allow players to freely choose their teams before the start of the game. I am looking to implement a mechanism that automatically balances the teams only during this pre-round phase.

Once the game starts, this script should no longer execute, and another standard script takes over to manage the rebalancing of players who join the game in progress, (for which I already have functioning code from the official Fortnite documentation.) :slight_smile:

Could you advise me on the best way to implement this initial team checking and balancing only before the game starts? :confused:

Thank you for your help and suggestions !

Well, the code itself is just simple arithmetic.
/Fortnite.com/Teams has all the methods you need.

Hello,

First thanks for answering but it’s not that easy for me …
i tried this :confused: but it’s not working i’am so sad… :frowning:

Here a video of all the test :

Code :

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }

balance_device := class(creative_device):
@editable PlayerCounterBleu : player_counter_device = player_counter_device{}
@editable PlayerCounterRouge : player_counter_device = player_counter_device{}

@editable  TriggerBleu : trigger_device = trigger_device{}
@editable  TriggerRouge : trigger_device = trigger_device{}

OnBegin<override>()<suspends>:void=
    spawn{ ManageTeamBlue() }
    spawn{ ManageTeamRed() }
    spawn{ ManageDeviceBlue() }
    spawn{ ManageDeviceRed() }

ManageDeviceBlue()<suspends>:void= #Device Blue
    if( PlayerMax := GetPlayspace().GetPlayers().Length /2 ): 
        PlayerMaxInt := Ceil(PlayerMax)

        Print("PlayerMax := {PlayerMaxInt}")
        if(TeamCountBlue.Length = PlayerMaxInt):     
            Print("PlayerCounterBleu.Disable()")
            PlayerCounterBleu.Disable()
        else:
            Print("PlayerCounterBleu.Enable()")
            PlayerCounterBleu.Enable()

ManageDeviceRed()<suspends>:void= #Device Red
    if( PlayerMax := GetPlayspace().GetPlayers().Length/2 ): 
        PlayerMaxInt := Ceil(PlayerMax)
        Print("PlayerMax := {PlayerMaxInt}")
        if(TeamCountRed.Length = PlayerMaxInt):     
            Print("PlayerCounterBleu.Disable()")
            PlayerCounterRouge.Disable()
        else:
            Print("PlayerCounterBleu.Enable()")
            PlayerCounterRouge.Enable()
       

var TeamCountBlue : []agent = array{} #Team Blue
ManageTeamBlue()<suspends>:void=
    loop:
        Agent:=PlayerCounterBleu.CountedEvent.Await()
        TriggerBleu.Trigger(Agent)
        set TeamCountBlue += array{Agent}
        spawn:
            ManageDeviceBlue()

var TeamCountRed : []agent = array{} #Team Red
ManageTeamRed()<suspends>:void=
    loop:
        Agent:=PlayerCounterRouge.CountedEvent.Await()
        TriggerRouge.Trigger(Agent)
        set TeamCountRed += array{Agent}
        spawn:
            ManageDeviceRed()

Test and questions :

Testing Team Selection and Balancing on My Game Map :

Objective : Create a XvsX player with balanced teams but with the opportunity to player to choose their team at start to be abble to play with friend in same team.

Initial Solo Test:
    I tried to join the Blue team, resulting in a team status of 1/1 for Blue and counter blue counter diseappear and 0/1 for Red. Consequently, the Blue team still activated and shouldn't. because already full with only one player in the map and in the blue team.

Switch to Red Team:
    I changed my team to Red, updating the status to 0/1 in Blue and 1/1 in Red and red counter diseappear. Blue counter still diseppear but (team selector still work and for red also very weird)

Attempt to Return to Blue Team:
    On my last attempt, I tried going back to the Blue team, so it switched me to blue but the teleporter don't work anymore. This leads me to believe that my counter for teams are disabled when I'm alone on the map. Ideally, I should be able to switch between teams repeatedly when solo.


Desired Team Balancing Feature:
    I aim to implement a system similar to what is described here: Team Multiplayer Balance in Verse. Unlike the automatic balancing at the start, 

For example : I want to allow players to choose their teams upon arriving at the beginning of the game (for about one minute). After this period, I plan to balance the teams if they are not equal or force them to be equal by some means.
Additionally, when a new player joins the game, I want them to be assigned to the team with the lowest number of players to maintain balance.

Request for Assistance:

Please, I urgently need help with Verse code or any ideas for implementing these features using Blueprints.

Thank you in advance for your support!

Cheers,