The Menu (again)

ok so now my menu worked by using openmenu
but i changed it so i can use F2 to open it instead, but my hook isnt working, could someone tell me why not
[lua]function Menutest()

local ply = LocalPlayer()

local BackGround = vgui.Create( "DFrame" )
BackGround:SetSize( 200, 90 )
BackGround:SetPos( (ScrW()/2)-BackGround:GetWide(), (ScrH()/2)-BackGround:GetTall() )
BackGround:SetTitle( "Ninjas - Main Menu" )
BackGround:SetVisible( true )
BackGround:SetDraggable( true )
BackGround:ShowCloseButton( true )
BackGround:MakePopup()

local AButton = vgui.Create( "DButton", BackGround )
AButton:SetSize( 160, 40 )
AButton:SetText( "Ninja Heal" )
AButton:SetPos( 20, 30 )
AButton.DoClick = function(AButton)
	ply:ConCommand( "say HEALLLL!!!!!!!" )
end

end

hook.Add( “ShowTeam”, “ninjasmenu”, Menutest )[/lua]

Put a print at the top to see if it’s getting called.

Code seems fine, you probably put it in the wrong place. Where is it at?

its in gamemode/ninjas/ <— Here
it used to work when i had
[lua]concommand.Add( “openmenu”, menutest )[/lua]
instead of
[lua]hook.Add( “ShowTeam”, “ninjasmenu”, Menutest ) [/lua]
i also cant try out anything right now because “steam servers are too busy to handle my request” and i can’t patch

I know how to fix it…
Read this http://wiki.garrysmod.com/?title=Binding_a_VGUI_to_F1-F4
you cant use that hook clientside you need to make the client run a console command or send him a usermessege, like in the tutorial

isn’t it easier to go into init.lua and do

[lua]function GM:ShowHelp( ply )
SendUserMessage( “OpenMenu” )
end[/lua]

But of course in the lua with the derma menu, you will need to hook a usermessage AFTER the derma has been created, so

[lua]function MenuTest()
–DermaCrap
end
usermessage.Hook( “OpenMenu”, “MenuTest”, MenuTest )[/lua]

[editline]11:03AM[/editline]



GM:ShowHelp --F1
GM:ShowTeam --F2
GM:ShowSpare1 --F3
GM:ShowSpare2 --F4

^Makes it easier to know what to put instead of GM:ShowHelp

I always use GM:BindPress on the client, is the usermessage method better?

Not really, The BindPress method cuts out the server. The usermessage method is better if you need to do some serverside security checks to see if the player is allowed to open the menu.

In the usermessage method the client actually sends a message to the server saying that he pressed a button, and then the server would send an usermessage back to the client saying that you need to display a menu.

It works, but it’s not as efficient as GAMEMODE.BindPress.

wasnt that exacly the thing i said?

I explained in a little more detail :3:

Ok now when i did that i always get this error

"
lua\includes\modules\usermessage.lua:77: attempt to call field ‘Function’ (a string value)"

here is my menu.lua[lua]function Menutest()

local ply = LocalPlayer()

local BackGround = vgui.Create( "DFrame" )
BackGround:SetSize( 200, 90 )
BackGround:SetPos( (ScrW()/2)-BackGround:GetWide(), (ScrH()/2)-BackGround:GetTall() )
BackGround:SetTitle( "Ninjas - Main Menu" )
BackGround:SetVisible( true )
BackGround:SetDraggable( true )
BackGround:ShowCloseButton( true )
BackGround:MakePopup()

local AButton = vgui.Create( "DButton", BackGround )
AButton:SetSize( 160, 40 )
AButton:SetText( "Ninja Heal" )
AButton:SetPos( 20, 30 )
AButton.DoClick = function(AButton)
	ply:ConCommand( "say HEALLLL!!!!!!!" )
end

end

usermessage.Hook( “OpenMenu”, “MenuTest”, MenuTest )[/lua]

and this is the init

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
AddCSLuaFile( “menu.lua” )

include( ‘shared.lua’ )
include( “menu.lua” )

// Serverside only stuff goes here

/---------------------------------------------------------
Name: gamemode:PlayerLoadout( )
Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------
/
function GM:PlayerSpawn( ply )
self.BaseClass:PlayerSpawn( ply )
ply:SetGravity( 0, 90 )
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 500 )
end

function GM:PlayerLoadout( ply )

ply:StripWeapons()
ply:Give( "weapon_crowbar" )
ply:Give( "weapon_shuriken" )

end
function GM:PlayerInitialSpawn( ply )
self.BaseClass:playerInitialSpawn( ply )
if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, “Ninjas : You appear to be an admin on Ninjas” )
end
end
– the f2 menu
function GM:ShowTeam( ply )
SendUserMessage( “OpenMenu”, ply )
end [/lua]

Try to replace function Menutest() by function Menutest(um) .

I am still getting the error :frowning:

usermessage.Hook only takes two arguments, Name and Function, so you can leave out the “MenuTest” string.

now im getting this
lua\includes\modules\usermessage.lua:77: attempt to call field ‘Function’ (a nil value)

any one have insight on this?

Can you post the code please, it seems like you are not passing a function in at all.

Your function is named Menutest.

You’re hooking MenuTest.

Capitals :eng101: