Index · Preferences · Help
Announcements · BYOND Features · Bug Reports · Fixes and Features · Developer How-To · Code Problems · Design Philosophy · Creations · Classified Ads · Gaming · Computers & Technology · Community
Forum Search:

[Advanced Search]

[Messages in this Thread] [Show All (5)] [Return to Code Problems]

Author:Garthor [Posts]
Date:11/5/09 5:28 pm
Topic:Re: Who Verb
Post ID:725914
Parent ID:725910
Next ID:725913
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.

Messages in this Thread: [Show All (5)]

  Who Verb The Great Sabin (11/5/09 5:15 pm)
      Re: Who Verb Garthor (11/5/09 5:28 pm)
      Re: Who Verb Vic Rattlehead (11/5/09 5:24 pm)
          Re: Who Verb The Great Sabin (11/5/09 5:47 pm)
              Re: Who Verb Vic Rattlehead (11/5/09 5:53 pm)