How to choose a random player from all the currently online players on a server?

Started by AInvisiblePerson on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to choose a random player from all the currently online players on a server?

I am currently working on a mod where a player has a hot potato and every session it resets to a random player, but I can't figure out how to choose a random player without there being a chance of no one getting the potato or more than one person getting it.

Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I just thought of a way to…
Sat, 01/28/2023 - 20:15

I just thought of a way to do it: set a true/false variable to false until it gives someone the potato. When it does, set the variable to true so it'll stop trying to give it to someone. Have a way to set the variable back to false, though.

Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use the "for each player in…
Mon, 01/30/2023 - 18:03

Use the "for each player in current world" block in conjunction with FiveNights2161's post.