How to get and compare the custom properties of all players inside a room?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to get and compare the custom properties of all players inside a room?

Tatsuki
2022-03-24 14:52:04

Hello, I'm trying to create a basic multiplayer game using Photon. I apologize if this is a silly question but I've been stumped already for 2 days. Inside the room, there should be an equal number of player for team 1 and team 2 before the button on the master client should be set to active. This button is what takes all the players to the actual game scene.

Each player has a custom property:

ExitGames.Client.Photon.Hashtable playerPropTeam = new ExitGames.Client.Photon.Hashtable();    

each players can then set their team through a button

public void OnClickChangeTeam()        
{    
        if ((int)playerPropTeam["playerTeam"] == 0)    
        {    
            playerPropTeam["playerTeam"] = teams.Length - 1;    
        } else    
        {    
            playerPropTeam["playerTeam"] = (int)playerPropTeam["playerTeam"] - 1;    
        }    
        PhotonNetwork.SetPlayerCustomProperties(playerPropTeam);    
        //print(playerPropTeam["playerTeam"].ToString());    
    }    

teams.Length is just 2 = 0 and 1. "0" is Team 1 while "1" is Team 2. This code is saved on a prefab playerItem.

On another script, the only conditions for my button is just this:

    private void Update()    
    {    
        if (PhotonNetwork.IsMasterClient && PhotonNetwork.CurrentRoom.PlayerCount >= 2)    
        {    
            playButton.SetActive(true);    
        }else    
        {    
            playButton.SetActive(false);    
        }    
    }    

TLDR; I want the play button to only be active if there are equal numbers of players inside the room with a custom properties of: playerPropTeam[playerTeam] = 0 and playerPropTeam[playerTeam] = 1

appreciate any help thanks!

Comments

Tatsuki
2022-03-28 07:17:06

Welps we can use:

PhotonNetwork.LocalPlayer.CustomProperties["playerTeam"]    

to access a custom property of local player in another script and make a system around that xD

Back to top