Raised This Month: $ Target: $400
 0% 

New Menus and Old Menus


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-09-2010 , 21:25   Re: New Menus and Old Menus
Reply With Quote #9

Code:
#include < amxmodx > #define MAX_PLAYERS 32 new bool:g_bToggle[ MAX_PLAYERS + 1 ]; new g_hMenu; public plugin_init( ) {     register_plugin( "Callback Test", "0.0.1", "Exolent" );         register_clcmd( "say /toggle", "CmdToggle" );         new hCallback = menu_makecallback( "CallbackToggle" );     g_hMenu = menu_create( "Toggle Menu", "MenuToggle" );         menu_additem( g_hMenu, "On", "1", _, hCallback );     menu_additem( g_hMenu, "Off", "0", _, hCallback ); } public client_disconnect( iPlayer ) {     g_bToggle[ iPlayer ] = false; } public CmdToggle( iPlayer ) {     menu_display( iPlayer, g_hMenu ); } public CallbackToggle( iPlayer, hMenu, iItem ) {     new iAccess, szInfo[ 2 ], hCallback;     menu_item_getinfo( hMenu, iItem, iAccess, szInfo, charsmax( szInfo ), _, _, hCallback );         switch( szInfo[ 0 ] )     {         case '1':         {             if( g_bToggle[ iPlayer ] )             {                 // toggle is already on, so disable the "On" item                 return ITEM_DISABLED;             }         }         case '0':         {             if( !g_bToggle[ iPlayer ] )             {                 // toggle is already off, so disable the "Off" item                 return ITEM_DISABLED;             }         }     }         // enable the items if they are allowed     return ITEM_ENABLED; } public MenuToggle( iPlayer, hMenu, iItem ) {     if( iItem == MENU_EXIT )     {         return;     }         new iAccess, szInfo[ 2 ], hCallback;     menu_item_getinfo( hMenu, iItem, iAccess, szInfo, charsmax( szInfo ), _, _, hCallback );         switch( szInfo[ 0 ] )     {         case '1':         {             // this will only be called if callback returns ITEM_ENABLED             g_bToggle[ iPlayer ] = true;         }         case '0':         {             // this will only be called if callback returns ITEM_ENABLED             g_bToggle[ iPlayer ] = false;         }     }         menu_display( iPlayer, g_hMenu ); }

If the callback returns ITEM_DISABLED, the item and number will be grayed out and nothing will happen if the key is pressed.

Of course, this could be reduced to smaller code, but it was just an example.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
 



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 08:40.


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