Raised This Month: $32 Target: $400
 8% 

[HELP] Something with menu cases.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ShLuMieL
Senior Member
Join Date: Jul 2010
Old 02-02-2014 , 18:00   [HELP] Something with menu cases.
Reply With Quote #1

Hello all.
I have a question if it possible

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "AUTHOR"

new bool:gItem1[33], gItem2[33], gItem3[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Add your code here...
    
register_clcmd("nightvision""Menu");
}

public 
Menu(id)
{
    new 
szItem[256];
    
    
formatex(szItemcharsmax(szItem), "\w[ \rItem's \w] \yMain Menu:")
    new 
menu menu_create(szItem"Menu_Handler"
    
    if(!
gItem1[id])
        
menu_additem(menu"Item1"""0);
    if(!
gItem2[id])
        
menu_additem(menu"Item2"""0);
    if(!
gItem3[id])
        
menu_additem(menu"Item3"""0);
    
menu_additem(menu"Item4"""0);    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
gItem1[id] = false;
        
gItem2[id] = false;
        
gItem3[id] = false;
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
item)
    {
        case 
0: {
            if(!
gItem1[id])
                
gItem1[id] = true;
        }

        case 
1: {
            if(!
gItem1[id])
                
gItem2[id] = true;
        }
            
        case 
2: {
            if(!
gItem2[id])
                
gItem3[id] = true;
        }
    }
    
    
Menu(id)
    return 
PLUGIN_HANDLED;

My question its if can I name the CASES or something cuse I want if I pick Item 1 its will wont show me this Item in the menu and the case of this item wont be.
its hard to explain that so sorry if you didn't understand that.

Thanks'
ShLuMieL is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-02-2014 , 18:52   Re: [HELP] Something with menu cases.
Reply With Quote #2

Yes, you can do this and is quite simple. The code below allows you to add/remove items how ever you would like without having to change the menu handler at all. The menu handler is solely based on the third argument of menu_additem() so that is the only thing that needs to remain consistent with the menu handler switch statement.

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "AUTHOR"

new bool:gItem1[33], gItem2[33], gItem3[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("nightvision""Menu");
}

public 
Menu(id)
{
    new 
szItem[256];
    
    
formatex(szItemcharsmax(szItem), "\w[ \rItem's \w] \yMain Menu:")
    new 
menu menu_create(szItem"Menu_Handler"
    
    if(!
gItem1[id])
        
menu_additem(menu"Item1""1"0);
    if(!
gItem2[id])
        
menu_additem(menu"Item2""2"0);
    if(!
gItem3[id])
        
menu_additem(menu"Item3""3"0);
    
menu_additem(menu"Item4""4"0);    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return
    }
    
    new 
szInfo[8], iAccessiCallback;  // iAccess and iCallback are required but unused
    
menu_item_getinfomenuitemiAccessszInfocharsmax(szInfo), ""0iCallback);
    
    new 
iChosenItem str_to_num(szInfo);
    
    switch(
iChosenItem)
    {
        case 
1:
        {
            
// Item1 has been chosen
        
}
        case 
2:
        {
            
// Item2 has been chosen
        
}
        case 
3:
        {
            
// Item3 has been chosen
        
}
    }
    
    
Menu(id);
    
    
menu_destroy(menu);  // You must destroy the menu here also (in your case).
    
return

__________________
fysiks is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 02-03-2014 , 03:52   Re: [HELP] Something with menu cases.
Reply With Quote #3

In this case there's no need to send any info with the the menu items - you can get the menu item index straight from item ( + 1 ) and not need to retrieve unnecessary info.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-03-2014 , 11:24   Re: [HELP] Something with menu cases.
Reply With Quote #4

Quote:
Originally Posted by hornet View Post
In this case there's no need to send any info with the the menu items - you can get the menu item index straight from item ( + 1 ) and not need to retrieve unnecessary info.
No, that won't work (he already tried it that way) if he doesn't always add all the items because the 'item' variable will not remain consistent to the content.

E.g. If he doesn't add Item1 to the menu, Item2 becomes the first item in the menu. When Item2 is chosen, 'item' will be 0 which will execute code for Item1.
__________________

Last edited by fysiks; 02-03-2014 at 11:28.
fysiks is offline
ShLuMieL
Senior Member
Join Date: Jul 2010
Old 02-03-2014 , 14:41   Re: [HELP] Something with menu cases.
Reply With Quote #5

Thank's fysiks
ShLuMieL is offline
Reply


Thread Tools
Display Modes

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 14:32.


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