In game modes such as box fights players need to randomly spawn in their own box. With the new update this system can be now optimized which is what will be described here today.
Introduction
To accomplish random unique spawns we will use a random integer to determine the box. However we need to be able to not generate the same number used for the last player. This is so two players don’t end up in the same box. Essentially we are checking for exceptions to teleporting the player to their box however when generating a random integer we cannot choose numbers as exceptions during the generating[1]. We have to check for exceptions after.
For this guide you will need a live player counter to see if all players are readied up. I suggest you follow this guide right here. How to make a live player counter
Part 1 - Setting Spawns
First Grab a property. Name it “ExceptionsList”. Its settings should be default. Duplicate that property and name it “Spawn#”. Make it a number variable with a scope of player. Duplicate that property and name it “ReadyUp”. Change the scope to global and have it broadcast on “ReadyUpdated” when the value changes. Now duplicate the property and rename it “Live Players.” Those properties should look like this.
Now get a counter and have it be invisible in-game and increase when receiving on the channel “ReadyUp”. It should also update the property ReadyUp. It should look like this.
Go to the counter used in your Live player counter. Link it the the property “Live Players” Now grab a trigger. Change it to invisible in game and turn player collision off. It should receive on the channel “ReadyUpdated”. In block code put the following code.
Get a life cycle that is wired to a relay. The relay should receive on “Begin Set Spawns” and broadcast on “Set Spawns.” Now grab a trigger. Change it to invisible in game and turn player collision off. It should receive on the channel “Set Spawns”. In block code put the following code.
IMPORTANT - make sure you change the random integer from 42 to the number of boxes you have
This code generates the random number for a player’s spawn. It then uses the new blocks to check if that number is included in the exceptions list property. If it isn’t included it will set the player scoped property “Spawn#” to the random number. It then adds the spawn number to the “ExceptionsList”.
We have now accomplished making a system that will give each player a random spawn with no duplicates. This system is run on the channel “Begin Set Spawns.”
Part 2 - Teleporting to Spawns
The next thing you need is to make your boxes. In each box put one teleporter; these teleporters should be numbered in a grid and teleport player there when receiving on the channel “Box” + its number on the grid. Here is an example layout.
Get a relay. Have it receive on “SpawnAll” and broadcast on “SpawnIn” Now get another trigger. Set it to player collision off, and visible in game to no. Make the trigger receive on “SpawnIn.” in block code put the following.
We have now accomplished making a system that will teleport players to a random unique box after spawns are set. This system is run on the channel “SpawnAll”
Part 3 - Multiple Rounds
If your map needs to call the randomized spawns again (such as multiple rounds in box fights) you are going to want to add a few more things.
Go to your counter that updates the property “Ready Up.” Have it reset upon receiving on the channel “ResetSystem.” Now place a trigger[2] that is invisible in-game and cannot run on collision. It should also receive on “ResetSystem.” In block code it should set the property “ExceptionsList” to a blank text box with nothing in it.
Conclusion and Further Optimization
When you want to start another round you broadcast on “ResetSystem” to get the system ready to run again. Next you broadcast on “Begin Set Spawns.” Once the spawns are set (detectable upon receiving on “SpawnSet”) you can broadcast on “SpawnAll.”
Optimization 1
Broadcasting on three channels seems annoying. This can actually be condensed. Your random spawn can be set in the middle of a round since it is simply updating a property. Resetting properties can also happen in the middle of a round. Also if you are resetting these properties you are doing so with the intention of later setting the spawns and since setting spawns mid round doesn’t affect anything you can actually call “Begin Set Spawns” in the block code of the trigger (footnote 2) that resets the ExceptionsList. If you optimize it like so when the round starts you can simply broadcast on “ResetSystem” and then be able to call “SpawnAll” and start a new round whenever the round finishes.
TL;DR - make trigger that resets ExceptionsList also broadcast on “Begin Set Spawns”
Optimization 2
When starting the game you cannot “pre-load” the spawns as you normally can while players are actually playing during the round. This is only bad because if you try to broadcast on “Begin Set Spawns” and then “SpawnAll” before all players spawns are set a few players will not teleport and will end up excluded from your round. This is why there is the property “Ready Up” it checks to see if everyone has their properties set and then broadcasts on the channel “SpawnsSet.”
TL;DR - when starting the game broadcast on “Begin Set Spawns” and then broadcast on “SpawnAll” only after receiving on “SpawnsSet”
Difficulty Poll
- 0/10
- 1/10
- 2/10
- 3/10
- 4/10
- 5/10
- 6/10
- 7/10
- 8/10
- 9/10
- 10/10
- 11/10
For the Reader
This forum has a like button for a reason. If you Did read my post and appreciated it, leave a like. If you have a question about troubleshooting this guide then you can reply but I do not want empty comment posts such as “oh nice guide” or “This is really useful.” If you want to compliment at least make it meaningful and unique if not the like button is plenty. This is even part of the forum FAQ and Rules.*
By replying to this guide you acknowledge that you have read this whole guide, have an understanding of the replies and are not about to leave an empty comment.
Thanks,
This leads however to the hypothetical chance that the generated number is never the number needed to progress infinitely locking you in the situation where this system, or any others that rely on this will every work. However this probability is infinitely zero and realistically impossible to happen ↩︎
further optimization happens with this trigger later ↩︎