Sort playerList with ActorID

Options

Hi guys thanks for your best network soultion

. I have question about to sort playerlist with actornubmer or name can you help ? Thanks

Answers

  • Tobias
    Options

    Thanks for the nice remarks.

    The PhotonNetwork.PlayerList is sorted by actorNumber. You can have a look at it, how that's done and come up with a property for the sorting by name, I'd say.

  • Arian
    Arian
    edited December 2021
    Options

    Is PhotonNetwork.playerlist sortrd by actornumber ? So why when i try to get playlist on each clients its like random.

    Im trying to spawn my (5 FIX) player to 5 spawn point this my code :

    Private void Awake()
    {
        SpawnPlayer()
    }
    
    Public void spawnplayer()
    {
        If(photon.isMine)
        {
            GameObject player = photonNetwork.Instantiate(playerPrefabs.name,Spawnpoint[index].position,dir,0);
        }
    }
    

    I tried to Set index of spawnpoint to actornumber but i have 5 spawn point

    If someone disconnect game or leave the game, actornumber reused and the next player join game will be actornumber = 6

    Then how i spawn them ?

    So

    Before the player joined Game they join Scene where they can see each other . On this room i have list to show them :

    Private void ListingPlayer()
    {
        If(photonNetwork.Inroom)
        {
            foreach(photon.Realtime.Player player in photonNetwok.playerlist)
            {
                Gameobject templisting = Instantiate(NamePlayerPrfabs , gridPlayer);
                templisting.Getcomponent<textmeshproGUI>().text = player.Nickname;
                If(photonNetwok.localPlayer.Nickname ==templisting.Getcomponent<textmeshproGUI>().text)
                {
                    Playercard = templisting;
                }
            }
        }
    }
    

    So for index of player i got playerCard

    Print(playerCard.transform.GetsiblingIndex());

    And save them to custom propreties but the output not working well cause playerlist is different for each client and index will be diffirenet

    So if i can sort the playerlist and send them to all my client (RPC) then it will works fine

    Sorry im new at this and my english is not good too. Thank you for all support .

  • Arian
    Arian
    edited December 2021
    Options

    I found solution

    Just add

    Private void ListingPlayer()
    {
        If(photonNetwork.Inroom)
        {
            foreach(photon.Realtime.Player player in photonNetwok.playerlist)
            {
                Gameobject templisting = Instantiate(NamePlayerPrfabs , gridPlayer);
                templisting.Getcomponent<textmeshproGUI>().text = player.Nickname;
                If((photonNetwok.localPlayer.Nickname + photonNetwork.localPlayer.ActourNumber).toString() ==(templisting.Getcomponent<textmeshproGUI>().text + player.ActorNumbrr).Tostring())
                {
                    Playercard = templisting;
                }
            }
        }
    }