Raised This Month: $32 Target: $400
 8% 

Sourcemod Sub-Menus Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Graru1
New Member
Join Date: Dec 2018
Old 12-10-2018 , 07:26   Sourcemod Sub-Menus Help
Reply With Quote #1

I'm trying to create a menu for a server which lets the user easily toggle some options for themself, teach others or manage the server. The menu currently has following options.

General Commands
Donator Commands
Moderation Menu
Music Commands

When you choose an option it opens a submenu. But I want it to open seperate submenus for each option. I am new to sourcemod I would appreceate some help

Here's the current code:
Code:
#include <sourcemod>

new Handle:g_hMenuOne = INVALID_HANDLE;
new Handle:g_hMenuTwo = INVALID_HANDLE;
new Handle:g_hMenuThree = INVALID_HANDLE;

public OnPluginStart()
{
	g_hMenuOne = CreateMenu(MenuOneHandler);
	SetMenuTitle(g_hMenuOne, "JA Menu");				//JA Menu
	AddMenuItem(g_hMenuOne, "1", "General Commands");
	AddMenuItem(g_hMenuOne, "2", "Donator Commands");
	AddMenuItem(g_hMenuOne, "3", "Moderation Menu");
	AddMenuItem(g_hMenuOne, "4", "Music Commands");

	g_hMenuTwo = CreateMenu(MenuTwoHandler);
	SetMenuTitle(g_hMenuTwo, "Submenu Two");		//
	AddMenuItem(g_hMenuTwo, "1", "Go to Submenu Three");
	SetMenuExitBackButton(g_hMenuTwo, true);

	g_hMenuThree = CreateMenu(MenuThreeHandler);
	SetMenuTitle(g_hMenuThree, "Submenu Three");
	AddMenuItem(g_hMenuThree, "2", "Bye!");
	SetMenuExitBackButton(g_hMenuThree, true);

	RegAdminCmd("sm_jamenu", Command_JAMenus, ADMFLAG_SLAY, "sm_jamenu opens up some JA related menu");
}

public Action:Command_JAMenus(client, args)
{
	if (client > 0)
	{
		DisplayMenu(g_hMenuOne, client, MENU_TIME_FOREVER);
	}

	return Plugin_Handled;
}

public MenuOneHandler(Handle:menu, MenuAction:action, param1, param2)
{
	if (action == MenuAction_Select && IsClientInGame(param1))
	{
		DisplayMenu(g_hMenuTwo, param1, MENU_TIME_FOREVER);
	}
}

public MenuTwoHandler(Handle:menu, MenuAction:action, param1, param2)
{
	if (action == MenuAction_Select && IsClientInGame(param1))
	{
		DisplayMenu(g_hMenuThree, param1, MENU_TIME_FOREVER);
	}
	else if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack && IsClientInGame(param1))
	{
		DisplayMenu(g_hMenuOne, param1, MENU_TIME_FOREVER);
	}
}

public MenuThreeHandler(Handle:menu, MenuAction:action, param1, param2)
{
	if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack && IsClientInGame(param1))
	{
		DisplayMenu(g_hMenuTwo, param1, MENU_TIME_FOREVER);
	}
}
Thanks in advance
Graru1
Graru1 is offline
cra88y
AlliedModders Donor
Join Date: Dec 2016
Old 12-12-2018 , 15:30   Re: Sourcemod Sub-Menus Help
Reply With Quote #2

Honestly I don't know what's up with what you have but here's the code I use for a relevant plugin

You can use multiple handlers but I felt it was easier for me to just combine them since a lot of them used shared functions
Code:
public void WelcomeMenu(int client)
{
	Menu menu = new Menu(WelcomeMenuHNDLR, MENU_ACTIONS_ALL);
	menu.SetTitle("Welcome %N!", client);
	menu.AddItem("commands", "Some server commands");
	menu.AddItem("rules", "Server Rules");
	menu.AddItem("settings", "Server Settings");
	menu.ExitButton = true;
	menu.Display(client, MENU_TIME_FOREVER);
}
public int WelcomeMenuHNDLR(Menu menu, MenuAction action, int client, int choice)
{
	switch (action)
	{
		case MenuAction_Select:
		{
			char info[32];
			menu.GetItem(choice, info, sizeof(info));
			if (StrEqual(info, "done"))
			{
				delete menu;
			}
			else if (StrEqual(info, "commands"))
			{
				delete menu;
				Menu commands = new Menu(WelcomeMenuHNDLR, MENU_ACTIONS_ALL);
				commands.SetTitle("Some Cool Commands!");
				commands.AddItem("command1", "Command one");
				commands.AddItem("command2", "Command two");
				commands.AddItem("command3", "Command three");
				commands.ExitButton = true;
				commands.Display(client, MENU_TIME_FOREVER);
			}
			else if (StrEqual(info, "command1"))
			{
				FakeClientCommand(client, "sm_command1");
			}
			else if (StrEqual(info, "command2"))
			{
				FakeClientCommand(client, "sm_command2");
			}
			else if (StrEqual(info, "command3"))
			{
				FakeClientCommand(client, "sm_command3");
			}
			else if (StrEqual(info, "rules"))
			{
				FakeClientCommand(client, "sm_rules");
			}
			else if (StrEqual(info, "settings"))
			{
				delete menu;
				Menu settings = new Menu(WelcomeMenuHNDLR);
				settings.SetTitle("Server Settings");
				settings.AddItem("done", "xxxx");
				settings.AddItem("done", "xxxxx");
				settings.AddItem("done", "xxxxxx");
				settings.AddItem("done", "xxxxxxx");
				settings.ExitButton = true;
				settings.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}
__________________
cra88y#6386 for paid requests | Support

Last edited by cra88y; 12-12-2018 at 15:33.
cra88y is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode