[Multiplayer] How to randomly select one player?

Report any bugs here or ask questions here!

[Multiplayer] How to randomly select one player?

Postby KrulYuno » 26 December 2019, 19:26

I want to select 1 player from all currently playing players.

For example:

  • There are 3 players in game, I wanted to randomly select one person from 3 players.
  • There are 8 players in game, I wanted randomly select one person from 8 players.
  • There's only 1 player in game, no one should get selected.

I tried using slots but I can't figure out which slot has the player on. I can't select a slot that has no player on it.

KrulYuno
 
Posts: 3
Joined: 10 April 2018, 15:56

Re: [Multiplayer] How to randomly select one player?

Postby jeje52 » 27 December 2019, 13:56

Randomize a value between 0 and the max player count on your map. If the player that gets selected has more than 0 hp, you can be sure that the slot has a player on it. When the hp is 0 or less, you should simply randomize the value again until you get a player that is alive. The randomized value should then be synced, as randomized values tend to be different for every player.
You can skip all this when the amount of players alive is 1.
This method would work perfectly as long as every player is alive. I haven't come up with a way to get around that.
User avatar
jeje52
Civil Security Lite [100]
 
Posts: 146
Joined: 13 April 2018, 19:52


Return to Bug Reporting, Help & Support

Who is online

Users browsing this forum: No registered users