How do you assign a role to a random player in Rec Room?

How do you assign a role to a random player in Rec Room? - Positive Asian boy wearing protective helmet and sportswear of American football player in yellow studio

How do I assign a specific role to a single, randomly selected player and make sure nobody else has the role?



Best Answer

My own take on this was the following:

Preconditions:

  1. Set up a game rules chip with 2 teams.

Random selection:

  1. Remove the role from all players (-1 to remove role chip).
  2. Move everyone to team 1.
  3. Move everyone to team 2. (This is to get rid of gaps in the player team indexes.)
  4. Select a random number between 1 and size of team 2 (inclusive), take that as player team index and use the team mapper to get the player id. Assign The role to that player.

This might require some short delays between each step.

However this solution has several drawbacks:

  • It interfers with the team assignments. So you can only really do this if you don't mind everyone being on the same team, or can change the team assignments afterwards in circuits.
  • It requires each team to be able to contain all players in the room.
  • It takes a bit of time, which means that it can break if a player leaves the room during the selection process.



Pictures about "How do you assign a role to a random player in Rec Room?"

How do you assign a role to a random player in Rec Room? - Small boy in uniform of sports player
How do you assign a role to a random player in Rec Room? - A Man in Green Crew Neck T-shirt Playing Computer Games
How do you assign a role to a random player in Rec Room? - A Man in Black Crew Neck T-shirt Using a Computer Keyboard





How To Automatically Assign Roles in Rec Room | Rec Room Tutorial




More answers regarding how do you assign a role to a random player in Rec Room?

Answer 2

Ok, here is a revised version based on the idea of skipping empty slots (new posting in order to avoid that the old comments become confusing). I'm assuming there are maximum T teams and maximum P players on each team.

Step 1: Remove the role from all players (-1 to Role Mapper chip).

Step 2: Pick a random number A between 0 and T*P (exclusive). Pick another random number B between 1 and the number of players in the game (inclusive) (number of players is provided by Player Event chip).

Step 3: Initialize a counter N with 0.

Step 4: Initialize a "slot counter" S with A.

Step 5: For any value of the slot counter S, compute the team as S/P+1; and the index on the team with (S mod P)+1. Use the Team Mapping chip to get the Player ID for each value of S. If you get a valid Player ID, increase the counter N by 1.

Step 6: If N == B, assign the role to this player and end.

Step 7: Change S to (S+1) mod (T*P).

Step 8: Continue with Step 5

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Amina Filkins, Amina Filkins, Yan Krukov, Yan Krukov