Raised This Month: $ Target: $400
 0% 

How to use a menu in a MetaMod plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 02-11-2012 , 12:41   How to use a menu in a MetaMod plugin?
Reply With Quote #1

Hello everyone!

I'm just wondering how to use menus in these modules!
Would be great if someone can explain me...

I know that a menu is a sent message, but, the problem is, the function with the button the player is pressing, and many: ...
How to register that function, to hook the menu shown to player?

Thanks in advance!
__________________

Last edited by claudiuhks; 02-11-2012 at 12:42.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-11-2012 , 12:45   Re: [HELP] Menus
Reply With Quote #2

Why you don't look at the amxx source code ?
__________________
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 02-11-2012 , 16:18   Re: [HELP] Menus
Reply With Quote #3

I want something better explained like a tutorial if possible.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
jim_yang
Veteran Member
Join Date: Aug 2006
Old 02-11-2012 , 21:29   Re: [HELP] Menus!
Reply With Quote #4

I can show you a simple example to begin with.
plain menu, some codes from amxx
PS: C-style, I personally don't like c++ class style for doing this.

Code:
bool g_Is_CSDM_Menu = false;	//distinguish from other menus
void (*g_MENU_func)(int);	//your menu callback function
char menu[512];			//menu text

void show_menu(int keys)
{
	MESSAGE_BEGIN(MSG_ONE, MSGID_ShowMenu, NULL, pEdict_Jim);
	WRITE_SHORT(keys);
	WRITE_CHAR(-1);
	WRITE_BYTE(FALSE);
	WRITE_STRING(menu);
	MESSAGE_END();
}

void show_menu_advanced(int keys, int mlen)
{
	char *m = menu;
	char *n = menu;
	char c = 0;
	int a;

	while(*n)
	{
		a = mlen;
		if(a > 175)
			a = 175;
		mlen -= a;
		c = *(n+=a);
		*n = 0;
		
		MESSAGE_BEGIN(MSG_ONE, MSGID_ShowMenu, NULL, pEdict_Jim);
		WRITE_SHORT(keys);
		WRITE_CHAR(-1);
		WRITE_BYTE(c ? TRUE : FALSE);
		WRITE_STRING(m);
		MESSAGE_END();
		*n = c;
		m = n;
	}
}

//CSDM Main Menu
void csdm_menu_main()
{
	int keys = (KEY_1|KEY_2|KEY_3|KEY_4|KEY_5|KEY_6|KEY_7|KEY_8|KEY_9|KEY_0);
	int len  = sprintf(menu, "\\yCSDM Settings\n\n\
				 \\r1.\\w Players\n\
				 \\r2.\\w Maps\n\
				 \\r3.\\w Bots\n\
				 \\r4.\\w Game Modes\n\
				 \\r5.\\w Grenades\n\
				 \\r6.\\w Brightness\n\
				 \\r7.\\w Jim\n\
				 \\r8.\\w Time\n\
				 \\r9.\\w Spawn Editor\n\n\
				 \\r0.\\w Exit");

	show_menu_advanced(keys, len);

	g_Is_CSDM_Menu = true;
	g_MENU_func = csdm_menu_main_cmd;
}

void csdm_menu_main_cmd(int key)
{
	switch(key)
	{
	case 1:	csdm_menu_players();		break;
	case 2: csdm_menu_maps();			break;
	case 3: csdm_menu_bots();			break;
	case 4: csdm_menu_modes();			break;
	case 5: csdm_menu_grenades();		break;
	case 6: csdm_menu_brightness();		break;
	case 7: csdm_menu_jim();			break;
	case 8: cmd_csdm_time();			break;
	case 9: csdm_menu_spawn_editor();	break;
	}
}

//hook clientcommand
void C_ClientCommand(edict_t *pEntity)
{
	const char *cmd = CMD_ARGV(0);
	if( EQUAL(cmd, "menuselect") && pEntity == pEdict_Jim && g_Is_CSDM_Menu)
	{
		g_Is_CSDM_Menu = false;
		(*g_MENU_func)(atoi(CMD_ARGV(1)));
		RETURN_META(MRES_SUPERCEDE);
	}
	else
		RETURN_META(MRES_IGNORED);
	
	RETURN_META(MRES_IGNORED);
}
I think this is quite clear and self-explained, hope this helps.
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 02-12-2012 , 11:35   Re: [HELP] Menus!
Reply With Quote #5

what a clear code !
test and work fine !
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 02-14-2012 , 15:04   Re: [HELP] Menus!
Reply With Quote #6

Of course, it works like a charm.
Thanks in advance, Jim.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
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 20:04.


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