Open a vgui panel when the user presses a key.

Hi. I’m working on a gamemode. I’m trying to create a main menu for all the functions etc.
I want it to open when i press a key. Then close when i press the default close button.

Right now i’m using this to open the box, but obviusly it just opens a ton of windows:
[lua]
if(input.IsKeyDown(KEY_F2)) then

[/lua]
How do i do this?

Check if the menu exists before creating it -

[lua]if !menu then – make it end[/lua]

If you want it to happen on the F1/2/3/4 keys, look at the functions like GM:ShowHelp

Yes, don’t use input.KeyIsDown for F keys.

[lua]
/-------------------------------------------------
Server
-------------------------------------------------
/

function GM:ShowTeam( pl )
pl:ConCommand( “open_menu” )
end

/-------------------------------------------------
Client
-------------------------------------------------
/

local function menu( )
// derma here
end

concommand.Add( “open_menu”, menu )
[/lua]

Oh ok :slight_smile: Thanks alot! :smiley:

Wouldn’t it be better to directly call the menu function? Why put it through a console command?

Because there is a difference between client and server…

Fuck me I got confused. I was thinking this was about the scoreboard. :v: