I’m making this map where every few seconds, players switch positions. works great with 2 players, however, doesn’t work very well with many players, especially an odd number, with 2 or more players teleporting to the same player. How would I change my code to make it work as intended? As I want players to switch randomly.
Code:
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# A Verse-authored creative device that can be placed in a level
TeleportRandomizer := class(creative_device):
@editable
var Teleporters : []teleporter_device = array{}
var FortMap : [fort_character]int = map{}
var PossibleIndexes :[]int = array{0, 1, 2, 3, 4, 5, 6, 7}
var PlayerIndex : int = 0
var RiftsCanTeleport : logic = true
var BreakLoop : logic = false
var My_Teleporter : teleporter_device = teleporter_device{}
AssignRifts()<suspends> : void=
loop:
for (FortCharacter->Index : FortMap):
PlayerPosition : vector3 = FortCharacter.GetTransform().Translation
if (Teleporter := Teleporters[Index]):
Teleporter.Enable()
if(FortCharacter.IsActive[]):
if (RiftsCanTeleport?):
if(Teleporter.TeleportTo[PlayerPosition, rotation{}]):
else:
Teleporter.Disable()
Sleep(0.016)
RemoveSelfFromList(Integer:int) : void=
if(PossibleIndexes.RemoveElement[Integer]):
SWITCH()<suspends> : void=
loop:
Sleep(5.0)
set RiftsCanTeleport = false
for (FortCharacter->Index : FortMap):
if (Indexes := PossibleIndexes.RemoveElement[Index]):
RandomIndex := Shuffle(Indexes)
for (RIndex : RandomIndex):
if (Agent := FortCharacter.GetAgent[]):
if (Teleporter := Teleporters[RIndex]):
Teleporter.Teleport(Agent)
set My_Teleporter = Teleporter
My_Teleporter.Disable()
Sleep(3.5)
set RiftsCanTeleport = true
My_Teleporter.Enable()
GameBegin()<suspends> : void=
AllPlayers := GetPlayspace().GetPlayers()
for (Player : AllPlayers):
if (FortCharacter := Player.GetFortCharacter[]):
if (set FortMap[FortCharacter] = PlayerIndex):
set PlayerIndex += 1
Print("{PlayerIndex}")
spawn{AssignRifts()}
spawn{SWITCH()}
OnBegin<override>()<suspends>:void=
GameBegin()