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)

Active 3 years ago
Joined Jul 2022
Points:
395

User statistics:

  • Modifications: 0
  • Forum topics: 2
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1
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.

Active 4 months ago
Joined Jun 2021
Points:
671

User statistics:

  • Modifications: 2
  • Forum topics: 16
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 40
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.

Active 2 years ago
Joined Mar 2022
Points:
475

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 9
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.