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
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
0
Best Answers
-
Doing matchmaking logic on client side is not recommended. This is from our Matchmaking Guide:
If you want to roll your own matchmaking, please make sure that most of that is done server side. The clients don't have perfect information about how full rooms are as the room-list update frequency from server to client is low (~1..2 seconds).
Please make use of Lobby Properties, for example, make one or more custom room properties visible to the lobby and use them as filters in random matchmaking:
When you have thousands of players, several will send their "join" requests at the very same time. If a room gets full quickly, your players will frequently fail to join rooms and matchmaking will take longer and longer.
- Key = "Color", Value= "Red" or "Black" or "Blue" etc.
- Key = "Level", Value= ?
There is no need to get rooms list at all.
Join Room:RoomOptions roomOptions = new RoomOptions(); roomOptions.customRoomPropertiesForLobby = { "Color", "Level" }; roomOptions.customRoomProperties = new Hashtable() { { "Color", color }, {"Level", level} }; roomOptions.maxPlayers = expectedMaxPlayers; PhotonNetwork.CreateRoom(roomName, roomOptions, typedLobby);
Create Room if "No Match Found":Hashtable expectedCustomRoomProperties = new Hashtable() { { "Color", targetColor }, {"Level", targetLevel } }; PhotonNetwork.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers);
5 -
Please try something like this. I'm not sure when and where you're trying to join/create rooms. Also I'm not sure if room creation ever happens. Please also do not use object initializers in Unity (e.g.
RoomOptions
, even so, you don't need to explicitly setisVisible
andisOpen
totrue
as that's their default value).using ExitGames.Client.Photon; using Photon; class Example : MonoBehaviour { public const byte MaxPlayerFromTable = 4; public void CreateRoom(string name, byte maxPlayers, object color, object level) { Hashtable roomProps = new Hashtable() { { "Color", color }, { "Level", level } }; string[] roomPropsInLobby = { "Color", "Level" }; RoomOptions roomOptions = new RoomOptions(); roomOptions.customRoomProperties = roomProps; roomOptions.customRoomPropertiesForLobby = roomPropsInLobby; roomOptions.maxPlayers = maxPlayers; PhotonNetwork.CreateRoom(name, roomOptions, TypedLobby.Default); } public void JoinRandom(object color, object level, byte maxPlayers) { Hashtable expectedCustomRoomProperties = new Hashtable() { { "Color",color }, {"Level", level } }; PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, maxPlayers); } void OnPhotonRandomJoinFailed() { string roomname = "ABC"; string color = "black"; string level = "1"; CreateRoom(roomname, MaxPlayerFromTable, color, level); } }
You can callexample.JoinRandom("black", "1", Example.MaxPlayerFromTable);
5
Answers
-
0
-
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.
0 -
Doing matchmaking logic on client side is not recommended. This is from our Matchmaking Guide:
If you want to roll your own matchmaking, please make sure that most of that is done server side. The clients don't have perfect information about how full rooms are as the room-list update frequency from server to client is low (~1..2 seconds).
Please make use of Lobby Properties, for example, make one or more custom room properties visible to the lobby and use them as filters in random matchmaking:
When you have thousands of players, several will send their "join" requests at the very same time. If a room gets full quickly, your players will frequently fail to join rooms and matchmaking will take longer and longer.
- Key = "Color", Value= "Red" or "Black" or "Blue" etc.
- Key = "Level", Value= ?
There is no need to get rooms list at all.
Join Room:RoomOptions roomOptions = new RoomOptions(); roomOptions.customRoomPropertiesForLobby = { "Color", "Level" }; roomOptions.customRoomProperties = new Hashtable() { { "Color", color }, {"Level", level} }; roomOptions.maxPlayers = expectedMaxPlayers; PhotonNetwork.CreateRoom(roomName, roomOptions, typedLobby);
Create Room if "No Match Found":Hashtable expectedCustomRoomProperties = new Hashtable() { { "Color", targetColor }, {"Level", targetLevel } }; PhotonNetwork.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers);
5 -
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.
0 -
Please try something like this. I'm not sure when and where you're trying to join/create rooms. Also I'm not sure if room creation ever happens. Please also do not use object initializers in Unity (e.g.
RoomOptions
, even so, you don't need to explicitly setisVisible
andisOpen
totrue
as that's their default value).using ExitGames.Client.Photon; using Photon; class Example : MonoBehaviour { public const byte MaxPlayerFromTable = 4; public void CreateRoom(string name, byte maxPlayers, object color, object level) { Hashtable roomProps = new Hashtable() { { "Color", color }, { "Level", level } }; string[] roomPropsInLobby = { "Color", "Level" }; RoomOptions roomOptions = new RoomOptions(); roomOptions.customRoomProperties = roomProps; roomOptions.customRoomPropertiesForLobby = roomPropsInLobby; roomOptions.maxPlayers = maxPlayers; PhotonNetwork.CreateRoom(name, roomOptions, TypedLobby.Default); } public void JoinRandom(object color, object level, byte maxPlayers) { Hashtable expectedCustomRoomProperties = new Hashtable() { { "Color",color }, {"Level", level } }; PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, maxPlayers); } void OnPhotonRandomJoinFailed() { string roomname = "ABC"; string color = "black"; string level = "1"; CreateRoom(roomname, MaxPlayerFromTable, color, level); } }
You can callexample.JoinRandom("black", "1", Example.MaxPlayerFromTable);
5 -
@JohnTube thank you so much. This is the thing that i want to do exactly using photon real time client sdk.0