Download

Best way to get player in gamemode?

The question is more complicated than what the title suggests, but I didn’t know how else to put it in such short words.

Here is the situation. I want to post a message from one player to another. In my gamemode I have a list of all connected controllers, which is great. But Only the server has the game mode and only the server therefor has acces to all controllers. The message is sent from a certain player to the gamemode. The gamemode then gets said message and there is where I’m stuck. To pass the message to the gamemode I have a function that includes a few inputs, such as the message itself and a reference to the playerstate, which is how I manage to select the player I want to send a message to. But now I have a playerstate reference and a array of all connected controllers. How can I get the correct controller from the array using the reference of the playerstate? Or is there a better way to “find out” in the gamemode which player I need to send the message to?

Use the GameState, not the GameMode.
The GameState has an array of PlayerStates. Simply iterate over the PlayerState Array and check if the PlayerState == Receiving PlayerState