Team Lobby System HELP

Options

I've been at this for a while and tried looking all over the place for some thing that works. I get close in a lot of different directions but I reach a road block when there isn't as much information. I know this is going to be kind of all over the player. Let me know if you need any information!

Basically I have built a lobby system where players join a room and they can see all the players that are currently in the room. Since I wanted to have teams introduced I decided to split the UI into a red and blue team and had buttons to click so you could join said teams. And then after joining teams there is a start button that will carry over into the next scene that already has player managers to setup the player controller prefabs of the correct team. Does anyone have some really good information on how I can implement this?

------ Some issues --------

I have a function that grabs all players in the room with: Player[] players = PhotonNetwork.PlayerList;

- Is there a way I can grab only players on a certain team.


If you send me to this *link below* I'm going to need more information. I will persist until I have something that works!!!!

https://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_pun_1_1_utility_scripts_1_1_photon_teams_manager.html

Answers

  • Fauyeti
    Fauyeti
    edited March 2023
    Options

    Alright I've been working on it some and I've actually got the Photon Teams Manager working 100%. I'm getting some UI bugs just simply because new players joining...even though they are showing up in the correct team in the Photon Teams Manager script...are showing up as having null teams.

    I'm currently trying go through a list of players and find what team they are on to assign them UI labels and show in a lobby. Not really sure whats happening. But at least I have narrowed down the problem! Hopefully someone can help. It seems as though it only happens with the latest player to join the room*

    And I have tried a couple things (all result in null) and I should also mention this is happening in the OnJoinedRoom() function:


    Player[] players = PhotonNetwork.PlayerList;


        foreach(Player p in players)

        {

          Debug.Log(p.GetPhotonTeam());

        }

  • Fauyeti
    Options

    One fix idea I came up with was basically if the player returns null it'll look at the lobby and decide where to place it self... I just have 1 issue. I'm probably having an issue with syntax. I would like to do something like this, but I'm really 100% sure why the GetPhotonTeam() == 1 isn't working. I tried strings as well "Blue":

        for (int i = 0; i < players.Count(); i++)

        {

          if (players[i].GetPhotonTeam() != null)

          {

            Debug.Log("Player: " +players[i] + "is on team: " + players[i].GetPhotonTeam());



            if (players[i].GetPhotonTeam() == 1)

            {

              Debug.Log(players[i] + " is on blue team!");

            }

            if (players[i].GetPhotonTeam() == 2)

            {

              Debug.Log(players[i] + " is on red team!");

            }

          }

          if (players[i].GetPhotonTeam() == null)

          {

            Debug.Log("New player should be asigned a team!");

          }

  • Fauyeti
    Options

    Nvm got it boys, thanks for showing up lol.


    Still not 100% how to grab the team code. But this worked for me:

    players[i].GetPhotonTeam().Name == "Blue"

  • Tobias
    Tobias admin
    edited March 2023
    Options

    What if you use players[i].GetPhotonTeam().Code == <byte value>?