GMOD Lua Show Html

Hello all developers!

I found this piece of code:


HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")

On https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index01b1.html this site.

My question is, what players will it be shown to and how can i select what players it will be shown to. Or is it something that i have missed?

  • Thank you.

This piece of code only creates the html panel. To show it, you need to add HTMLTest:Popup() at the end of your piece of code, so everytime the file where your code is ran, the window will open.

[editline]6th October 2014[/editline]

You can also put the panel in a function that is linked to a console command like that:


function testpanel()
HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")
HTMLTest:MakePopup()
end
concommand.Add("testpanel", testpanel)

When you write testpanel in the console, your panel is going to open

How do i need to like “run” the code? Because now im using the command lua_openscript and when im trying “testpanel” in the console it’s not working. Do i need to create a new folder in addons and place it there and restart the server or what?

I have this code:


function testpanel()
	HTMLTest = vgui.Create("HTML")
	HTMLTest:SetPos(50,50)
	HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
	HTMLTest:OpenURL("http://www.garrysmod.com")
	HTMLTest:MakePopup()
end

for k, v in pairs( player.GetAll() ) do
    v:testpanel()
end

But it does not work.

Everytime i run the file, i want to show a specific webpage for everyone on the server.

P.S i hope you understand what i mean…

[lua]v:testpanel[/lua] :pwn:

Firstly, you can’t do that. Secondly, what are you even trying to do? Make the menu pop up for everyone? If so, you could use BroadcastLua, or net messages.

[editline]example[/editline]

Client side:
[lua]
local function OpenHTMLMenu()
HTMLTest = vgui.Create(“HTML”)
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL(“http://www.garrysmod.com”)
HTMLTest:MakePopup()
end

net.Receive(“OpenHTMLMenu”, function(len, server)
OpenHTMLMenu()
end)
[/lua]

Server side:
[lua]
util.AddNetworkString(“OpenHTMLMenu”)

function OpenHTMLMenu()
net.Start(“OpenHTMLMenu”)
net.Broadcast()
end
[/lua]

Running OpenHTMLMenu() server-side would then open it for everyone, whilst running OpenHTMLMenu() client side for a specific person would open it for them.

If you want to open it on a specific person, you could use

[lua]
ply:SendLua(“OpenHTMLMenu()”)
– Remember to have this somewhere ply is defined…
[/lua]

The for loop to get all the players is a server side function, while the panel you are trying to run is on the client side. Here’s a way to do it :

First of all we need to create a client side file that creates the panel. Put this file into your lua/autorun/client folder :


function testpanel()
	HTMLTest = vgui.Create("HTML")
	HTMLTest:SetPos(50,50)
	HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
	HTMLTest:OpenURL("http://www.garrysmod.com")
	HTMLTest:MakePopup()
end
concommand.Add("testpanel", testpanel)

Second of all we need to create a serverside function to force the panel on all the players screen. Put this file into your lua/autorun/server :


function forcepanel()

	for k,v in pairs( player.GetAll() ) do 
		v:ConCommand("testpanel")
	end
	
end

concommand.Add("forcepanel", forcepanel)

So when you’re going to type forcepanel in the console, it’s going to execute the console command testpanel on all the players. There are better way to do it, but this is probably the most basic way to do it. I haven’t tested it, but it should be working.

[editline]6th October 2014[/editline]

You could also create a single file that you put into lua/autorun :


if CLIENT then
	function testpanel()
		HTMLTest = vgui.Create("HTML")
		HTMLTest:SetPos(50,50)
		HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
		HTMLTest:OpenURL("http://www.garrysmod.com")
		HTMLTest:MakePopup()
	end
concommand.Add("testpanel", testpanel)
end

if SERVER then
	function forcepanel()

		for k,v in pairs( player.GetAll() ) do 
			v:ConCommand("testpanel")
		end
	
	end
concommand.Add("forcepanel", forcepanel)
end

Thanks for the help, but it wasn’t the most helpful post for a noob as me.
You didn’t make it very clear where to put the file etc.

[editline]7th October 2014[/editline]

Thanks for the help, it was really helpful. Before i didn’t know about client side and server side code etc.

[editline]7th October 2014[/editline]

Thanks for the post, you made it very clear. :slight_smile:

I don’t think you want all of your players to be able to force the panel on everyone else.
And make the DHTML parent to a dframe or create a close button for it. And ConCommand is a clientside function.

Here
[lua]if CLIENT then
function testpanel()
local frame = vgui.Create(“DFrame”)
frame:SetSize(ScrW() - 100, ScrH() - 100)
frame:SetTitle(“Html”)
frame:ShowCloseButton(true)
frame:SetDraggable(false)
frame:MakePopup()
frame:Center()

   local  HTMLTest = vgui.Create("HTML", frame)
	HTMLTest:SetSize(frame:GetWide(), frame:GetTall() - 24) -- I added minus 24 so it won't block the close button
	HTMLTest:OpenURL("http://www.garrysmod.com") -- change url here
	HTMLTest:MakePopup()
            HTMLTest:Center()
end

concommand.Add(“testpanel”, testpanel)
end

if SERVER then
function forcepanel(ply)
if ply:IsAdmin() then – admin check
for k,v in pairs( player.GetAll() ) do
v:RunConsoleCommand(“testpanel”)
end
end
end
concommand.Add(“forcepanel”, forcepanel)
end[/lua]

Since you’ve got answers to your questions I don’t have much to add unless you want more examples… But, I did want to give you this…

Here’s a dev tool to help you out: https://dl.dropboxusercontent.com/u/26074909/tutoring/_utilities/concommand_clearvgui.lua

Put in garrysmod server folder: /addons/acecool/lua/autorun/client/concommand_clearvgui.lua

Basically, it adds a console command to remove all vgui elements, including ones that may be stuck on your screen due to a typo and autorefresh…

It is very useful if you start working with VGUI. It is pretty easy to make a typo and end up with a vgui element stuck on the screen forcing you to retry to the local dev server to clear it before continuing testing…

Instead of retry, use clearvgui and continue working. There is a bug though; any element that used PANEL:ParentToHUD( ) doesn’t get properly seen in the HUD removal segment, so if you do decide to add vgui elements to your hud, test them before parenting…

If you aren’t working on a local SRCDS, I highly recommend it. If you use a Listen Server then CLIENT and SERVER code gets executed on your client. It can confuse things, overwrite wrong things and give a false impression of how the code will work in a live environment.

Here’s how to setup a local dev server:
https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

You can even set up a local FastDL: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/fastdl_setup_instructions.lua.html

then don’t add anything? the OP is obviously inexperienced with lua, why confuse him with code that’s barely relevant to the question (that’s already been answered (more than once))?

The main reason I wanted to add something is for the console command ( which is a drag and drop developer addon ) because inexperienced and even experienced users make typos or a small mistake with vgui and end up with vgui stuck on the screen. Having a simple console command to clear vgui is as useful, if not more-so, than stopsounds.

And, because I am not aware of how the OP is testing code, it is better to learn right from the start that a Listen server isn’t good for testing ( I added that because the OP admitted that he didn’t know the difference between SERVER and CLIENT code, which could be because he could be using a Listen Server ).

When I respond to posts, I typically think it through.