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 ![]()
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 ![]()
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:
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!
first thank you bro
bro sorry he not run ..Everything is as it was before.
This is what I did, look at the picture… because I can’t explain it in English.
I await your reply, and thank you.
Hello again!
At a first glance, I have a question: are you using Team 1 for the spectators? I’d recomend you to use the last available team for the spectators (3 in your case) and reserve teams 1 and 2 as the playable teams to avoid any issues with the code.
In addition, you can use the last team as dummy team, as it doesn’t count for the condition to start the game (team 3 in your case, that should be the same as the spectators team).
Try implementing those changes and let me know if it works!
In case it doesn’t works, please, let me know if you are using a different verse code with the same devices and share it here as text so I can test it!
I’ll be waiting for your answer!