|
| 23 Jun 2012 10:22 AM |
Im working on a custom leaderboard, but how would I get all the players, and sort them into the teams in a Gui?
p = game.Players:GetChildren() for i = 1,#p do if p[i].TeamColor == "Bright yellow" then --The main thing im trying to ask is how would I add the players name without skipping a space or overlapping any other TextLabels? |
|
|
| Report Abuse |
|
|
1pie23
|
  |
| Joined: 11 Jul 2010 |
| Total Posts: 1865 |
|
|
| 23 Jun 2012 10:29 AM |
Maxplayers = 10
team1 = 5 team2 = 5
make 10 textlabels. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 10:31 AM |
Trust me. Custom leaderboards are a real pain to update stats.
-[ RS ]- |
|
|
| Report Abuse |
|
|
| |
|
1pie23
|
  |
| Joined: 11 Jul 2010 |
| Total Posts: 1865 |
|
|
| 23 Jun 2012 10:35 AM |
| Right, didn't read post correctly. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 10:45 AM |
| I don't really care how much of a pain it is I just wanna do it. :L |
|
|
| Report Abuse |
|
|
awas3
|
  |
| Joined: 24 Oct 2010 |
| Total Posts: 2854 |
|
|
| 23 Jun 2012 10:50 AM |
| I asked the same question a long time ago. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 10:51 AM |
| I will look on this after dinner. Its not really hard actually. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 10:55 AM |
p = game.Players:GetChildren(); list = {}; for i,v in pairs(p) do list[v.TeamColor.Name] = list[v.TeamColor.Name] or {}; list[v.TeamColor.Name][#list[v.TeamColor.Name]+1] = v; end
--The above will sort them into teams. --The following will set all players into a single table.
new_list = {}; for i,v in pairs(list) do for x,y in pairs(v) do new_list[#new_list+1] = y; end end |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 11:29 AM |
| Could you perhaps, explain what each line does? Ive never done much with tables. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 12:05 PM |
Oh god sure.
p = game.Players:GetChildren(); -- At this point, p will look like {game.Players.blobbyblob, -- game.Players.SilverNinja14}, etc. It just lists all the players.
list = {}; -- Now 'list' is an empty table.
for i,v in pairs(p) do -- Creates an iterating loop. This will go through where (i = 1), -- and (v = game.Players.blobbyblob). Second time through it -- will be (i = 2) and (v = game.Players.SilverNinja14).
list[v.TeamColor.Name] = list[v.TeamColor.Name] or {}; -- This will initialize a new empty table *inside* the first table. -- That nested table will have the same name as v.TeamColor.Name. -- The 'or' operator as I used it in that situation might need an -- explanation all of its own, so here goes: -- -- x = y or z; Will set x to the value of y if y is not nil. If y is nil, -- then it will set x to the value of z. -- -- The idea in the situation where I used it is that list.< teamcolor> -- will stay the same if it has been initialized already. Otherwise, it -- gets set to {} (empty set).
list[v.TeamColor.Name][#list[v.TeamColor.Name]+1] = v; -- Sets the next open slot in the table to the value of v. -- It's the same as doing table.insert(list[v.TeamColor.Name], v) -- except it's faster because it doesn't need to handle all the cases -- table.insert does. I know what the indices will be.
end -- duh.
And when you're done, you'll have something that looks like this:
list = { Bright red = {game.Players.blobbyblob, game.Players.Player}, Bright blue = {game.Players.SilverNinja14} } |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 12:08 PM |
I'll be totes honest. I didn't explain the second part because I got bored. But the first part is the most advanced one. The second one just takes this:
list = { Bright red = {game.Players.blobbyblob, game.Players.Player}, Bright blue = {game.Players.SilverNinja14} }
and turns it into this:
list = {game.Players.blobbyblob, game.Players.Player, game.Players.SilverNinja14}
And it stays in the correct order team-wise. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2012 12:09 PM |
| Very confusing. But helpful. Thanks, ill see what I can do with it. |
|
|
| Report Abuse |
|
|