Hi. I’m trying to create a custom derma menu on the clientside whenever the player runs a console command. I created a file called lua_test.lua and put it into lua/autorun folder. Inside the file I created a function which you can find below.
local mainPanel = vgui.Create( "DPanel" )
mainPanel:SetPos( ScrW() / 2 - 150, ScrH() / 2 - 150 )
mainPanel:SetSize( 300, 300 )
concommand.Add( "lua_test_1", LuaTest1 )
However, whenever I write lua_test_1 into the console, I get this error: attempt to index global ‘vgui’ (a nil value). I did some searching and found that the error shows up whenever the vgui library is used on the server.
Now, here’s my question: how can I create clientside concommands in which I could use the vgui library?
I tried that, then it will say something along the lines of “concmd not found”. I also tried to do if( SERVER ) then return end and if( CLIENT ) then <code> end yet that had the same effect.
Ideally, I would like this to work in singleplayer. I also tried if( SERVER or !SinglePlayer() ) then return end yet that also complained about vgui being nil. Shouldn’t vgui be available in singleplayer in under both server and client code?
I believe it would be, as the code is run on your end (the client’s end), it should be accessible to you.
Client side doesn’t mean it has to be run in the ‘client’ space of the game.
This is where the terms ‘Client’ and ‘Server’ become a bit ambiguous, but what you’re looking for (if i understand you correctly) is code that is run from your end of the game. To achieve this, it doesn’t mean all of your code should be in the client space of your code, but rather, on your machine’s end of the game.
I may be wrong, let me test my theory…
[editline]17th January 2012[/editline]
It works for singleplayer, but not on multiplayer servers.
This would make sense, as i could see plenty of Lua based hacks being used if you were allowed to run your own code anywhere you like.
Anyhow, here’s what i used
print(“Running our test script…”)
function TestCommand( ply, comm, args )
print(“Sending to client…”)
print(“Running client side of script…”)
You can run any console command you’ve created on any multiplayer server as long as they do not have script enforcer on.
If you wanted to create your derma panel just put the file inside of garrysmod/lua/test.lua
Go in a server type in console lua_openscript_cl test.lua
then type your concommand in console which would be open.
I’ll reference this from this code.
local DermaPanel = vgui.Create( “DFrame” ) – Creates the frame itself
DermaPanel:SetPos( 50,50 ) – Position on the players screen
DermaPanel:SetSize( 800, 600 ) – Size of the frame
DermaPanel:SetTitle( “Testing Derma Stuff” ) – Title of the frame
DermaPanel:ShowCloseButton( true ) – Show the close button?
DermaPanel:MakePopup() – Show the frame
You can run any console command you’ve created on any multiplayer server as long as they do not have script enforcer on. As I posted before, yes this does work by placing inside of autorun but they can’t have SE on.