Quote:
Originally Posted by uxMal
Make a callback for the menuitem and return ITEM_DISABLED in the callback...
|
Best answer of the thread.
Example 1:
Code:
new g_hCallback;
public plugin_init( ) {
g_hCallback = menu_makecallback( "MenuCallback" );
}
ShowMenu( client ) {
new hMenu = menu_create( "Some Menu", "MenuHandler" );
menu_additem( hMenu, "You can press me", "1" );
menu_additem( hMenu, "You can't press me", "2", _, g_hCallback );
menu_additem( hMenu, "You can press me, too", "3" );
menu_display( client, hMenu );
}
public MenuCallback( client, hMenu, iItem ) {
// iItem starts at 0
if( iItem == 1 ) {
return ITEM_DISABLED;
}
return ITEM_ENABLED;
}
public MenuHandler( client, hMenu, iItem ) {
menu_destroy( hMenu );
if( iItem == MENU_EXIT ) {
return;
}
switch( iItem ) {
case 0: {
client_print( client, print_chat, "You chose option #1" );
}
case 2: {
client_print( client, print_chat, "You chose option #3" );
}
}
ShowMenu( client );
}
Example 2:
Code:
new g_hMenu;
public plugin_init( ) {
new hCallback = menu_makecallback( "MenuCallback" );
g_hMenu = menu_create( "Some Menu", "MenuHandler" );
menu_additem( g_hMenu, "You can press me", "1" );
menu_additem( g_hMenu, "You can't press me", "2", _, hCallback );
menu_additem( g_hMenu, "You can press me, too", "3" );
}
ShowMenu( client ) {
menu_display( client, g_hMenu );
}
public MenuCallback( client, hMenu, iItem ) {
// iItem starts at 0
if( iItem == 1 ) {
return ITEM_DISABLED;
}
return ITEM_ENABLED;
}
public MenuHandler( client, hMenu, iItem ) {
if( iItem == MENU_EXIT ) {
return;
}
switch( iItem ) {
case 0: {
client_print( client, print_chat, "You chose option #1" );
}
case 2: {
client_print( client, print_chat, "You chose option #3" );
}
}
ShowMenu( client );
}
__________________