--Scoreboard
--plz do not steal this
-- thnx
-- Scripted by Waffler

if( Scoreboard ) then

	Scoreboard:Remove()
	Scoreboard = nil
	
end

function CreateScoreboard()

	Scoreboard = CreateBPanel( nil, ScrW() * .25, ScrH() * .25, 800, 600 )
	Scoreboard:CanClose( false );
	Scoreboard:CanDrag( false );
	Scoreboard:CanSeeTitle( false );
	Scoreboard:SetBodyColor( Color( 30, 30, 30, 255 ) )
	Scoreboard:SetOutline( true, 3 )
	Scoreboard:EnableScrolling( true )
	
	Scoreboard.PlayerIcon = { }
	
	local y = 0
	local x = 0
	
	for k, v in pairs( player.GetAll() ) do
	
		Scoreboard.PlayerIcon[v] = vgui.Create( "DModelPanel", Scoreboard )
		Scoreboard.PlayerIcon[v]:SetSize( 150, 150 )
		Scoreboard.PlayerIcon[v]:SetModel( v:GetModel() )
		Scoreboard.PlayerIcon[v]:SetPos( x + 10, y + 10 )
		Scoreboard.PlayerIcon[v]:SetAmbientLight( Color( 50, 50, 50 ) )
		Scoreboard.PlayerIcon[v]:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) )
		Scoreboard.PlayerIcon[v]:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) )
		Scoreboard.PlayerIcon[v]:SetCamPos( Vector( 50, 0, 50 ) )
		Scoreboard.PlayerIcon[v]:SetLookAt( Vector( 0, 0, 50 ) )
		Scoreboard.PlayerIcon[v]:SetFOV( 70 )
		Scoreboard.PlayerIcon[v]:SetAnimSpeed( 0.0 )
		Scoreboard.PlayerIcon[v]:SetAnimated( false )
		
		Scoreboard.PlayerIcon[v].LayoutEntity = function( self ) 
		end
		
		Scoreboard.PlayerIcon[v]:SetToolTip( v:GetRPName() .. "\n" .. v:GetNWString( "title" ) .. "\n" .. v:GetNWString( "secondtitle" ) .. "\n" .. v:Nick() .. "\n" .. "Ping: " .. v:Ping() .. "\n" )
		
		x = x + 152
		
		if( x > 732 ) then
			y = y + 152
			x = 0 
		end
		
		Scoreboard:AddObject( Scoreboard.PlayerIcon[v] )

	end

end

function removescoreboard()

	if( Scoreboard ) then
		Scoreboard:Remove()
		Scoreboard = nil
	end
	
	gui.EnableScreenClicker( false );
	
end

function GM:ScoreboardShow()

	if( not Scoreboard ) then
		CreateScoreboard();
	end
	
	gui.EnableScreenClicker( true );
	

end

function GM:ScoreboardHide()

	removescoreboard()

end		
	
	