F2 Menu

Ok I’am making this gamemode but I could do with some help if any one is willing to help me. :slight_smile:

Ok so I want to make a F2 menu for my gamemode to pick a class;

Sniper, Rife, and Patriot

How would i go about making this menu? All I can do is make the frame and add detail to it.

Well you’ll have to be a little more specific about what you need help on. If it’s about designing the derma itself you might want to look at other gamemodes for examples, if you need help about a particular function feel free to name it and if it’s about making the menu show up F2 you can simply use the ShowTeam hook.

Thank you! I’ve been wanting that thank you :smiley: but how do you make it another key like f3 or f4?

Take a look at the “See Also” at the bottom of the page :wink:

then read them.

I tryed

Server Side:

function SchoolShow( ply )
ply:ConCommand( “SchoolMe” )
end
hook.Add(“ShowTeam”, “School”, SchoolShow)

function Givesniper( ply )
give( “Barret .50 cal”)
end

concommand.Add(“sniper_class”)

then Client side:

function SchoolShow( ply )

local classes = vgui.Create( “DFrame” )
classes:SetPos( 50,50 )
classes:SetSize( 100, 200 )
classes:SetTitle( “Pick Your Class” )
classes:SetVisible( true )
classes:SetDraggable( false )
classes:ShowCloseButton( true )
classes:MakePopup()

local DermaButton = vgui.Create( “DButton” )
sniper:SetParent( “classes” )
sniper:SetText( “Sniper” )
sniper:SetPos( 50, 10 )
sniper:SetSize( 80, 10 )
sniper.DoClick = function ()
RunConsoleCommand( “sniper_class” )
end

But it just ruins the gamemode? give me alittle help here? please.

This is a shot out of the dark, but try make client side and server side in different LUAs?

How so?

If you want this to be called when the F2 menu is pressed, you could just do:
[lua]function GM:ShowTeam( pl )
pl:SendLua( “FunctionName()” ) --Alternative to ConCommand
end[/lua]
That’s an alternative, I’ve never used the hook for it as I’m not sure it works the same way as the actual function.

As for:
[lua]function Givesniper( ply )
give( “Barret .50 cal”)
end[/lua]
That wont work. The weapon name is what the folder containing the lua files for the weapon is named, something like weapon_barret ( Example ). You’re using the give function wrong, or forgetting something.
[lua]function SniperGive( pl )
pl:Give( “weapon_sniper” )
end[/lua]

So this should work? Should i not use the hook?

function SchoolShow( ply )
pl:SendLua( “FunctionName()” )
end
hook.Add(“ShowTeam”, “School”, SchoolShow)

function SniperGive( pl )
pl:Give( “weapon_sniper” )
end

concommand.Add(“sniper_class”)

I’ve doen it all gamemodes working but the menu comes back with
Warning: Unhandled usermessage ‘SchoolMe’

Fixed it all but now i get

Unknowncommand:sniper_class

and there buttons will not follow the menu and when pressing f2 they will appear behide the menu its self

function SchoolShow( ply )

local classes = vgui.Create( “DFrame” )
classes:SetPos( 400, 300 )
classes:SetSize( 250, 200 )
classes:SetTitle( “Pick Your Class” )
classes:SetVisible( true )
classes:SetDraggable( true )
classes:ShowCloseButton( true )
classes:MakePopup()

local sniper = vgui.Create( “DButton” )
sniper:SetParent( classes )
sniper:SetText( “Sniper” )
sniper:SetPos( 400, 300)
sniper:SetSize( 230, 20 )
sniper.DoClick = function ()

    classes:Close()

RunConsoleCommand( "sniper_class" )

end

That’s because you don’t have a function Sniper_class >.>
please read the wiki! http://wiki.garrysmod.com/?title=LUA:Gamemode_from_scratch

EDIT:

also PLEASE put your code in [ lua][ /lua] or [ code][ /code] tags!

Look before you post


function SniperGive( ply )  
ply:Give("weapon_sniper")  
end  
concommand.Add("sniper_class", SniperGive)

LAWL! FAIL! you changed it before you posted! In the original you forgot the second argument!!! So technically I AM right and I DID read it. But now you say its still not working? I just woke up so ill take a look at it when im fully awake, as I dont see any errors at the moment

[editline]06:49AM[/editline]

Heres the proof! :smiley:

Yes but thats why i said i fixed it…

but i did have the function posted

For F3/F4 I think you can bind it to GMShowSpare2 and 3. (something like that)
And GMShowHelp for F1.

dude i’ve already done that i just get


Unknowncommand:sniper_class

but thanks for replying

Post your code please

No worrys i have fixed it :slight_smile: but i get this error back


NULL Ent in GiveNamedItem!


function SniperClass(ply)  
ply:Give("weapon_sniper")
return ""
end  
AddChatCommand("/sniper", SniperClass)


function SniperClass(ply)  
ply:Give("sniper")
return ""
end  
AddChatCommand("/sniper", SniperClass)