• Open derma on key
    9 replies, posted
I've already manage to bind the derma panel to a key however when I hit it, it opens like 10 dermas on eachother. If anyone could help me with how to make it so that it only opens one [CODE] function ActMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetSize( 328, 101 ) Frame:Center() Frame:SetTitle("") Frame:MakePopup() Frame:SetVisible(true) Frame:ShowCloseButton(false) Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end end hook.Add( "ActMenuShow", "ActMenuShow", ActMenu ) hook.Add( "Think", "MenuKeyListener", function() if ( input.IsKeyDown( KEY_G ) ) then ActMenu() end end ) [/CODE] If possible I would even like to do it so that it is only open whilst you hold the key and when you release it it disappears
[CODE]local f1pressed = false hook.Add("Think", "input_menukey", function() if input.IsKeyDown(KEY_F1) and not f1pressed then f1pressed = true -- When F1 is pressed ToggleMenu() -- I toggle my menu here but you may want to do something like ActMenu() instead elseif (not input.IsKeyDown(KEY_F1)) and f1pressed then f1pressed = false -- When F1 is released -- And close your menu here end end)[/CODE] This is what I use for my gamemode's options menu. Works perfectly. Hopefully it helps.
[code]local keyDown; hook.Add("Think", "", function() if (input.IsButtonDown(KEY_G) and !keyDown) then ActMenu(); end keyDown = input.IsButtonDown(KEY_G); end); [/code] This is my way of doing it.
[QUOTE=Remixful;51300847][CODE]local f1pressed = false hook.Add("Think", "input_menukey", function() if input.IsKeyDown(KEY_F1) and not f1pressed then f1pressed = true -- When F1 is pressed ToggleMenu() -- I toggle my menu here but you may want to do something like ActMenu() instead elseif (not input.IsKeyDown(KEY_F1)) and f1pressed then f1pressed = false -- When F1 is released -- And close your menu here end end)[/CODE] This is what I use for my gamemode's options menu. Works perfectly. Hopefully it helps.[/QUOTE] How would I close the menu from outside the ActMenu() function?
:snip: misread the question [QUOTE=Flaow;51300894]How would I close the menu from outside the ActMenu() function?[/QUOTE] Make the frame variable OUTSIDE the function: [CODE] local Frame function ActMenu() Frame = vgui.Create( "DFrame" ) // the rest of the code [/CODE] Then just do Frame:Remove()
[code]local Frame local keyDown function ActMenu() if (Frame) then Frame:Remove() Frame = nil else Frame = vgui.Create( "DFrame" ) Frame:SetSize( 328, 101 ) Frame:Center() Frame:SetTitle("") Frame:MakePopup() Frame:SetVisible(true) Frame:ShowCloseButton(false) Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end end end hook.Add("Think", "MenuKeyListener", function() if (input.IsButtonDown(KEY_G) and !keyDown) then ActMenu() end keyDown = input.IsButtonDown(KEY_G) end); [/code]
[QUOTE=Moosicorn;51300916][code]local Frame local keyDown function ActMenu() if (Frame) then Frame:Remove() Frame = nil else Frame = vgui.Create( "DFrame" ) Frame:SetSize( 328, 101 ) Frame:Center() Frame:SetTitle("") Frame:MakePopup() Frame:SetVisible(true) Frame:ShowCloseButton(false) Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end end end hook.Add("Think", "MenuKeyListener", function() if (input.IsButtonDown(KEY_G) and !keyDown) then ActMenu() end keyDown = input.IsButtonDown(KEY_G) end); [/code][/QUOTE] That works great but I'm trying to get the hold down [editline]3rd November 2016[/editline] [QUOTE=MPan1;51300900]:snip: misread the question Make the frame variable OUTSIDE the function: [CODE] local Frame function ActMenu() Frame = vgui.Create( "DFrame" ) // the rest of the code [/CODE] Then just do Frame:Remove()[/QUOTE] Tried that but when I used my buttons that I have on the derma on their DoClick I have 1 command and then Frame:Close() and it does an error [editline]3rd November 2016[/editline] [QUOTE=Moat;51300824]Since the think hook is called every frame, you're gonna need to add a simple timer check to prevent the menu from opening every frame while the key is pressed. Example: [lua] local key_down_timer = CurTime() local key_down_delay = 1 hook.Add( "Think", "iskeydown_example", function() if ( input.IsKeyDown( KEY_G ) and key_down_timer <= CurTime() ) then -- Open your derma here key_down_timer = CurTime() + key_down_delay -- reset the timer end end ) [/lua][/QUOTE] I'm using this, it works perfectly. How would I make it so that when the menu is open already it doesn't open a new one when I click it again? [editline]3rd November 2016[/editline] [QUOTE=Remixful;51300847][CODE]local f1pressed = false hook.Add("Think", "input_menukey", function() if input.IsKeyDown(KEY_F1) and not f1pressed then f1pressed = true -- When F1 is pressed ToggleMenu() -- I toggle my menu here but you may want to do something like ActMenu() instead elseif (not input.IsKeyDown(KEY_F1)) and f1pressed then f1pressed = false -- When F1 is released -- And close your menu here end end)[/CODE] This is what I use for my gamemode's options menu. Works perfectly. Hopefully it helps.[/QUOTE] I would like to use this but don't know how to
Misread the question, thought you wanted a toggle. [code]local Frame function ActMenu() if (Frame and !input.IsButtonDown(KEY_G)) then Frame:Remove() Frame = nil elseif (input.IsButtonDown(KEY_G) and !Frame) then Frame = vgui.Create( "DFrame" ) Frame:SetSize( 328, 101 ) Frame:Center() Frame:SetTitle("") Frame:MakePopup() Frame:SetVisible(true) Frame:ShowCloseButton(false) Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end end end hook.Add("Think", "MenuKeyListener", function() ActMenu() end); [/code]
[QUOTE=Moosicorn;51300970]Misread the question, thought you wanted a toggle. [code]local Frame function ActMenu() if (Frame and !input.IsButtonDown(KEY_G)) then Frame:Remove() Frame = nil elseif (input.IsButtonDown(KEY_G)) then Frame = vgui.Create( "DFrame" ) Frame:SetSize( 328, 101 ) Frame:Center() Frame:SetTitle("") Frame:MakePopup() Frame:SetVisible(true) Frame:ShowCloseButton(false) Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end end end hook.Add("Think", "MenuKeyListener", function() ActMenu() end); [/code][/QUOTE] Opens up multiple menus and they aren't hold down only and it makes the buttons on it do this error [ERROR] lua/derma.lua:29: attempt to index upvalue 'Frame' (a nil value) 1. DoClick - lua/derma.lua:29 2. unknown - lua/vgui/dlabel.lua:232
Sorry, you need to Log In to post a reply to this thread.