Open Derma on chat command

So I’m trying to make a derma panel pop up when a player says “!pubg”

Here is my code:



hook.Add("PlayerSay", "OpenCFG", function(ply, text, team)
	if ((text == "!pubg") && ply == LocalPlayer()) then
		local igcfg = vgui.Create("DFrame")
		igcfg:SetPos(0,0)
		igcfg:SetSize(500,400)
		igcfg:SetTitle("")
		igcfg:SetVisible(true)
		igcfg:ShowCloseButton(true)
		igcfg:MakePopup()
		igcfg:Center()
	end
end)


PlayerSay is a serverside hook. You should use that hook, check the command, then send a net message to the player to open the menu.

Use

GM:OnPlayerChat. No networking bullshit needed.

Why does everyone say to use net messages? STOP PLEASE I WANT TO DIE

GM:OnPlayerChat



hook.Add( "OnPlayerChat", "OpenCFG", function( ply, text )
	if ply == LocalPlayer() and text == "!pubg" then
		local igcfg = vgui.Create("DFrame")
		igcfg:SetPos( 0, 0 )
		igcfg:SetSize( 500, 400 )
		igcfg:SetTitle( "" )
		igcfg:SetVisible( true )
		igcfg:ShowCloseButton( true )
		igcfg:MakePopup()
		igcfg:Center()
		return true
	end
end )


[editline]27th September 2017[/editline]

ninja’d

Because you can’t block the chat command from being sent from there.


return true

to suppress the message

Return true as I did in my example and as the wiki says

[editline]27th September 2017[/editline]

ninja’d again

So here is my current code:



hook.Add("OnPlayerChat", "OpenCFG", function(ply, text, team)
	if ply == LocalPlayer() && text == "!pubg" then
		local igcfg = vgui.Create("DFrame")
		igcfg:SetPos(0,0)
		igcfg:SetSize(500,400)
		igcfg:SetTitle("")
		igcfg:SetVisible(true)
		igcfg:ShowCloseButton(true)
		igcfg:MakePopup()
		igcfg:Center()
		return true
	end
end)


But still no panel pops up.

Did u read anything we said?

That’s a waste. What happens internally is:


CLIENT: Player chats -- is networked to the server
SERVER: Receives the message and calls PlayerSay. If you return "" here, it will not be networked.
SERVER: Networks it to all clients, including the client who sent it
CLIENT: OnPlayerChat is called on all clients

If you block the message serverside, it will stop the networking from occurring internally. Pinging a client with the net library is way less data than networking a string.

Copy paste my code. I just tested it, and for me at least, it works fine.

I did what you said. its in a client file, now using OnPlayerChat, and return true

[editline]26th September 2017[/editline]

I did, but still no panel

What directory are you putting it in?

I just ran it in Luapad and it worked. Where’d you put the file? Is it clientside or serverside?

Here is what the file looks like:

Thats where the code is (This is where everything else is being drawn):
\garrysmod\addons\pubg_hud\pubg\hud_vgui.lua

and it gets initialized here:
\garrysmod\addons\pubg_hud\lua\autorun\pubg_hud.lua

Also, the code could have a few lines removed, ShowCloseButton is true by default, as is SetVisible, and SetPos is unnecessary if you’re centering it anyway:



hook.Add( "OnPlayerChat", "OpenCFG", function( ply, text )
	if ply == LocalPlayer() and text == "!pubg" then
		local igcfg = vgui.Create("DFrame")
		igcfg:SetTitle( "" )
		igcfg:SetSize( 500, 400 )
		igcfg:Center()
		igcfg:MakePopup()
		return true
	end
end )


Sorry, automerge

In your pubg_hud.lua file, are you including hud_vgui.lua clientside, and AddCSLuaFile’ing it serverside?

Here is my pubg_hud.lua file:



if SERVER then
	AddCSLuaFile("pubg/config.lua")
	AddCSLuaFile("pubg/hud_main.lua")
	AddCSLuaFile("pubg/hud_fonts.lua")
	AddCSLuaFile("pubg/hud_vgui.lua")

	resource.AddFile("materials/pubg/bullet.png")
    resource.AddFile("materials/pubg/armor.png")
    resource.AddFile("materials/pubg/helmet.png")
    resource.AddWorkshop("1148369256")
else
	include("pubg/hud_main.lua")
end


You are only including hud_main.

Yeah my dumbass just realized that. It works not, sorry