Photon multiplayer room make disappear in lobby when room is getting full
Options
Hi all, I am making realtime multiplayer game. want to Provide on options like 1) Room#1 - with two maximum player capacity 2)Room#2 - with four maximum player capacity
If in these case if Room#1 player count (getting full) then this room name should not be visible in lobby. same as for 4 player Room#2, it should getting visible false. these room should not visible to other connected player in lobby. How can it is possible ? which photon function should i have call ? and when call ?
Thanks in advance
0
Best Answers
-
I'm not sure i fully understand what you're asking but i believe simply having a check in the code that displays the rooms to see if the room is full capacity and if it is, then don't display it. eg..
foreach (RoomInfo game in PhotonNetwork.GetRoomList())
{
if(game.playerCount != game.maxPlayers)
{
}
}5 -
ok thanks let me try...5
Answers
-
I'm not sure i fully understand what you're asking but i believe simply having a check in the code that displays the rooms to see if the room is full capacity and if it is, then don't display it. eg..
foreach (RoomInfo game in PhotonNetwork.GetRoomList())
{
if(game.playerCount != game.maxPlayers)
{
}
}5 -
:C0
-
Hi thanks for the answer. How to generate another room when one room is getting full ?
The case are ;
1#when there is no room I am creating room using one button
2#when second player joins room, its getting full
3#Room is getting disappear using isvisible = false, and isopen = false.
So at that time Want to generate a button with same 2 player maximum and that room should be available for other player who has joined lobby and he can join room using that button ?
Is it possible in photon networking ? Is there any other option of it ?
0 -
You could have a UI that deals with match making. And take in room information as parameters, if that's what you're asking? Regardless if you have a foreach loop in your update or OnGUI, that should automatically update changes... For example I have a main loop which renders room state... It shows if its open and amount of players in it (2/3 eg). Once that room is full, depending on how you wrote your code it should just disappear off the screen (at least mine does the way i programmed it).
Hope this helps, wasn't exactly sure of what you were asking but..0 -
The way I did it was I had 2 options for user: Create match or find match. Find match simply displays all the open (unfull rooms) that currently exist while create match simply creates a new match. In your case, you could set more options for creating a match. Options like least and max amount of players can be parametrized and used before the room is actually created.0
-
Here what I have done is generating another room when its getting full on single button .
Don't know this fully perfect or not but its working for me.
if(rooms.Length == 0)
{
RoomOptions roomOptions = new RoomOptions ()
{
isVisible = true,
maxPlayers = (byte)MaxPlayerFromTable
};
roomabc += ""+1.ToString();
PhotonNetwork.CreateRoom(roomabc,roomOptions,TypedLobby.Default);
}
if (rooms.Length >= 1)
{
foreach (RoomInfo room in rooms)
{
string name = "";
for(int i = 0; i < rooms.Length ; i++)
{
name = rooms[i].name;
}
if(room.name == name) // Room name is same then join if room is not full
{
int r1 = Random.Range (0, rooms.Length);
PhotonNetwork.JoinRoom (rooms [r1].name);
RoomjoinCount = 0;
Debug.Log("Join same Room");
}
else //Room name is different then create new one
{
RoomOptions roomOptions = new RoomOptions ()
{
isVisible = true,
maxPlayers = (byte)MaxPlayerFromTable
};
PhotonNetwork.CreateRoom(roomName.text,roomOptions,TypedLobby.Default);
RoomjoinCount = 0;
Debug.Log("room Available but not same name so create new one");
}
}
}
Is there something wrong in this code that can mislead me in future ?0 -
Your code seems to have a lot of unnecessary functionality. Try something like this:
if (PhotonNetwork.insideLobby == true)
{
//Display the lobby connection list and room creation.
GUI.Box (new Rect (Screen.width / 2 - 200, Screen.height / 2 - 50, 400, 300), "");
GUILayout.BeginArea (new Rect (Screen.width / 2 - 200, Screen.height / 2 - 50, 400, 400));
GUILayout.Box ("Existing matches");
GUI.color = Color.white;
GUILayout.Space (20);
if(PhotonNetwork.countOfRooms < 1)
{
Debug.Log ("No available rooms, make one!");
}
else
{
// for each currently existing room
foreach (RoomInfo game in PhotonNetwork.GetRoomList())
{
// only display matches that aren't full yet
if(game.playerCount != game.maxPlayers)
{
GUI.color = Color.green;
GUILayout.Box(game.name + " " + game.playerCount + "/" + game.maxPlayers); //Thus we are in a for loop of games rooms display the game.name provide assigned above, playercount, and max players provided. EX 2/20
GUI.color = Color.white;
if (GUILayout.Button ("Join Room"))
{
// join the applicable match
matchMaker.JoinExistingRoom (game.name); // Next to each room there is a button to join the listed game.name in the current loop.
}
}
}
}
GUILayout.EndArea ();
}
This is very basic code which allows you to join rooms if they aren't full and displays a bit of info about it - however it uses unity's old gui system, still enough to point you in the right direction though! Hope this helps0 -
ok thanks let me try...5