• for k, v in pairs(player.GetAll()) - Admins only.
    9 replies, posted
Hello, So I'm trying to create an admin Scoreboard, but when I try: [CODE]for k, v in pairs(player.GetAll()) do if v:IsUserGroup( "superadmin" ) then -- scoreboard panel end end[/CODE] This does work, however it leaves gaps for people who aren't that rank as well, meaning there are gaps inbetween peoples names who are superadmins. What would be the best way to do this, getting rid of the gaps?
My own, trying to make my own, but I want admins to only show on it and not players. By using the above code.
Sure, this is the code for each panel. [CODE]for k, v in pairs(player.GetAll()) do if v:IsUserGroup( "superadmin" ) then ppp = vgui.Create( "DButton", bbgs ) ppp:SetSize( bbgs:GetWide() - 5, 50 ) ppp:SetPos( 5, 55 * (k-1) ) -- I think it'd to do with this bit, but not sure if it is. ppp:SetText( "" ) ppp.Paint = function(self) draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 24, 109, 179 ) ) draw.DrawText( v:Name(), "ButtonsFont", 5, self:GetTall() / 2 - 18, Color( 255, 255, 255 ), TEXT_ALIGN_LEFT ) end end end[/CODE]
Create a table with all the ranks of staff ordered like so [CODE]local staff = { admin = true, superadmin = true etc = true }[/CODE] then do the for loop and [code]if staff[v:GetUserGroup()] then --code end [/code]
[QUOTE=Moat;52816555]Try this: [lua] local y_pos = 0 -- store y position outside of loop for k, v in pairs(player.GetAll()) do if v:IsUserGroup( "superadmin" ) then ppp = vgui.Create( "DButton", bbgs ) ppp:SetSize( bbgs:GetWide() - 5, 50 ) ppp:SetPos( 5, 55 * y_pos ) -- use y value to get proper y position ppp:SetText( "" ) ppp.Paint = function(self) draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 24, 109, 179 ) ) draw.DrawText( v:Name(), "ButtonsFont", 5, self:GetTall() / 2 - 18, Color( 255, 255, 255 ), TEXT_ALIGN_LEFT ) end y_pos = y_pos + 1 -- increase y value everytime we actually draw something end end[/lua] Alternatively, you could use docking rather than setting the position. Which you would just call [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/Dock]Panel:Dock[/url] TOP on the button. (instead of SetPos) [editline]24th October 2017[/editline] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/IsUserGroup]Player:IsUserGroup[/url] is a function.[/QUOTE] Awesome, that worked! Thank you so much, helped a lot, been trying different ways for a while, will give the table ago as well to learn more. Thanks guys!
Sorry, you need to Log In to post a reply to this thread.