How to join room by matching room property in lobby ?

Options
Hi to join room
I am doing such like this :
if(roomInfo.playerCount != roomInfo.maxPlayers && roomInfo.customProperties.ContainsValue("black"))
{
PhotonNetwork.JoinRoom(roomInfo.name);
}

How to match room property ? like : Red team player, blue team player Room Joining
Thanks in advance

Best Answers

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    hi @JANESTHEKING,

    You can find your answer in our "Matchmaking Guide" doc.
  • JANESTHEKING
    edited June 2016
    Options
    yeah, i have already seen it.


    Here is my code for joining and creating room :
    
    void OnGUI() 
    {
        if(PhotonNetwork.insideLobby )
        {
            rooms = PhotonNetwork.GetRoomList ();
            if(isRoomJoin )
            {   
                PlayerIdLstInRoom.Clear ();                 
                if(PhotonNetwork.GetRoomList().Length >= 1 )
                {
                    foreach (RoomInfo roomInfo in rooms)
                    {
                        if(room_Name.Contains("black"))
                        {
                            if(roomInfo.customProperties.ContainsKey("black") && 
    						   roomInfo.maxPlayers ==  MaxPlayerFromTable)
                            {
                                PhotonNetwork.JoinRandomRoom() ;
                                isRoomJoin = false;                                                         
                                                            
                            }                                               
                            else
                            {
                                string chosenLevel = room_Name + Random.Range(0,99);;
                                string gameType = "black";
                                
                                Hashtable customPropertiesToSet = new Hashtable();
                                customPropertiesToSet.Add("black", chosenLevel);
    
                                string[] customPropertiesForLobby = new string[1];
                                customPropertiesForLobby[0] = "black";
                                RoomOptions roomOptions = new RoomOptions() 
                                {
                                    isVisible = true, 
                                    isOpen = true,
                                    maxPlayers = (byte)MaxPlayerFromTable,
                                    customRoomProperties = customPropertiesToSet,
                                    customRoomPropertiesForLobby = customPropertiesForLobby 
                                };              
                                PhotonNetwork.CreateRoom(chosenLevel,  roomOptions,  TypedLobby.Default);
                                isRoomJoin = false;
                                
                            }
                        }
                        else if(room_Name.Contains("red"))
                        {
                            if(roomInfo.customProperties.ContainsKey("red") && 
    						   roomInfo.maxPlayers ==  MaxPlayerFromTable)
                            {
                                PhotonNetwork.JoinRandomRoom() ;
                                isRoomJoin = false;                                                         
                                
                            }   
                            else
                            {
                                string chosenLevel = room_Name + Random.Range(0,99);;
                                string gameType = "red";                            
                                Hashtable customPropertiesToSet = new Hashtable();
                                customPropertiesToSet.Add("red", chosenLevel);
                                string[] customPropertiesForLobby = new string[1];
                                customPropertiesForLobby[0] = "red";
                                RoomOptions roomOptions = new RoomOptions() 
                                {
                                    isVisible = true, 
                                    isOpen = true,
                                    maxPlayers = (byte)MaxPlayerFromTable,
                                    customRoomProperties = customPropertiesToSet,
                                    customRoomPropertiesForLobby = customPropertiesForLobby 
                                };              
                                PhotonNetwork.CreateRoom(chosenLevel,  roomOptions,  TypedLobby.Default);   
                                isRoomJoin = false;
                            }
                        }
                    }           
                }
                else
                {
                    if(room_Name.Contains("black"))
                    {
                        string chosenLevel = room_Name + Random.Range(0,99);
                        string gameType = "black";
                        
                        Hashtable customPropertiesToSet = new Hashtable();
                        customPropertiesToSet.Add("black", chosenLevel);
    
                        string[] customPropertiesForLobby = new string[1];
                        customPropertiesForLobby[0] = "black";
                        RoomOptions roomOptions = new RoomOptions() 
                        {
                            isVisible = true, 
                            isOpen = true,
                            maxPlayers = (byte)MaxPlayerFromTable,
                            customRoomProperties = customPropertiesToSet,
                            customRoomPropertiesForLobby = customPropertiesForLobby 
                        };              
                        PhotonNetwork.CreateRoom(chosenLevel,  roomOptions,  TypedLobby.Default);
                        isRoomJoin = false;
    
                        }
                    else if(room_Name.Contains("red"))
                    {
                                        
                        string chosenLevel = room_Name + Random.Range(0,99); ;
                        string gameType = "red";
                        
                        Hashtable customPropertiesToSet = new Hashtable();
                        customPropertiesToSet.Add("red", chosenLevel);
    
                        string[] customPropertiesForLobby = new string[1];
                        customPropertiesForLobby[0] = "red";
                        RoomOptions roomOptions = new RoomOptions() 
                        {
                            isVisible = true, 
                            isOpen = true,
                            maxPlayers = (byte)MaxPlayerFromTable,
                            customRoomProperties = customPropertiesToSet,
                            customRoomPropertiesForLobby = customPropertiesForLobby 
                        };              
                        PhotonNetwork.CreateRoom(chosenLevel,  roomOptions,  TypedLobby.Default);
                        isRoomJoin = false;
                    }
                }   
            }
        }
    }
    

    Sometimes joining and sometimes not :
    Please help.
  • JANESTHEKING
    edited June 2016
    Options
    hi thank you so much for answer.
    I am doing like this :

    To create room :
    string roomname = "ABC";
    string color = "black";
    string level = "1";
    Hashtable roomProps =  new Hashtable(){{ "Color", color }, {"Level", level} };
    string[] roomPropsInLobby = { "Color", "Level" };
    RoomOptions roomOptions = new RoomOptions()
    {
    	isVisible = true, 
    	isOpen = true,
    	customRoomProperties = roomProps,
    	customRoomPropertiesForLobby = roomPropsInLobby 
    };						
    PhotonNetwork.CreateRoom(roomname, roomOptions, TypedLobby.Default);     

    To Join/create ROOM :
    Hashtable expectedCustomRoomProperties = new Hashtable() 
    {
    	{ "Color","black" },
    	{"Level", "1" } 
    	};
    	PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, (byte)MaxPlayerFromTable);
     }
    But i am not able to join room and when joining room it gives me message like :
    JoinRandom failed: No open game.Calling: OnPhotonRandomJoinFailed() and staying on master server.

    Don't know why its coming.

    Please help . thanks again.
  • JANESTHEKING
    Options
    @JohnTube thank you so much. This is the thing that i want to do exactly using photon real time client sdk.