Need Assistance With A Derma Menu

Hey guys, I’m having troubles with setting up my derma menu to open if i press like F4. I have read the tutorials on derma menus here.

But it doesn’t tell how you are able to get the menu to open up like in Darkrp once you hit F4. So i am just gonna take the example coding at the Guide to Derma wiki. And if you guys could explain what code i need to add, and or where I need to add it. All help is appreciated. :smiley:

**local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( “Menu” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local MenuButton = vgui.Create(“DButton”)
MenuButton:SetParent( DermaPanel )
MenuButton:SetText( “Menu >” )
MenuButton:SetPos(25, 50)
MenuButton:SetSize( 150, 175 )
MenuButton.DoClick = function ( btn )
local MenuButtonOptions = DermaMenu() – Creates the menu
MenuButtonOptions:AddOption(“hello”, function() Msg(“Hello”) end ) – Add options to the menu
MenuButtonOptions:AddOption(“how”, function() Msg(“How”) end )
MenuButtonOptions:AddOption(“are”, function() Msg(“Are”) end )
MenuButtonOptions:AddOption(“you”, function() Msg(“You”) end )
MenuButtonOptions:AddOption("?", function() Msg("?") end )
MenuButtonOptions:Open() – Open the menu AFTER adding your options
end**

Use [lua] tags.
F4 is showspare2, so use this on the serverside lua.
[lua] hook.Add(“ShowSpare2”,“OpenF4”, function (ply)
ply:SendLua(“OpenMenu()”
end)
[/lua]
Or use umsg’s instead.
For your code just do on the client
[lua]
function OpenMenu()
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( “Menu” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local MenuButton = vgui.Create(“DButton”)
MenuButton:SetParent( DermaPanel )
MenuButton:SetText( “Menu >” )
MenuButton:SetPos(25, 50)
MenuButton:SetSize( 150, 175 )
MenuButton.DoClick = function ( btn )
local MenuButtonOptions = DermaMenu() – Creates the menu
MenuButtonOptions:AddOption(“hello”, function() Msg(“Hello”) end ) – Add options to the menu
MenuButtonOptions:AddOption(“how”, function() Msg(“How”) end )
MenuButtonOptions:AddOption(“are”, function() Msg(“Are”) end )
MenuButtonOptions:AddOption(“you”, function() Msg(“You”) end )
MenuButtonOptions:AddOption("?", function() Msg("?") end )
MenuButtonOptions:Open() – Open the menu AFTER adding your options
end
end
[/lua]

Im still having problems getting it to work, i placed your code for the Server Side only into the init.lua file under // Server Side only stuff goes here.

Then I placed the client side code you gave me into the cl_init.lua under // Client Side Only Goes Here

My Files look like this right now, what am i doing wrong?

cl_init.lua
[lua]
include( ‘shared.lua’ )

// Clientside only stuff goes here

function OpenMenu()
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( “Menu” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local MenuButton = vgui.Create(“DButton”)
MenuButton:SetParent( DermaPanel )
MenuButton:SetText( “Menu >” )
MenuButton:SetPos(25, 50)
MenuButton:SetSize( 150, 175 )
MenuButton.DoClick = function ( btn )
local MenuButtonOptions = DermaMenu() – Creates the menu
MenuButtonOptions:AddOption(“hello”, function() Msg(“Hello”) end ) – Add options to the menu
MenuButtonOptions:AddOption(“how”, function() Msg(“How”) end )
MenuButtonOptions:AddOption(“are”, function() Msg(“Are”) end )
MenuButtonOptions:AddOption(“you”, function() Msg(“You”) end )
MenuButtonOptions:AddOption("?", function() Msg("?") end )
MenuButtonOptions:Open() – Open the menu AFTER adding your options
end
end
[/lua]

init.lua
[lua]

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

// Serverside only stuff goes here

hook.Add(“ShowSpare2”,“OpenF4”, function (ply)
ply:SendLua(“OpenMenu()”)
end)

/---------------------------------------------------------
Name: gamemode:PlayerLoadout( )
Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------
/
function GM:PlayerLoadout( ply )

ply:Give( "weapon_physcannon" )

ply:Give( "weapon_physgun" )

end
[/lua]

Don’t use SendLua. OpenMenu might not be in _G, but either way it’s bad coding practice. Use usermessages instead.

Did you save init.lua in “lua/autorun/server/” and cl_init.lua in “lua/autorun/client/”?
If you do that, you could remove the “include” and “AddCSLuaFile” lines, and maybe give it a console-command…
Just add [lua] concommand.Add(“OpenMenu”, OpenMenu ) [/lua] to the client file, and you got a console command named “OpenMenu”! :slight_smile:

Thanks Herover, i deleted the stuff you told me too and my menu now works when you hit f4, thank you soo much, now i can get on with my gamemode :smiley:

-snip-

First time I write something useful :smiley: