In-Game Menu

Hey, I was just wondering how someone could create a pop-up menu, such as the F4 Menu in DarkRP or Sassilization’s menu.

Can someone give me a .lua code for such a thing or a tutorial you come across.

Its called derma, look it up here:

Thanks that worked, do you know how I could bind that “NameHere.lua” to a button (e.g: q), for the gamemode?

You don’t need to bind a lua script to a key, what you should do is create a console command in the script and then bind a key to that.

RunConsoleCommand( “bind F4 lua_openscript_cl (GunArena/content/addons/DButton.lua)” )
Placed in the DButton.lua folder.

And that doesnt work.

You can’t run the bind console command, it’s protected as it could allow people to mess about with your controls.
You’d have to do something like this and stick it in autorun, or at least somewhere that you know will be executed.
[lua]concommand.Add(‘ga_make_popup’, function() include(‘GunArena/content/addons/DButton.lua’) end)[/lua]

It also looks like you’re altering the DButton, this is in general a bad idea.

IS there anyway I could make this open by pressing down F4?

(User was banned for this post ("Didn't search" - mahalis))

– note, only works Clientside
hook.Add(“KeyPress”, “MenuPopup”, function(pl, key)
if key == KEY_F4 then

No you should use the hook, GMSpare2 I think

I placed that code in my cl_init.lua fine in the gamemodes folder of GunArena, and there was no errors, but by hitting F4, nothing happened.

I am POSITIVE that this file works, just pressing the button doesnt.

You could maybe make a concommand of your menu function, and then call it with:

– Note, still only works Clientside
hook.Add(“KeyPress”, “MenuPopup”, function(pl, key)
if key == KEY_F4 then
RunConsoleCommand(“ShowMyMenu”) – Replace ShowMyMenu with your concommand.

You shouldn’t be opening menu’s like that. It’s a terrible method (the include way). Your panel should be VGUI registered and then opened using vgui.Create() in the keypress hook.

You don’t want to be creating a new menu everytime you want to see it. Creating it once then hiding/showing it should be fine.

And yeah you should totally use the ShowSpare2 hook.

What is wrong with creating it every time? As long as you destroy when you don’t need it, to stop duplications.

It depends of how big that interface is. If it takes a while to build it everytime then you will get a noticeable lag whenever you open it. I just think that something you use often should be kept in memory. Creating and deleting everytime is the same as spawning a model then clearing the cache. It will lag again next time you spawn that model.

If your interface needs dynamic information, such as the players on the server, then you would either need to rebuild your menu every time you open it (to update this information) or you would need to update it periodically, such as in a think hook. I would go for the first option. However, if the interface is large then I can see why you would need to keep it in memory.

Or you could have a hook when players join and leave so it only updates the menu when it changes.
It’s often all about tradeoffs
If you’re not using the menu very often or for very long then creating and destroying it would be the way to go.
If you always need it but it doesn’t need updating very often then use a hook to update it.
If it changes really rapidly (updates more than once a second, unlikely in the player list scenario) you may find it better to just update it every second.