<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alliedmods.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=LbrGfn</id>
	<title>AlliedModders Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alliedmods.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=LbrGfn"/>
	<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/Special:Contributions/LbrGfn"/>
	<updated>2026-04-15T09:25:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.6</generator>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Using_New_Menu_System&amp;diff=4815</id>
		<title>Using New Menu System</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Using_New_Menu_System&amp;diff=4815"/>
		<updated>2007-07-01T02:52:43Z</updated>

		<summary type="html">&lt;p&gt;LbrGfn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting (AMX Mod X)]]&lt;br /&gt;
{{LanguageSwitch}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Write some intro here&lt;br /&gt;
&lt;br /&gt;
== Beginners Menu Tutorial ==&lt;br /&gt;
Now lets discuss how to use the new menu system. We will go through the basics in this tutorial and make a simple Change Level vote.&lt;br /&gt;
&lt;br /&gt;
=== Includes ===&lt;br /&gt;
As always we will start out by adding the required includes&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
#include &amp;lt;amxmodx&amp;gt;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Global Variables ===&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new g_Menu;	// Main Menu handler&lt;br /&gt;
new g_Votes[3];	// Store Yes votes at 1, No at 2&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In here we created 2 global var's. One to hold our menu handle, and the other to store our menu votes. The 'Yes' votes will be stored in g_Votes[1] and the 'No' votes will be stored in g_Votes[2].&lt;br /&gt;
&lt;br /&gt;
=== Registering Plugin and Menu ===&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
public plugin_init()&lt;br /&gt;
{&lt;br /&gt;
	// Register Our Plugin&lt;br /&gt;
	register_plugin(&amp;quot;Vote Menu&amp;quot;,&amp;quot;1.0&amp;quot;,&amp;quot;Freecode&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	// Register our Change Level vote menu&lt;br /&gt;
	g_Menu = menu_create(&amp;quot;Change Level?&amp;quot;,&amp;quot;menu_handle&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	register_clcmd(&amp;quot;amx_startvote&amp;quot;,&amp;quot;startvote&amp;quot;,ADMIN_CFG,&amp;quot;Gaben&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	// Now we need to build our menu&lt;br /&gt;
	build_menu();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets break this down. &lt;br /&gt;
&lt;br /&gt;
*Registers our plugin&lt;br /&gt;
&amp;lt;pawn&amp;gt;register_plugin(&amp;quot;Vote Menu&amp;quot;,&amp;quot;1.0&amp;quot;,&amp;quot;Freecode&amp;quot;);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*g_Menu - Our menu handle. It will be set after menu_create gets called.&lt;br /&gt;
&amp;lt;pawn&amp;gt;g_Menu = menu_create(&amp;quot;Change Level?&amp;quot;,&amp;quot;menu_handle&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//menu_create ( title[], handler[], ml=0 )&lt;br /&gt;
//title[] - Menu title&lt;br /&gt;
//handler[] - This is a function which will get called once someone presses a key on your menu.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We made this client command so we can start our vote.&lt;br /&gt;
&amp;lt;pawn&amp;gt;register_clcmd(&amp;quot;amx_startvote&amp;quot;,&amp;quot;startvote&amp;quot;,ADMIN_CFG,&amp;quot;Gaben&amp;quot;);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is a function call. build_menu() function will construct our vote menu.&lt;br /&gt;
&amp;lt;pawn&amp;gt;build_menu();&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructing Menu ===&lt;br /&gt;
Constructing the menu is just adding needed items to your menu. Before we go ahead with adding items we must look at menu_additem native.&lt;br /&gt;
&amp;lt;pawn&amp;gt;menu_additem ( menu, const name[], const command[], paccess=0, callback=-1 )&amp;lt;/pawn&amp;gt;&lt;br /&gt;
* menu - menu handle. This tells menu_additem the menu to which we are adding our item.&lt;br /&gt;
* const name[] - the item name. This is what gets displayed into the menu.&lt;br /&gt;
* const command[] - item info.&lt;br /&gt;
&lt;br /&gt;
Now lets get into constructing our menu. As said, this is a simple vote for a Change of Level. So we will only need 2 items. A &amp;quot;Yes&amp;quot; and a &amp;quot;No&amp;quot;.&lt;br /&gt;
&amp;lt;pawn&amp;gt;build_menu()&lt;br /&gt;
{&lt;br /&gt;
	menu_additem(g_Menu, &amp;quot;Yes&amp;quot;, &amp;quot;1&amp;quot;);&lt;br /&gt;
	menu_additem(g_Menu, &amp;quot;No&amp;quot;, &amp;quot;2&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	menu_setprop(g_Menu, MPROP_PERPAGE, 0);&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;Notes&amp;lt;/tt&amp;gt;&lt;br /&gt;
** As you can see i set the const command[] to numbers. This is for us to identify the item easier.&lt;br /&gt;
** I have also added menu_setprop. This sets our menu to have no pages. For additional properties look int amxconst.inc&lt;br /&gt;
&lt;br /&gt;
=== Displaying the Vote Menu ===&lt;br /&gt;
To display our menu we must simply use menu_display.&lt;br /&gt;
&amp;lt;pawn&amp;gt;menu_display ( id, menu, page )&amp;lt;/pawn&amp;gt;&lt;br /&gt;
* id - id of the user your displaying menu to.&lt;br /&gt;
* menu - which menu are you showing the user.&lt;br /&gt;
* page - what page (of the menu) to start on. Page of the menu starts at 0.&lt;br /&gt;
&lt;br /&gt;
Ok lets proceed to our code.&lt;br /&gt;
&amp;lt;pawn&amp;gt;public startvote(id)&lt;br /&gt;
{&lt;br /&gt;
	for(new i = 0; i &amp;lt; 33; i  )&lt;br /&gt;
	{&lt;br /&gt;
		if( is_user_alive(i) )&lt;br /&gt;
		{&lt;br /&gt;
			menu_display(i, g_Menu, 0);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return PLUGIN_HANDLED;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;Notes:&amp;lt;/tt&amp;gt;&lt;br /&gt;
** The for loop is used to cycle through players and display the menu to players that are alive.&lt;br /&gt;
&lt;br /&gt;
=== Handling Menu Choices ===&lt;br /&gt;
Last step is actualy handling the menu choices. This happens through the menu handler function. It will get called once someone chooses an item off the menu. There are &amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt; variables that are passed to the function.&lt;br /&gt;
* id - the users id&lt;br /&gt;
* menu - the menu user had open&lt;br /&gt;
* item - and the item user chose&lt;br /&gt;
&lt;br /&gt;
Now there are a few of special items like the Exit item.&lt;br /&gt;
&amp;lt;pawn&amp;gt;#define MENU_EXIT	-3&lt;br /&gt;
#define	MENU_BACK	-2&lt;br /&gt;
#define MENU_MORE	-1&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So we must check at first if the item chosen was not one of the special ones.&lt;br /&gt;
&amp;lt;pawn&amp;gt;if( item &amp;lt; 0 ) return PLUGIN_CONTINUE;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we must retrieve the item information. What we are looking for is the number we gave the item (Yes = 1, No = 2). And to do this we use menu_item_getinfo.&lt;br /&gt;
&amp;lt;pawn&amp;gt;menu_item_getinfo ( menu, item,&lt;/div&gt;</summary>
		<author><name>LbrGfn</name></author>
		
	</entry>
</feed>