I am currently working on a test project multiplayer game, and I have 4 buttons that set an integer value to players 1-4 team. I wanted to compare the 4 of these values, so that they cannot begin the game with all 4 being on the same team. I do not care about which order they are in or anything, I just need all 4 to not be the same, like if I had three 1s and a 2 or two 2s and two 3s. Is this at all possible?
Yes, it is definitely possible to compare the values of the integers assigned to each player’s team and check whether all four values are the same.
You would have to make sure the server have a final decision here and receives all of the player data. This is a great explanation of where values can be stored so that clients can speak to each other:
Assign each player’s selected team number to a variable, such as “Player1Team”, “Player2Team”, “Player3Team”, and “Player4Team”. This can be done with an integer or some other variable. I mean a simple boolean could do the trick to see if a member is ready.
Alternatively:
- Declare a set variable to store the unique team numbers. You can do this in your game mode or player controller blueprint.
- When a player selects a team number, add it to the set. You can do this by calling the “Add” function on the set variable with the selected team number as the input.
- After all players have selected their teams, check the size of the set. If the size is less than four, it means that at least two players have selected the same team. In this case, you can display an error message or take some other action to prevent the game from starting.
1 Like
Thank you very much! I will give it a go.