Can I use the int of CurrentRoom.Players<int,Player> for my purpose?

Options
Hi! I have chat rooms with a fixed circle of 8 seat objects each, and I want to ensure that every player is assigned sitting on a seat (so that also, everyone sees everyone else on the correct seat position, e.g. Peter is at seat 3, Susan is at say 7, the person who created the room will be at seat 1 etc.).

Can I just re-use the KeyValuePair<int,Player> int number served with PhotonNetwork.CurrentRoom.Players (after OnJoinedRoom()) for that, relying on those being 1-8, and the same on every client -- and assigned in chronological order from 1 - 8 as players joined -- or do I need to come up with a different system (if so, what's appropriate)?

Thanks!

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Philipp,

    The keys of the PhotonNetwork.CurrentRoom.Players dictionary are the actor numbers of the players joined to the room.

    You should know that the actor numbers:

    - start from 1: the room creator (and initial MasterClient) gets actor number 1. But the room creator can leave the room. Master client can be automatically or explicitly switched.
    - are "chronological": if X > Y ==> a player with actor number X has initially entered the room (joined for the first time) after the player with actor number Y.
    - can "overflow", i.e. go higher than PlayerCount or MaxPlayers.
    - can be preserved for inactive actors: a player can leave the room temporarily for up to PlayerTTL or indefinitely and rejoin the room (come back with the same UserId). The same actor number will be kept for the user. However, if the user leaves the room for good (actor removed from the actors' list) then joins the room again even with the same UserId, a new actor number will be attributed.
    - cannot be reused/recycled: an actor number that was "claimed"/"assigned" cannot be reclaimed or reassigned to another player.
    - can have gaps: if a player leaves the room for good (actor removed from the actors' list) then his actor number will never be reused.

    So if one of these properties do not meet your requirements you could rely on a custom player index.
    PUN has UtilityScript for PlayerIndexing. You should try those first or make your own.
  • Philipp
    Philipp
    edited July 2019
    Options
    Thank you very much for the fast & detailed reply! Some of these properties do not fit my requirements (e.g. overflowing above my 8 MaxPlayers), so it looks like I need to go for a custom player index.

    The utility script you mention, would that be PlayerNumbering? (I'm using Pun v2, and can't seem to find any code mention of PlayerIndexing.)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    The utility script you mention, would that be PlayerNumbering?

    Yes.
  • Philipp
    Options
    Great, looks like just what I need then! Thanks again!