ID:154425
 
How would i make a counter of how many people appear on the who command?

var/counter = 0
for(var/mob/player/M in world)
counter += 1
usr << "[M] is with us"
usr << "[counter] people are playing"

However you wanted to. Two ways spring immediately to my mind.

The first is to have a master list of players online... this is useful for several reasons. Instead of sending global messages to world (most of the world doesn't have a player connected to receive these!), you can just send it to the list. It also gives you a handy list to use as a menu in Admin function inputs. In this case, you could access the list.len to get your number of players.

The other is to have your loop add 1 to a variable each time it goes through a player.
Who()
var/n
for (var/mob/player/p in world)
src << "[p] ([p.key]) [p.address"]
n +=1
src << "[n] player\s online.
In response to LexyBitch
In response to SonVegitto
SonVegitto wrote:
var/counter = 0
for(var/mob/player/M in world)
counter += 1
usr << "[M] is with us"
usr << "[counter] people are playing"

This will count NPCs too. So you might wanna check to see if the key of the mob is null before adding to the count.
In response to Theodis
Theodis wrote:
SonVegitto wrote:
var/counter = 0
for(var/mob/player/M in world)
counter += 1
usr << "[M] is with us"
usr << "[counter] people are playing"

This will count NPCs too. So you might wanna check to see if the key of the mob is null before adding to the count.

Why do you think this will count NPCs? A mob of type /mob/<font color=yellow>player</font> is not likely to be a PC, unless someone has some funky coding going on.
In response to Skysaw
Why do you think this will count NPCs? A mob of type /mob/<font color=yellow>player</font> is not likely to be a PC, unless someone has some funky coding going on.

You forget a crucial aspect about the type of game being created. =P

(Agh, it burns! The yellow! It burns, it burns!)