ID:264550
 
Code:
    Who()
usr<<"<b>Players Online:"
var/counter=0
for(var/mob/M in world)
if(M.key)
counter+=1
usr<<"\icon[usr.icon] [M.name] Level: [src.Level]"
usr<<"<b>[counter] Players Online"


Problem description:

Its not really i problem, more of a question.

So, in usr<<"\icon[usr.icon] [M.name] Level: [src.Level]" It shows the Icon, Name, and level. But before the Icon of the character, i want it to show the rank of him/here level based.

So if someone is Level 100
And someone else is 200

I want the level 200 before the level 100, and his rank being 1, and the other ones rank being 2.

Can someone help?

Thanks in advanced.
var/list/players=list()

client
New()
players+=src //adds the client to the players list
..()
Del()
players-=src //removes them from it
..()

mob/verb/who()
for(var/client/c in players)
usr<<"Rank: [c.mob.rank] / \icon[c.mob.icon] [c.name] / Level: [c.mob.level]"
src<<"[players.len] players online." //player.len is the length
//if two players are online it will output 2.

In your level proc, set the rank to be whatever when a certain level is reached.
You'll need to sort it. First of all, don't loop through mobs in the world, loop through clients. Second, you manage to mix up usr, M, and src all at once in that thing. M is what you want, not usr or src.

So, for a simple example:

var/list/players = list()
for(var/client/C)
var/mob/Mnew = C.mob
var/v
for(v = 1 to players.len)
var/mob/M = players[v]
if(M.level <= Mnew.level)
players.Insert(v, M)
break
//v will be null if the loop exited normally, which means Mnew is lower-level than everybody in the list
if(!v)
players += Mnew
//now loop through players and display each mob in it


Note that this is not the most efficient algorithm but for the expected size of the list and the frequency of this being called it's a non-issue.
In response to Vic Rattlehead (#1)
Vic Rattlehead wrote:
In your level proc, set the rank to be whatever when a certain level is reached.

I have a rank system i have made already.

I meant by "Rank" is that when you click on Who it looks:

Players Online:
1*icon* Person1 Level: 200
2*icon* Person2 Level: 100
3*icon* Person3 Level: 50
4*icon* Person3 Level: 25
4 Players Online

Catching my drift? I want it to be like a scoreboard, but show it up on the Who tab, the if your the highest level on, your Rank will be "1" in "Who".
In response to The Great Sabin (#3)
Then simply sort the list to highest rank to lowest rank?