how would you go about counting all the people on a server, i know on the login() make a variable that adds everytime a person logs in and decreases everytime they log out would work but hasnt been for me, anyone have a code for this?
plus id like to ask someone to answer my other posted newbie central question if its not to much
ID:177129
Oct 27 2002, 2:47 pm
|
|
In response to Koshigia
|
|
Koshigia wrote:
this way, people are counted for at all times... Don't forget that the list has to be initialized:
var/list/people=list()
Lummox JR |
In response to Koshigia
|
|
Why not just keep a global variable as a counter. Initialize it to 0, increment it when someone logs in, and decrement it when someone logs out. This would require less memory.
|
In response to CableMonkey
|
|
And thats actually what he requested.
|
In response to CableMonkey
|
|
A list can be useful for this and other things,
var/list/players = list() mob/Login() players.Add(src) ..() mob/Logout() players.Remove(src) ..() Now what you could do with this, mob/Stat() ..() statpanel("Players") stat(players)//shows everyone in the players list(or in game) stat("Player Count",players.len)//players.len is the length of the list in this case how many people are in the game |
In response to Super16
|
|
showoff. :-P
|
var/list/people
mob/Login()
..()
people+=src
or... if your checking all at once, you could do it this way.
mob/verb/showmepeople()
for(var/mob/X in world)
if(X.client)
src << "I'm a person! - [X]"
There are a few ways, it all depends on how you wish to use the return values.
-Koshigia