Thread: Simple text menu callback not working

Results 1 to 3 of 3
  1. #1
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Simple text menu callback not working

    I couldn't find any info on how to use text menus, but the API docs helped me figure most of it out. The menu is created, but nothing happens when an option is selected.

    Anything missing here?
    Code:
    void PluginInit()
    {
    	g_Module.ScriptInfo.SetAuthor( "w00tguy123" );
    	g_Module.ScriptInfo.SetContactInfo( "w00tguy123@gmail.com" );
    	g_Hooks.RegisterHook( Hooks::Player::ClientSay, @ClientSay );
    }
    
    void voiceMenuCallback(CTextMenu@ menu, CBasePlayer@ plr, int page, const CTextMenuItem@ item)
    {
    	g_Game.AlertMessage( at_console, "lol why doesn't this work\n");
    	g_PlayerFuncs.SayTextAll(plr, "Player chose: " + item.szName + " " + item.szUserData);
    }
    
    HookReturnCode ClientSay( SayParameters@ pParams )
    {
    	CBasePlayer@ plr = pParams.GetPlayer();
    	const array<string>@ args = pParams.GetArguments();
    	
    	if ( args.length() >= 1 )
    	{
    		if ( args[0] == "/vcom" )
    		{
    			CTextMenu@ menu = CTextMenu(@voiceMenuCallback);
    			menu.SetTitle("Best menu");
    			menu.AddItem("This is true", "true");
    			menu.AddItem("I disagree", "false");
    			menu.AddItem("No comment", "maybe");
    			if ( menu.Register() == false ) {
    				g_PlayerFuncs.SayTextAll(plr, "oh dear register failed");
    			}
    			menu.Open(10, 0, plr);
    			
    			return HOOK_HANDLED;
    		}
    	}
    	return HOOK_CONTINUE;
    }
    Love,
    w00tguy

  2. #2
    Banned Solokiller's Avatar
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    3,314

    Re: Simple text menu callback not working

    The text menu is being destroyed immediately after being created because its scope ends in the function that you created it in. You have to store the menu somewhere for it to continue to exist.

  3. #3
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Re: Simple text menu callback not working

    Yep, that was it. Thanks!
    Love,
    w00tguy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •