Using VGUI with Surface

Hi all,

I’m currently trying to put a DHTML in the map but all I get is a grey rectangle( i made that so I know it was working )

Here’s the clientside code:



hook.Add("PostDrawOpaqueRenderables", "drawsometingplzlol", function()
	
	if LocalPlayer():GetPos():Distance( WEBWALL.WEBPOSITION ) > WEBWALL.DISTANCE then return end	
	
	cam.Start3D2D(WEBWALL.WEBPOSITION, WEBWALL.WEBANGLES, 0.25)
		surface.SetDrawColor(25, 25, 25, 255)
		surface.DrawRect(0, 0, WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT)
			
			local display = LocalPlayer().display
			if (IsValid(display)) then
				display:SetPaintedManually(false)
					display:PaintManual()
				display:SetPaintedManually(true)
			end 
		
	cam.End3D2D()
	

end)

net.Receive( "WebWallSend", function()
	local display = vgui.Create("DHTML")
		display:OpenURL("http://google.com/")
		display:SetSize( WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT )
		display:SetPaintedManually(true)
		display:SetMouseInputEnabled(true)
	
	LocalPlayer().display = display

end)


In my serverside code the net message “WebWallSend” is sent when the player initially spawns ( using PlayerInitialSpawn ). The rectangle I drew is drawn but I cannot see the webpage.

How can I see the webpage?

Thanks,
Computer600

Pretty sure you don’t need to call display:SetPaintedManually so many times.
I would’ve just used Panel:PaintAt( x, y ) and Panel:SetVisible( false )

Hmm, is this what you meant?



hook.Add("PostDrawOpaqueRenderables", "drawsometingplzlol", function()
	
	if LocalPlayer():GetPos():Distance( WEBWALL.WEBPOSITION ) > WEBWALL.DISTANCE then return end	
	
	cam.Start3D2D(WEBWALL.WEBPOSITION, WEBWALL.WEBANGLES, 0.25)
		surface.SetDrawColor(25, 25, 25, 255)
		surface.DrawRect(0, 0, WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT)
			
			local display = LocalPlayer().display
			if (IsValid(display)) then
				display:PaintAt( 0,0, WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT  )
				display:SetVisible(false)
			end 
		
	cam.End3D2D()
	

end)

net.Receive( "WebWallSend", function()
	local display = vgui.Create("DHTML")
		display:OpenURL("http://google.com/")
		display:SetSize( WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT )
		display:SetPaintedManually(true)
		display:SetMouseInputEnabled(true)
	
	LocalPlayer().display = display

end)


Because that doesn’t seem to work

Without display:SetPaintedManually(true). You only need to call display:SetVisible once.

Hmm still no, here’s the code now with those changes:



hook.Add("PostDrawOpaqueRenderables", "drawsometingplzlol", function()
	
	if LocalPlayer():GetPos():Distance( WEBWALL.WEBPOSITION ) > WEBWALL.DISTANCE then return end	
	
	cam.Start3D2D(WEBWALL.WEBPOSITION, WEBWALL.WEBANGLES, 0.25)
		surface.SetDrawColor(25, 25, 25, 255)
		surface.DrawRect(0, 0, WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT)
			
			local display = LocalPlayer().display
			if (IsValid(display)) then
                                print("test2")
				display:PaintAt( 0,0, WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT  )
			end 
		
	cam.End3D2D()
	

end)

net.Receive( "WebWallSend", function()
	print("hi")
	
	local display = vgui.Create("DHTML")
		display:OpenURL("http://google.com/")
		display:SetSize( WEBWALL.WEBWIDTH, WEBWALL.WEBHEIGHT )
		display:SetMouseInputEnabled(true)
		display:SetVisible(false)
		
	LocalPlayer().display = display

end)


I put some print functions in just to see if it was running and the “hi” print is showing, but the “test2” print isn’t so what have I done wrong?

Probably “if LocalPlayer():GetPos():Distance( WEBWALL.WEBPOSITION ) > WEBWALL.DISTANCE then return end” doesn’t work as you expect it to work.

Also, try PostDrawTranslucentRenderables hook.

Tried commenting out the if and that did nothing apart from removing the rectangle after the distance. and the hook did the same sadly. I tried ingame with the console command:



lua_run_cl print(LocalPlayer().display)


And it returned nil so I’m thinking that has something to do with it. But that net function gets ran ( because the print(“hi”) worked ) hmm

Right, missed that part. Does the print(“hi”) work? Do you actually send a net message “WebWallSend” from your server?

Yes it does, I looked at client console and it said “hi” meaning the net message got sent

EDIT: FIXED! It was sending the net message to quickly when the player spawned so a simple timer fixed it. Thanks for all the help Robotboy655