Clientside concommands?

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.



function LuaTest1()
	local mainPanel = vgui.Create( "DPanel" )
	mainPanel:SetPos( ScrW() / 2 - 150, ScrH() / 2 - 150 )
	mainPanel:SetSize( 300, 300 )
end
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?

Put the file into the lua/autorun/client folder.

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?

Might have to use a usermessage to show the derma on the client end.

Though you shouldn’t have to, i guess it might work.

Yes, that would work, but I’d really want this to be fully clientside. e.g you can go to a random server, write lua_test_1 in the console and get a derma panel pop up.

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

Server code:
[lua]
AddCSLuaFile(“client/cl_test.lua”)

print(“Running our test script…”)

function TestCommand( ply, comm, args )

print(“Sending to client…”)

umsg.Start(“TestShowPanel”, ply)
umsg.End()

end

concommand.Add(“Test_Command”, TestCommand)[/lua]

Client code:
[lua]
print(“Running client side of script…”)

function ShowTestPanel( ply, comm, args )

print(“Ran command”)

local mainPanel = vgui.Create( “DFrame” )
mainPanel:SetPos( ScrW() / 2 - 150, ScrH() / 2 - 150 )
mainPanel:SetSize( 300, 300 )
mainPanel:SetTitle( “Test Panel” )
mainPanel:SetVisible( true )
mainPanel:MakePopup()

end

usermessage.Hook(“TestShowPanel”, ShowTestPanel)
[/lua]

concommand’s are executed(?) on the server not the client, you’ll have to send a usermessage back to the client to tell it the command has been ran like IceBreaker98 explains above.

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.
[lua]
function Menu()
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
end
concommand.Add(“open”, Menu)
[/lua]

-snip-
didn’t read the whole thing

What the fuck are you talking about…? I posted exactly what he asked for.

Brandon’s solution looks like the best for me. I’ll try it out after school and post back if it worked.

It works using lua_openscript_cl but is there any way to autorun it?

Put it in “lua/autorun/client/”.

If you used the two-part solution that Icebreaker posted, however, you need to put the serverside piece in “lua/autorun/server/” and the client piece in “lua/autorun/client/”.

As far as i’m aware, this doesn’t work on a server.

However, i did not try it with the lua_openscript_cl command, but this would negate the ‘autorun’ effect.

IceBreaker “YOU” Are not reading this.

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.

I’m aware of this. That’s not what i was talking about.

I was talking about how it has to be run manually. It will not run the script file on its own.

Panto asked if there was a way for the script to be run automatically. As far as i’m aware, there isn’t.

You have to run the script by using the lua_openscript_cl command.

It will run automatically on singleplayer, as i’ve said before.

Look at what nonsense posted and what wizards bane posted. This has already been solved.

What i had meant by my post of ‘This doesn’t work on a server’ is that it is not run automatically on a server. It requires lua_openscript.

If you are coding on a server without SE you’d have to use lua_openscript to reload the code anyway, so theres no point in autorunning it unless you are not coding.

Thats simply what Panto requested.

I’m done bumping this thread.