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
if(!v)
players += Mnew
|
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. |
|