Max Player Problem

Hi team,
I want to make min 2 max 5 players arena game.
I need a list of players same for each client.
I tried to set each player another id (playerSlotID) range (0-4).

playerSlotID assigning conditions are;
When player connects, player gets minimum playerSlotID available and keeps while connected.
When player disconnects, that player's playerSlotID became reusable for another new player.

Example;
Slot 0 - PlayerID:1
Slot 1 - PlayerID:2
Slot 2 - PlayerID:3

PlayerID:2 disconnected;
Slot 0 - PlayerID:1
Slot 1 - empty
Slot 2 - PlayerID:3

new PlayerID:4 connected and new PlayerID:5 connected;
Slot 0 - PlayerID:1
Slot 1 - PlayerID:4
Slot 2 - PlayerID:3
Slot 3 - PlayerID:5

I need this order for each client, can you help about this algorithm?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited August 2016
    Hi @musakara,

    I'm not sure this discussion should belong into "Native" category...

    For the minimum number of players per game you should handle it yourself by entering the game only when 2 players at least are joined.

    First of all, I invite you to study ActorNr player property available out-of-box by Photon. The only thing that is different from your approach, is that ActorNr always increase and never decrease, meaning when a player leaves the room for good his ActorNr will not be reused.

    For the slots, you should manually assign a PlayerID number to each new player. You can do it from joining client itself or from MasterClient only. Preferably this should be done using RoomProperties: each slot is a property and you should set it using Check-And-Swap feature to avoid situation where 2 players joined at the same time claim same PlayerID. So when a new player is joined look for first empty slot and try assigning it to a the PlayerID value. When a player leaves, look for his slot and make it empty. Each new PlayerID value can be obtained either from total number of joined actors or use a separate players counter as RoomProperties also, increment and decrement manually. You can choose to initialize it to 0 or 1.
  • Hi,

    To add to JohnTub comments.

    I would use room properties and have four property, Player1, Player2, Player3, Player4

    when someone joins, it checks the first available slot ( if PlayerX == -1 then it can fill that slot).

    and so you have like a simple mechanism for each player to know which slot to occupy, and all other players will get notified via room property update. You can also duplicate this information inside the PlayerProperties, where each player would have a "slot" and would be equal to 1, 2, 3, 4.

    Bye,

    Jean