Search Unity

Third Party Photon player names, friends, room names and custom properties

Discussion in 'Multiplayer' started by SlonCHL, Aug 26, 2014.

  1. SlonCHL

    SlonCHL

    Joined:
    Jul 15, 2014
    Posts:
    8
    First of all I want to state that I'm very new to networking, I don't have much clue on how to connect and create rooms in PUN even with the help of the documentation because it lacks of examples so I need to enquire on a few things.

    1. Player names
    - Must they be unique?
    - If yes then is it possible to and how do I search if that name already exist in-game

    2. Friends
    - How do I define the player names in PhotonNetwork.FindFriends()
    - I understand that the function will return result in PhotonNetwork.Friends but what does it return? PhotonPlayer?

    3. Room names
    - Is it possible to and how do I tell if there's already a room with a certain name

    4. Custom properties
    - Can I have a simple example code on how to set and retrieve values for custom props and custom props for lobby?
     
  2. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    1. Name of player in the room is just a built-in player property. It may be same for different players in room.
    While in room, Iterate PhotonNetwork.playerList and check 'name' property of each element.

    2. FindFriends works with player names registered on master server (lobby) during connection.
    Set PhotonNetwork.playerName property before connecting to the server. PUN sets player name in room to the same value automatically. FindFriends accepts array of strings representing names of players you are looking for.
    PhotonNetwork.Friends is array of FriendInfo's. FriendInfo is simple struct with basic player info.

    3. While client is in lobby, call PhotonNetwork.GetRoomList() for list of currently available rooms in lobby. Iterate that list and check 'name' property of every element.

    4. Initial room properties are set during room creation:
    PhotonNetwork.CreateRoom("MyRoomName", , true, true, 0, new ExitGames.Client.Photon.Hashtable() { { "prop1", "val" }, { "prop2", 10 } }, new string[] { "prop1" });
    Note last parameter, it's a list of properties to be listed in lobby.
    When client in room, update or add room properties:
    PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "prop2", 11 }, { "prop3", true } });
    and retrieve them:
    PhotonNetwork.room.customProperties["prop1"];
     
    Whiteleaf, Meceka and SlonCHL like this.
  3. 2xxx2

    2xxx2

    Joined:
    May 11, 2014
    Posts:
    3
    Can you explane that a little bit more pls? :D I want to check if a room with a name "room" exists, so if it does I can join it and if it doesnt I will create it and then join it. Please help :/
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    For that case, just use JoinRoom(rooname). If it works, the room exists. If it doesn't, you can create it.
    If several friends try to get into the same room by room-name, they can also use PhotonNetwork.JoinOrCreateRoom(). That method avoids race conditions nicely :)
     
  5. 2xxx2

    2xxx2

    Joined:
    May 11, 2014
    Posts:
    3
    Thanks for the help :D