Clientside Menu for Console Commands

I know this is possible. It’s too simple not to be. However, though I’m good enough at fiddling, I’d like some help getting started. The basic idea is that when holding down a button (Let’s say ‘b’ for now), a dropdown menu will appear from your cursor and your cursor will be unlocked to select an item from the dropdown menu. When you click one of the items in the dropdown menu, it will run a command in the clients console. The thing is, I want this whole process to be done clientside. I don’t think this is exactly a request, as I want to be kind of involved in the process of making it.

Thanks for any help or suggestions.


RunConsoleCommand("say","This is a command in the client console")

You might want to copy and modify the example Lua from here, as it should give you a good example of a list in a layout. For example,



concommand.Add( "commandlistbox", function()

local Frame = vgui.Create( "DFrame" ) //Create a Frame to contain everything.
Frame:SetTitle( "Console Commands" )
Frame:SetSize( 375, 240 )
Frame:Center()
Frame:MakePopup()

local Scroll = vgui.Create( "DScrollPanel", Frame )
Scroll:SetSize( 355, 200 )
Scroll:SetPos( 10, 30 )

local List	= vgui.Create( "DIconLayout", Scroll )
List:SetSize( 340, 200 )
List:SetPos( 0, 0 )
List:SetSpaceY( 5 )
List:SetSpaceX( 5 )

for i = 1, 35 do //A loop to create a lot of buttons in your panel
	local ListItem = List:Add( "DButton" )
	ListItem:SetSize( 80, 40 )
end

end)


That would give you a list of buttons all with the same label, if you type ‘commandlistbox’ in the console. The only problem is, I have no idea how you are able to list all console commands to then add labels to the buttons doing the commands when pressed. I’m just offering a base. By the way, put that in the autorun/client folder of garry’s mod if you want it to work.

I’m not sure if you can get the default console commands via Lua. However, for commands added by Lua, you could detour concommand.Add to get the command names into a table, then run the original function to create the command. You’d also have an obscene amount of commands if you were to get every single command; I don’t think a drop down menu with 2000+ options is a good idea. As for binding it, you can either use a KeyPress hook if you wish to use the IN_ENUMS or use a clientside Think hook with the input library to use the KEY_ENUMS.

For the detouring:



local cadd = cadd or concommand.Add
ConCommandList = ConCommandList or {}


function concommand.Add(name, callback, autocomplete, helptext, flags)
	ConCommandList[#ConCommandList+1] = name
	cadd(name, callback, autocomplete, helptext, flags)
end


You could also just use concommand.GetTable which returns the internal tables and not a copy. So they can be modified. Engine concommands can’t be modified or detected on call.

Whoops. When the wiki said it got a table of all the callbacks and autocomplete functions, I assumed that it was a numerical table, not one that used the command names as keys.

concommand.GetTable() doesn’t return ALL the commands, only the custom ones. The example below shows so.



concommand.Add( "concommandmenu", function()

local Frame = vgui.Create( "DFrame" ) //Create a Frame to contain everything.
Frame:SetTitle( "Console Commands" )
Frame:SetSize( ScrW()-100, ScrH()-100 )
Frame:Center()
Frame:MakePopup()
Frame:SetSizable(true)

local Scroll = vgui.Create( "DScrollPanel", Frame )
Scroll:Dock(FILL)

local List = vgui.Create( "DIconLayout", Scroll )
List:Dock(FILL)
List:SetSpaceY( 5 )
List:SetSpaceX( 5 )

local test, _ = concommand.GetTable()

	for k, _ in pairs(test) do
	local ListItem = List:Add( "DButton" )
	ListItem:SetSize( 100, 50 )
	ListItem:SetText(k)
	ListItem.DoClick = function()
		RunConsoleCommand( k )
		Frame:Remove()
		end
	end
end )


Note this still works as requested, just not with all of them.

[editline]16th May 2015[/editline]

I have a feeling the solution is something dodgy to do with



cvarlist log data/cvarlist.txt


And file.Read…