RunConsolCommand and concommand.Add | Lua Help

Hello everyone!
First of all, my name is pakos. I’m new to lua coding and started building up a basic addon for the admins on my server.

I do have some experience in coding, for example in ‘second life’ (If anyone knows the scripting language there)

However, I have a problem in this code and would really much appreciate if you could help or even fix the code and past the correct version of it here. <3!

Files:
I made a net library in the init.lua file (Server side)
I made a net.Receive in the cl_init.lua file (Client side)

What i’m trying to do:
I want the consol command ‘pkgaming_menu’ to open the vgui.
I don’t want ShowSpare2 to open it. (F4 key)
I want the consol command ‘FAdmin cleardecals’ to run, when some admin pressed the button.

Problems:
My vgui doesn’t appear on F4 nor does it appear if I type pkgaming_menu in the consol. :confused:

Thanks in advance for helping me out with this problem!

cl_init.lua code:


	net.Receive( 'pkgaming', function()
		local base = vgui.Create( 'DFrame' )
			base:SetSize( 600, 300 )
			base:Center()
			base:SetTitle( ' ' )
			base:ShowCloseButton( true )
			base:SetDraggable( false )
			base:SetVisible( true )
			base:MakePopup()
			function base:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 150, 30 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-2, h-2 )
			end
			
		local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:SetPos( 20, 20 )
			button:SetSize( 50, 25 )
			button:SetText( 'FA cldec' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("FAdmin cleardecals", "1" ) 
			end
		
		local button2 = vgui.Create( 'DButton' )
			button2:SetParent( base )
			button2:SetPos( 90, 20 )
			button2:SetSize( 50, 25 )
			button2:SetText( 'FA stso' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("FAdmin cleardecals", "1" )
			end
		
		local button3 = vgui.Create( 'DButton' )
			button3:SetParent( base )
			button3:SetPos( 180, 20 )
			button3:SetSize( 50, 25 )
			button3:SetText( 'ULX rag' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("FAdmin cleardecals", "1" )
			end
				
	end )
	
concommand.Add( "pkgaming_menu", pkgaming )

init.lua code:


util.AddNetworkString( 'pkgaming' )

hook.Add( 'ShowSpare2', 'testietest', function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end )

If you need more information, please get me updated on that and I will give you all I have. Thank you so much!!

Remove ‘concommand.Add( “pkgaming_menu”, pkgaming )’ from cl_init, and put this into your init.lua:



concommand.Add( "pkgaming_menu", function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end)

I will do that, thank you!

[editline]15th May 2014[/editline]

The RunConsoleCommand(“FAdmin cleardecals”, “1” ) doesn’t work. Anything I can do to make it work. Is the “1” a false argument, is the “FAdmin cleardecals” a false string? Is the RunConsoleCommand(“FAdmin cleardecals”, “1” ) A false command?

[lua]RunConsoleCommand("_FAdmin", “ClearDecals”)[/lua]

Oh wow, thank you Bo98!

[editline]15th May 2014[/editline]

I have this


 util.AddNetworkString( 'pkgaming' )

/*

hook.Add( 'ShowSpare2', 'testietest', function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end )

*/
concommand.Add( 'pkgaming_menu', 'testietest', function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end )

inside the init.lua (Server side) file.

and this



	net.Receive( 'pkgaming', function()
		local base = vgui.Create( 'DFrame' )
			base:SetSize( 600, 300 )
			base:Center()
			base:SetTitle( ' ' )
			base:ShowCloseButton( true )
			base:SetDraggable( false )
			base:SetVisible( true )
			base:MakePopup()
			function base:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 150, 30 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-2, h-2 )
			end
			
		local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:SetPos( 20, 20 )
			button:SetSize( 50, 25 )
			button:SetText( 'FA cldec' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("_FAdmin", "cleardecals") 
			end
		
		local button2 = vgui.Create( 'DButton' )
			button2:SetParent( base )
			button2:SetPos( 90, 20 )
			button2:SetSize( 50, 25 )
			button2:SetText( 'FA stso' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("_FAdmin", "cleardecals")
			end
		
		local button3 = vgui.Create( 'DButton' )
			button3:SetParent( base )
			button3:SetPos( 180, 20 )
			button3:SetSize( 50, 25 )
			button3:SetText( 'ULX rag' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 112, 112, 112 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-1, h-1 )
			end
			function button:DoClick()
				RunConsoleCommand("_FAdmin", "cleardecals")
			end
				
	end ) 

in the cl_init.lua (Client side) file.

But when I type ‘pkgaming_menu’ nothing happens.

What I think, is that the net Library doesn’t work. Since when I do a DFrame without the net library it works. (With the same code)

Please, PAY ATTENTION to what I say. Is that too hard?

He … did …
In his most recent post where he has supplied his code, he has done what you have told him to do…

He said to put it in serverside part.

[lua]
AddCSLuaFile("<insert cl_init.lua file path here>")
[/lua]
Add that to server side.

Find the differences between his code:


concommand.Add( 'pkgaming_menu', 'testietest', function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end )

and my code:


concommand.Add( "pkgaming_menu", function( ply )
	net.Start( 'pkgaming' )
	net.Send( ply )
end)

[editline]15th May 2014[/editline]

If that was the case, he wouldn’t have been able to open the menu with F2 previously.

At what point is this working?

My bad, must have misread it.

Thanks for you efforts guys! I really much appreciate it!

@ Robotboy655

I replaced the code and did everything you told me to, I also included every file I need (AddCSLuaFile("")), but it still didnt work. In some video I then saw, after the command I want to enter to call a certain function, I need some kind of ‘place holder’ so I added “testietest” inbetween. I did as I got told. My net librarys work for everything else, … inventory, shop, etc. Just not for the most simple structure of a code which is pretty annoying. And Idk why it wont work. Howerver, I made the Derma I had without the net library. Thanks again for your effort <3!

[editline]18th May 2014[/editline]

I will set this thread as ‘solved’ since I figured a different way. Love you all!!

That’s for hook.Add. Not concommands.

Oh, alright. Thank you Bo98!