Addon VGUI

I am trying to make a VGUI screen in an addon, using a console command to access it( “vgui_menu” ). And the problem is when I call it, I get a server error( blue text ) about a nil value vgui. I know the problem is that its calling it on server, when its a client function. But when I check if its a client [lua] if( CLIENT ) then[/lua] I get an error of unknown console command “vgui_menu”. Im confused and unsure of what to do!

You can’t check if it’s the client unless it’s a shared script.

How do I make it a shared script? I’m used to working with the gamemodes with 3 files that are the server, client, and shared. This addon is a bit more confusing…

You send the file to the clients with AddCSLuaFile.

I did send the file to the clients… unless I messed up somewhere. I will go overlook my code again.

Well I have 1 main file, that includes “cl_menu.lua” and also sends “cl_menu.lua” to the client. Do I have to send the main file to the client aswell?

Does the client include (run) the file?

Yes, I now see the error of my way, I DO have to send the main file for it starts all the client functions and server functions. I might make 2 seperate “main” files for client functions and server functions.

That’s better, yes.

Well, if I’m testing on singleplayer, I shouldn’t have to worry about sending the files, as I already have them… and I am still getting errors. Maybe I looked at this wrong… Heres the basic outlay…

[addons] -> [My_Addon] -> [lua] -> [autorun] -> “launcher.lua”
[lua]if( SERVER ) then
AddCSLuaFile( “autorun/launcher.lua” )

include( “AddonLUA/init.lua” )[/lua]

[addons] -> [My_Addon] -> [lua] -> [AddonLUA] -> “init.lua”
[lua]if( SERVER ) then
AddCSLuaFile( “AddonLUA/init.lua” )
AddCSLuaFile( “cl_menu.lua” )
include( “cl_menu.lua” )[/lua]

[addons] -> [My_Addon] -> [lua] -> [AddonLUA] -> “cl_menu.lua”
[lua]local function plugin_DermaMenu()
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( “Testing Derma Stuff” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )

local CheckBoxThing = vgui.Create( "DCheckBoxLabel", DermaPanel )
CheckBoxThing:SetPos( 10,50 )
CheckBoxThing:SetText( "God Mode" )
CheckBoxThing:SetConVar( "sbox_godmode" ) -- ConCommand must be a 1 or 0 value
CheckBoxThing:SetValue( 1 )
CheckBoxThing:SizeToContents() -- Make its size to the contents. Duh?


concommand.Add( “qk_menu”, plugin_DermaMenu )[/lua] This is not all the code, except for cl_menu. Its just bits and bobs of the areas that handle inclusion and sending of other files…

The error is a blue text server error,cl_menu.lua:10: attempt to index global ‘vgui’ (a nil value). But in this case, line 02 is line 10!

That’s because after the server has ran the code inside the ‘if ( SERVER ) then’, it continues with the menu include.

Try this:

[lua]if( SERVER ) then
AddCSLuaFile( “AddonLUA/init.lua” )
AddCSLuaFile( “cl_menu.lua” )
include( “cl_menu.lua” )