Hello, i need help, im trying to build some kind of an Among Us map, and im trying to get a code that picks a random players and changes their team to team 2.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# A Verse-authored creative device that can be placed in a level
Team_manager := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
AllPlayers:= GetPlayspace().GetPlayers() # Collect players available in the map
TeamCollection:= GetPlayspace().GetTeamCollection() # Collect the team collection
ActiveTeams:= TeamCollection.GetTeams() # Collect active teams in the map
if (
Index:= GetRandomInt(0, AllPlayers.Length-1) # Select random number in range of total players
RandomPlayer:= AllPlayers[Index] # The randomly selected player
TeamCollection.AddToTeam[RandomPlayer, ActiveTeams[1]] # Add the randomly selected player to the desired team (team 2 in this case)
):
I have this code but it doesn’t work good, can anybody help me?
What behavior do you notice exactly? is the “if” just failing? try putting an else with a print and see if that’s the cause. The code seems relatively correct to me, except I would have just shuffled the array itself and then picked whatever was at index 0. Maybe trying to swap teams exactly on onbegin is not 100% certain to work, would putting a sleep(0.1) or something make this code less prone to fail? other than that I have no other idea on what could cause it to not work.
Well, it does work, i forgot to explain that this code is part of something bigger, I would be very grateful if you send me a DM on discord.
pizzasteve4848
thats my discord tag.
If you dont want to see the full thing, heres a summary:
When the game starts, we have a code that 1 players turns into a “monster”. The problem is that the monster is always going to be the first person to load on the island. We want the monster to be only in team 2, but we cant make it.
Another solution we could do is that the monster could be activated by a trigger, but i don’t have the enough knowledge in Verse to do that.
Okay so i think the code works. But the monster still loads to the first person on the island and idk how to fix that (nor idk what causes it)
here is the code if you wanna look at it
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }