ID:177446
 
I know this shows lag stat("Lag",world.cpu)
world.cpu has nothing to do with lag.

To show the number of people in-game...

var/Players = 0
mob/Login()
..()
Players += 1
mob/Logout()
..()
Players -= 1
In response to Garthor
Garthor wrote:
world.cpu has nothing to do with lag.

To show the number of people in-game...

var/Players = 0
mob/Login()
..()
Players += 1
mob/Logout()
..()
Players -= 1

A better solution is to keep a global list of players; this is more useful overall, because that list can be used for lots of other things, including listing the players who are logged in:
var/list/players=list()

mob
Login()
..()
players+=src
Logout()
players-=src
..()

Stat()
statpanel("Players")
stat("-- [players.len] player\s logged in --")
for(var/mob/M in players-src)
if(!M)
players-=null
continue
M.suffix="Health [round(M.HP*100/M.maxHP)]% -- [M.score] point\s"
stat(M.name)

The players list is useful for other commands, including admin commands, private messages, etc.

Lummox JR
In response to Lummox JR
Yeah, I guess, but he just wanted a number.
In response to Garthor
Garthor wrote:
Yeah, I guess, but he just wanted a number.

True, but any game worth its salt is gonna need admin commands, among other things, and ultimately the players list is going to become necessary (or at least much more useful). Having it opens lots of doors for special options in the game, but having just a number provides only a number.

Lummox JR
In response to Garthor
acually, i think this code is cool

mob/Stat()
statpanel("Players Online")
for(var/mob/M in world)
if(M.client)
stat(M)
..()