How to count number of specific players in a lobby?

Options
The users have the choice to become either a monster or a human being. It's a one-on-one combat game. So, 1 room can only have 1 monster and 1 human being. When a user opens the game, I want him to see the number of available monsters. So, if a total of 10 users are online, out of which 4 are human beings and 6 are monsters. 3 human beings and 3 monsters are in 3 rooms (1 human + 1 monster in 1 room). So, 4 users are left (1 human and 3 monsters). I can calculate the number of users available (X = total users - number of rooms * 2 ) But I need to know the number of available monsters, not users.

However, I can't think of how I can get the 'number of monsters available' - monsters that are in the lobby waiting (excluding the ones who are already in rooms). This number also needs to exclude human beings (both in the lobby and in rooms). I only need to know the number of available monsters.

Under the hood, monsters and human beings are just regarded as 'users'. Therefore, I'm having trouble singling out the number of monsters.

How do I count the number of available monsters?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @ssg_games,

    Thank you for choosing Photon!

    Take a look at the documentation page here.
  • ssg_games
    Options
    @JohnTube Hi, thanks for referring to that page. PhotonNetwork.countOfPlayersOnMaster looks like the function I need to use to get the nunmber of players who are online but not joined a room yet. However, how do I categorize 'users' into let's say 2 'types' of users like 'enemy' and 'heroes'? I couldn't find a way to create a global variable which is accessible across all rooms and lobbies in Photon. I need to separate the general 'users' into these two types because I need to get the count of users who are online but not joined a room yet who are enemies.

    PhotonNetwork.countOfPlayersOnMaster will give the number of users (enemy+heroes) who are online but not joined a room yet.
  • Damu
    Options
    ssg_games said:

    @JohnTube Hi, thanks for referring to that page. PhotonNetwork.countOfPlayersOnMaster looks like the function I need to use to get the nunmber of players who are online but not joined a room yet. However, how do I categorize 'users' into let's say 2 'types' of users like 'enemy' and 'heroes'? I couldn't find a way to create a global variable which is accessible across all rooms and lobbies in Photon. I need to separate the general 'users' into these two types because I need to get the count of users who are online but not joined a room yet who are enemies.

    PhotonNetwork.countOfPlayersOnMaster will give the number of users (enemy+heroes) who are online but not joined a room yet.

    Have any one found the way to get the count for Enemy and heros , I got struck at this point for 3 days , please help me in fixing this
  • TetraGames
    Options
    I am wondering did you fix that?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @ssg_games, @Damu, @TetraGames,

    If you want to have a "global" counter or variable accessible outside of rooms by everyone you need to use another service. Photon do not provide that out of the box.

    What you could do using Photon, which is not something we recommend:
    • Have a "sub counter" per room as a lobby property (e.g. "count of heroes" inside room, "count of enemies" inside the room)
    • Join the lobby where the counters should belong to
    • Loop over all rooms list and get the sum of all sub counters (e.g. "count of all heroes" inside all rooms, "count of all enemies" inside all rooms)
    There is no guarantee the total is accurate.
    You have to do this every time to sync the value per client.
    Clients may have different values.