Difference between revisions of "Using New Menu System"
(→Menu Tutorial) |
|||
Line 5: | Line 5: | ||
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. | 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. | ||
+ | === Includes === | ||
+ | As always we will start out by adding the required includes | ||
<pawn> | <pawn> | ||
#include <amxmodx> | #include <amxmodx> | ||
+ | </pawn> | ||
+ | === Global Variables === | ||
+ | <pawn> | ||
new g_Menu; // Main Menu handler | new g_Menu; // Main Menu handler | ||
new g_Votes[3]; // Store Yes votes at 1, No at 2 | new g_Votes[3]; // Store Yes votes at 1, No at 2 | ||
+ | </pawn> | ||
+ | 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]. | ||
+ | === Registering Plugin and Menu === | ||
+ | <pawn> | ||
public plugin_init() | public plugin_init() | ||
{ | { | ||
// Register Our Plugin | // Register Our Plugin | ||
− | + | register_plugin("Vote Menu","1.0","Freecode"); | |
// Register our Change Level vote menu | // Register our Change Level vote menu | ||
Line 25: | Line 34: | ||
build_menu(); | build_menu(); | ||
} | } | ||
+ | </pawn> | ||
+ | Lets break this down. | ||
public startvote(id) | public startvote(id) | ||
{ | { |
Revision as of 08:27, 2 April 2006
Contents
Introduction
Write some intro here
Menu Tutorial
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.
Includes
As always we will start out by adding the required includes
#include <amxmodx>
Global Variables
new g_Menu; // Main Menu handler new g_Votes[3]; // Store Yes votes at 1, No at 2
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].
Registering Plugin and Menu
public plugin_init() { // Register Our Plugin register_plugin("Vote Menu","1.0","Freecode"); // Register our Change Level vote menu g_Menu = menu_create("Change Level?","menu_handle"); register_clcmd("amx_startvote","startvote",ADMIN_CFG,"Gaben"); // Now we need to build our menu build_menu(); }
Lets break this down. public startvote(id) { for(new i = 0; i < 33; i++) { if( is_user_alive(i) ) { menu_display(i, g_Menu, 0); } }
return PLUGIN_HANDLED; }
build_menu() { menu_additem(g_Menu, "Yes", "1"); menu_additem(g_Menu, "No", "2");
menu_setprop(g_Menu, MPROP_PERPAGE, 0); }
public menu_handle(id, menu, item) { if( item < 0 ) return PLUGIN_CONTINUE;
// Get item info new cmd[6], iName[64]; new access, callback;
menu_item_getinfo(menu, item, access, cmd,5, iName, 63, callback);
new iChoice = str_to_num(cmd);
g_Votes[iChoice]++;
return PLUGIN_HANDLED; } </pawn>