Problem in class selector

I don’t want my game to start… unless there’s a player on the other team

look the video

sorry my English is bad :smiling_face_with_tear:

Hey @Faisal907 how are you?

I’ve been trying to do this and I found an approach that is not so hard to implement!

The idea is to check if the conditions are met (2 teams with at least 1 player each) whenever a player enters or leaves a team.

To do it, you only need to setup your Calss Selectors with a Player Counter for each one, and a Timer Device. Then, you will use Verse to register to some events from the Player Counter devices and execute some logic as shown below:

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

game_start_conditioned := class(creative_device):

    # Timer device used to delay the start of the round
    @editable
    RoundStartTimer : timer_device = timer_device{}
    
    # Player Counter devices, each one associated with a team/class selector
    @editable
    PlayerCounters : []player_counter_device = array{}

    # Team Selector devices, they are here only to turn them off after round start
    @editable
    TeamSelectors : []class_and_team_selector_device = array{}
    
    # -------------------------------------------------------------------------------#
    # Minimum number of players required on a team for it to be considered "ready"
    PlayersOnTeamRequiredToStart : int = 1

    # Number of teams that must meet the requirement for the round to begin
    TeamsRequiredToStart : int = 2
    
    # Index of the "holding" or "dummy" team where all players are placed initially
    DummyTeamIndex : int = 4
    
    # Tracks whether the minimum team conditions are currently met
    var TeamsAreReady : logic = false
    

    OnBegin<override>()<suspends>:void=
        # Send all existing players to the dummy team at match start
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers):
            AssignPlayerToDummyTeam(Player)

        # Send newly joined players to the dummy team
        GetPlayspace().PlayerAddedEvent().Subscribe(AssignPlayerToDummyTeam)

        # Listen for changes in every Player Counter device
        # Any time a team gains or loses a player, re-check readiness conditions
        for (PlayerCounter : PlayerCounters):
            PlayerCounter.CountedEvent.Subscribe(CheckReadyTeams)
            PlayerCounter.RemovedEvent.Subscribe(CheckReadyTeams)

        # When the timer completes successfully, start the round
        RoundStartTimer.SuccessEvent.Subscribe(StartRound)

    # Moves a given player into the dummy team        
    AssignPlayerToDummyTeam(Player:agent) : void =
        TeamCollection := GetPlayspace().GetTeamCollection()
        Teams := TeamCollection.GetTeams()

        # Retrieve the dummy team using its index
        if(DummyTeam := Teams[DummyTeamIndex]):
            # Attempt to add the player to the dummy team
            if(TeamCollection.AddToTeam[Player, DummyTeam]):


    # Called whenever player counts change on any team            
    CheckReadyTeams(Agent:agent) : void =
        # Keeps track of how many teams meet the minimum player requirement
        var ReadyTeamsCounter : int = 0
        
        # Count teams that have enough players to be considered "ready"
        for (PC : PlayerCounters):
            PlayerCount := PC.GetCount()
            if (PlayerCount >= PlayersOnTeamRequiredToStart):
                set ReadyTeamsCounter += 1

        # Update TeamsAreReady based on whether enough teams qualify
        if (ReadyTeamsCounter >= TeamsRequiredToStart):
            set TeamsAreReady = true
        else:
            set TeamsAreReady = false

        # If teams are ready, start the timer
        # If they stop being ready, pause and reset the timer
        if (TeamsAreReady = true):
            RoundStartTimer.StartForAll()
        else:
            RoundStartTimer.PauseForAll()
            RoundStartTimer.ResetForAll()

    # Called when the round starts to disable all the Team Selection stage devices (RoundStartTimer, PlayerCounters and TeamSelectors)
    DisableTeamSelectionDevices():void=
        RoundStartTimer.Disable()
        for (PlayerCounter : PlayerCounters):
            PlayerCounter.Disable()
        for (TeamSelector : TeamSelectors):
            TeamSelector.Disable()
    

    StartRound(Agent:?agent) : void =
        # This function is called when the timer finishes successfully
        Print("THE ROUND STARTS NOW!")
        DisableTeamSelectionDevices()
        # Place round-start logic here (spawning, enabling devices, etc.)

Some clarifications:

  • You can change the values of PlayersOnTeamRequiredToStart, TeamsRequiredToStart, and DummyTeamIndex variables to adapt to the number of teams you want for your Island. In my example I’m using 3 teams (teams from 1 to 3) and a dummy team (team 4) to place all the players when they login, so they don’t count for the condition to start the round
  • You should implement all the logic of the Round Start into the function “StartRound()”, turning on the devices that your island will need to work and turning of the devices that are only part of the team selection phase.

The code avobe includes comments explaining what is the functionality of each of its parts, but let me know if you don’t understand anything!

Hope this helps you!