How would I draw a scoreboard?

Hey FP community. I’ve had this question for a while, but exactly how and what functions would I use to draw a scoreboard? I’ve never really worked with scoreboards so I’d like some pointers / example code.

You create your own VGUI elements somewhat like the following:

local PANEL = {}
function PANEL:Init() ... end
function PANEL:Paint( w, h ) ... end
function PANEL:PerformLayout() ... end
-- etc
vgui.Register( "CustomScoreboardElement", PANEL, "Panel" )

You can derive your elements from the standard elements or elements that you create, providing a form of inheritance.

You override or hook into GM:ScoreboardShow to then create your scoreboard (if it hasn’t been created yet) and show it, and GM:ScoreboardHide to hide it.

function GAMEMODE:ScoreboardShow()
    if ( not IsValid( g_YourCustomScoreboard ) ) then
       g_YourCustomScoreboard = vgui.Create( "CustomScoreboard" )

    return true -- can't remember if this is necessary when defining the GAMEMODE function itself

function GAMEMODE:ScoreboardHide()
    if ( not IsValid( g_YourCustomScoreboard ) ) then return end

    return true -- can't remember if this is necessary when defining the GAMEMODE function itself

I don’t know what the current mainstream scoreboard is, if any, but you can look into the SUI scoreboards and see how they do things to get an idea.

Basically you build each piece as a vgui element and eventually tie it all together into a single component that controls all the little pieces. E.g., a DPanel that just provides a background and the size of the scoreboard, but holds many “PlayerRow” elements that each hold a single player.

Thanks for the pointers. I will try these out!

This is along the lines of how i make the scoreboard

local SCOREBOARD = {}

function SCOREBOARD:Init()

	self.Frame = vgui.Create("DFrame")
	self.Frame:SetSize( ScrW() * .5, ScrH() / 3 )
	self.Scroll = vgui.Create("DScrollPanel", self.Frame )
	self.Scroll:SetSize( self.Frame:GetWide() - 10, self.Frame:GetTall() - 10 )
	self.Scroll:SetPos( 5,5 )
	self.Layout = vgui.Create("DIconLayout", self.Scroll )
	self.Layout:SetSize( self.Scroll:GetWide(), self.Scroll:GetTall() )
	self.Layout:SetPos( 0,0 )
	self.Layout:SetSpaceX( 5 )
	self.Layout:SetSpaceY( 5 )


function SCOREBOARD:LoadPlayers()

	for k,v in pairs( player.GetAll() ) do
		local PlayerBar = self.Layout:Add("DPanel")
		PlayerBar:SetSize( self.Layout:GetWide(), 32 )
		PlayerBar.Paint = function( self, w, h )


function SCOREBOARD:Hide()
	self.Frame:SetVisible( false )

function SCOREBOARD:Show()
	self.Frame:SetVisible( true )

vgui.Register("base_scoreboard", SCOREBOARD , "Panel");

// To use the scoreboard.

local Scoreboard = vgui.Create("base_scoreboard")

You can add the players inside of the init function if you want, i just like to be awkward.

Thanks again. I will definantly try these out.

Why not use a DListView?

for _,ply in pairs( player.GetAll() ) do
– code here

local _main = vgui.Create( “DFrame” )

_main.Paint() = function()
draw.RoundedBox( 0, _main:GetWidth(), _main:GetHeight(), 0, 0, Color( 255, 255, 255, 255 ) )

[editline]21st September 2015[/editline]

Oh sorry, thought you ment how to make a scoreboard xD