• Need Assistance With A Derma Menu
    7 replies, posted
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. [url]http://wiki.garrysmod.com/?title=Guide_to_Derma[/url] 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. :D [B]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[/B]
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 [b]Server Side only[/b] into the [b]init.lua[/b] file under [b]// Server Side only stuff goes here[/b]. Then I placed the [b]client side[/b] code you gave me into the [b]cl_init.lua[/b] under [b]// Client Side Only Goes Here[/b] My Files look like this right now, what am i doing wrong? [b]cl_init.lua[/b] [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] [b]init.lua[/b] [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 [b][url=http://wiki.garrysmod.com/?title=User_Messages]usermessages[/url][/b] 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"! :)
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 :D
First time I write something useful :D
Sorry, you need to Log In to post a reply to this thread.