ID:157269
 
How can i assign every player when they log in a number?

Example

P1 - First who logged in
P2 - Second who logged in

etc..

Then when someone logs out, all the below players move up a spot.
this may not be the best way to do it so dont use it unless u HAVE to lol

var/ppl = 1
mob/var/num = 0

mob
Login()
..()
src.num = ppl
ppl++
Logout()
ppl--
Num_Add()
del(src)

proc
Num_Add()
for(var/mob/M in world)
if(!M.client) continue
M.num++
In response to Masschaos100 (#1)
Subtracting from ppl when people leave is not going to work, because it will result in two #2 if you have two people join, and the first leaves and reconnects. The Num_Add() you wrote is supposedly meant to correct this, but it really doesn't, and should just be removed entirely.

To reuse numbers, you'd need to keep a list of every number that's been freed up, and assign from that, or increment ppl and use that if the list if empty.
In response to Garthor (#2)
oh :O
In response to Garthor (#2)
Garthor wrote:
Subtracting from ppl when people leave is not going to work, because it will result in two #2 if you have two people join, and the first leaves and reconnects. The Num_Add() you wrote is supposedly meant to correct this, but it really doesn't, and should just be removed entirely.

To reuse numbers, you'd need to keep a list of every number that's been freed up, and assign from that, or increment ppl and use that if the list if empty.

would this fix it or would a list be better? i actually feel like using this for something too :)

this may not be the best way to do it so dont use it unless u HAVE to lol

var/ppl = 1
mob/var/num = 0

mob
Login()
..()
src.num = ppl
ppl++
Logout()
ppl--
Num_Add(src)
del(src)

proc
Num_Add(mob/A)
for(var/mob/M in world)
if(!M.client) continue
if(M.num < A.num)
M.num++

In response to Masschaos100 (#4)
That'd be on the right track to a solution, but it's doing it backwards (resulting in there always being a #1 free). And, of course, you have the issue that you're rearranging everybody's numbers, and that looping through every mob in the world is wasteful.