I was wondering if it's possible to sort the players in a scoreboard without using a "DListView"
Basically I want them to be sorted automatically.
Basically it depends on how you draw the board.
This is how my row is looking
[lua]
for k,pl in pairs(player.GetAll()) do
local plist = vgui.Create("DButton",players)
plist:SetPos(0,k*45-45)
plist:SetSize(plybg:GetWide(),40)
plist:SetText("")
plist.Paint = function()
draw.DrawText(pl:GetName(),"Check",45,2,Color(255,255,255),TEXT_ALIGN_LEFT)
draw.DrawText("User","Check",45,20,Color(255,255,255),TEXT_ALIGN_LEFT)
draw.DrawText(pl:Nick(),"Check",plybg:GetWide()/2-125,2,Color(255,255,255),TEXT_ALIGN_LEFT)
draw.DrawText(job,"Check",plybg:GetWide()/2+85,2,Color(255,255,255),TEXT_ALIGN_LEFT)
end
end
[/lua]
You'd probably want to store player.GetAll() first, then sort that array, then draw the rows.
[lua]
local plys = player.GetAll()
table.sort(plys, function(a, b) return a:Name() > b:Name() end)
for k, pl in pairs(plys) do
...
end
[/lua]
[QUOTE=Wizard of Ass;41264342][lua]
local plys = player.GetAll()
table.sort(plys, function(a, b) return a:Name() > b:Name() end)
for k, pl in pairs(plys) do
...
end
[/lua][/QUOTE]
That helped me a lot. Thank You.
Sorry, you need to Log In to post a reply to this thread.