local specbox = {
	[ 'data' ] = {};
};

concommand.Add( 'specbox_on', function( x, y, z, text )
	for k , v in ipairs( player.GetAll() ) do
		if( v:Nick() == text || v:Name() == text ) then
			print( '[specbox] Targetting: ' .. v:Nick() );

			specbox.target = v;

			return;
		end
	end

	print( '[specbox] Unable to locate player: ' .. text );
end );

concommand.Add( 'specbox_off', function()
	specbox.target = nil;
end );

function specbox.camera()
	if( IsValid( specbox.target ) && specbox.target ~= nil && LocalPlayer():IsUserGroup( 'user' ) ) then
		local angles = specbox.target:EyeAngles();

		local origin = specbox.target:EyePos();

		origin = origin - ( angles:Forward() * 100 );

		specbox.data.angles = angles;
		specbox.data.origin = origin;

		specbox.data.x = specbox.settings[ 'x' ]:GetFloat();
		specbox.data.y = specbox.settings[ 'y' ]:GetFloat();
		specbox.data.w = ScrW() / specbox.settings[ 'scale_w' ]:GetFloat();
		specbox.data.h = ScrH() / specbox.settings[ 'scale_h' ]:GetFloat();
		surface.DrawRect( 500, 500, 500, 500 )
		render.RenderView( specbox.data );
	end
end

function specbox.init()
	specbox.settings = {};

	specbox.settings[ 'x' ]			  = CreateClientConVar( 'specbox_x', 0, true, false );
	specbox.settings[ 'y' ]			  = CreateClientConVar( 'specbox_y', 0, true, false );
	specbox.settings[ 'scale_w' ]	  = CreateClientConVar( 'specbox_scalew', 6, true, false );
	specbox.settings[ 'scale_h' ]	  = CreateClientConVar( 'specbox_scaleh', 6, true, false );
	specbox.settings[ 'thirdperson' ] = CreateClientConVar( 'specbox_zoom', 100, true, false );
end

specbox.init();

hook.Add("HUDPaint", "camera", specbox.camera);