How do I choose a random player?

Hello!

So I’m working on a multiplayer game, where the game chooses a random player, who will be the “killer”. Others will be normal guys. I didn’t find lot of information about this. So How do I choose a random player to be the “killer”?

Sorry for asking, but how can i make an array all the players in it?

i think that when players are connectd, when you launch your game, the server should choose the random player and assign it the correct pawn.
like , get all the connected players in an array, choose one randomly in the array, and set this player to use the “killer” pawn

You want to utilize the event OnPostLogin in your gamemode, or game instance blueprints. it is triggered anytime someone connects and has been assigned their player controller. The pin it provides is the reference to that assigned player controller. you can make an array and pick via that.

314596-plogin.png

I successfully made the array and It choose a random player controller, but how can i print a text for only the killer and a text for only the normal guys? I tried the posses node, but when I cast to the KillerPawn It always fails. What can I do?

I’m not sure why your cast to killerPawn always fails, be sure that your game modes class defaults are using your specific player controller, its possible its still set to the default.

to display a message to the specific player you will need to create a custom event on the player controller then and set it to run on owning client. As a note, print statements display to all screens by design, so even for testing you will want to use a widget.

My example logic here of the postlogin is a just a rough one. I need the delay because the clients are still loading when the server has added them, and thus can miss instructions. I recommend that your player controllers report in that they’ve finished loading up before gameplay progresses.

oops. forgot the gamemode defaults picture

Wow! Everything worked. Thanks for the help! :smiley:

i have the same question how to make an array with players in it

How to do this fpr an Variable. here should be the IsKiller Variable should be set to true for 1 time by 5 players.