Hello I have made a derma menu for my gamemode and I want to know how do I make it so if I press F4 it opens the menu?
Can you post the code?
Don't forget to use the # key, or the [lua ] [ /lua] brackets
My cl_init: [lua] include( 'shared.lua' )
function hidehud(name) -- Removing the default HUD
for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", })do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)
function CoolHUD()
local ply = LocalPlayer()
local HP = ply:Health()
local Armor = ply:Armor()
draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 120 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 255, 255, 255, 40 ) )
end
hook.Add( "HUDPaint", "CoolHUD", CoolHUD )
--{[ Menu ]}
[/lua]
Serverside:
[lua]function GM:ShowSpare2( ply )
umsg.Start( "F4Menu", ply )
umsg.End()
end[/lua]
Clientside:
[lua]usermessage.Hook("F4Menu", YourFunctionNameHere)[/lua]
So basically what this will do is send a message to the client when he/she presses F4, when the message is recieved it will execute your function which contains your menu etc.
Use the ShowSpare hook: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb26f.html[/url]
Or, if you just want the code:
[CODE]function [CommandNameHere]( ply )
ply:ConCommand( "[ConsoleCommandNameHere]" )
end
hook.Add("ShowSpare2", "Whatever", [Commandnamehere])[/CODE]
Wow, I thought I posted this but left it...
Here are two examples. One using the server-side hook for F1-F4 and networks it, and the other example does it all client-side.
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html[/url]
On top of this, you could use several different KeyPress hooks, Think to monitor for keypresses ( not recommended with the other hooks in place ), extending the vgui world/game-panel to capture keys / mouse events, etc... There are MANY ways to do what you want to do, it really just depends on how you want to do it.
JasonMan option is extremely viable, execute a console command on the client through the server, which is a nice simple way to open the vgui, however don't rely on console commands to "network", or to follow a sequence. It is one of the easiest ways for clients to tamper with a server..
[QUOTE=JasonMan34;45609732]Use the ShowSpare hook: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb26f.html[/url]
Or, if you just want the code:
[CODE]function [CommandNameHere]( ply )
ply:ConCommand( "[ConsoleCommandNameHere]" )
end
hook.Add("ShowSpare2", "Whatever", [Commandnamehere])[/CODE][/QUOTE]
Never link the old wiki if there is a [URL="http://wiki.garrysmod.com/page/GM/ShowTeam"]newer/updated version on the new wiki[/URL].
I dont use DarkRP anymore, but be careful when messing around with hooks that the gamemode uses. The code Jason used is pretty retarded, I would personally advise using TheDoggy's code but use it with caution. Overriding the hook will prevent DarkRP's default F4 menu from opening, which means you are responsible for rendering everything for your F4 menu. Adding a new hook to it and creating a new menu for it will mean that DarkRP's default F4 menu will open with yours (so you will have 2 menus open).
Sorry, you need to Log In to post a reply to this thread.