The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to count number of specific players in a lobby?

ssg_games
2017-07-18 12:00:46

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
2017-07-18 12:11:26

Hi @ssg_games,

Thank you for choosing Photon!

Take a look at the documentation page here.

ssg_games
2017-07-18 12:58:55

@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
2017-07-19 12:04:07

@ssg_games wrote:

@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
2017-10-23 09:59:42

I am wondering did you fix that?

JohnTube
2017-10-23 12:23:13

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.

Back to top