TransWikia.com

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

Arqade Asked by SteakOverflow on December 12, 2020

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

2 Answers

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.

Answered by SteakOverflow on December 12, 2020

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

Answered by forbym on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP