Raised This Month: $51 Target: $400
 12% 

Disable items in the menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-29-2009 , 00:33   Disable items in the menu
Reply With Quote #1

Hi, i want to know the better way to block options in the menu... this is my way:

PHP Code:
#include <amxmodx>

#define PLUGIN    "Test Menu"
#define AUTHOR    "Alucard"
#define VERSION    "1.0"

new p_test

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""TestMenu")
    
    
p_test register_cvar("menu_test""0")
}

public 
TestMenu(id)
{
    new 
Menu menu_create("\yTest Menu""test_show")
    
    
menu_additem(Menu"\wTest 1""1"0)
    
menu_additem(Menu"\wTest 2""2"0)
    
    if(
get_pcvar_num(p_test) )
        
menu_additem(Menu"\dTest 3""3", -1)
    else
        
menu_additem(Menu"\wTest 3""3"0)
    
    
menu_setprop(Menu,MPROP_EXITNAME,"Salir")
    
menu_setprop(MenuMPROP_EXITMEXIT_ALL)
    
    
menu_display(idMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
test_show(idMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6]
    new 
iAccess
    
new iCallback
    
new iName[64]
    
    
menu_item_getinfo(MenuitemiAccessiData5iName63iCallback)
    
    switch(
str_to_num(iData))
    {
        case 
1:
        {
            
client_print(idprint_chat"test 1")
        }
        case 
2:
        {
            
client_print(idprint_chat"test 2")
        }
        case 
3:
        {
            if(
get_pcvar_num(p_test) )
                
menu_display(idMenu0)
            else
                
client_print(idprint_chat"test 3")
        }
    }
    return 
PLUGIN_HANDLED

is there another better way?
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
IneedHelp
Veteran Member
Join Date: Mar 2007
Location: Argentina
Old 07-29-2009 , 00:45   Re: Disable items in the menu
Reply With Quote #2

PHP Code:
    if(get_pcvar_num(p_test) )
        
menu_additem(Menu"\dTest 3""3", -1)
    else
        
menu_additem(Menu"\wTest 3""3"0
-->

PHP Code:
new item[32]
formatex(itemsizeof(item)-1"%sTest 3"get_pcvar_num(p_test) ? "\w" "\d")
menu_additem(menuitem"3"0
__________________
IneedHelp is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-29-2009 , 02:10   Re: Disable items in the menu
Reply With Quote #3

The bad thing about using menu_additem() is that it registers the key and therefore the menu will call the handler when that key is pressed.

So, my solution to use menu_addtext(menu,"\d3. Text Here",1) should theoretically work but it seems that the "new menus" system is flawed when using menu_addtext(). So, unfortunately this will not work.

Using the "old" menu system might be best in this situation.

I have another idea that might "work." brb

UPDATE:

Ok, so I think I found the best work-around:

PHP Code:
public TestMenu(id)
{
    new 
Menu menu_create("\yTest Menu""test_show")
    
    
// g_bool = get_pcvar_num(p_test)
    
    
menu_additem(Menu"\wTest 1""1"0)
    
menu_additem(Menu"\wTest 2""2"0)
    if( 
g_bool )
    {
        
menu_additem(Menu"\dTest 3""99")
    }
    else
    {
        
menu_additem(Menu"\wTest 3""3"0)
    }
    
menu_additem(Menu"\wTest 4""4"0)
    
menu_additem(Menu"\wTest 5""5"0)
    
menu_additem(Menu"\wTest 6""6"0)
    
menu_additem(Menu"\wTest 7""7"0)
    
menu_additem(Menu"\wTest 8""8"0)
    
menu_additem(Menu"\wTest 9""9"0)
    
menu_additem(Menu"\wTest 10""10"0)

    
menu_setprop(Menu,MPROP_EXITNAME,"Salir")
    
menu_setprop(MenuMPROP_EXITMEXIT_ALL)
    
    
menu_display(idMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
test_show(idMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
szData[6]
    new 
iAccess
    
new iCallback
    
new szName[64]
    
    
menu_item_getinfo(MenuitemiAccessszData5szName63iCallback)
    
    new 
iData str_to_num(szData)
    
    switch(
iData)
    {
        case 
1..10:
        {
            
// Client selected valid item.
            
client_print(idprint_chat"test %d"iData)
        }
        case 
99:
        {
            
// "id" selected disabled item.
            
TestMenu(id// Re-display the menu to emulate "not being able to select that option."  Unfortunately will only work well on page 0.
            
        
}
    }
    
    
menu_destroy(Menu)
    return 
PLUGIN_HANDLED

Remember to destroy the menu at the end of the function. Also, the "i" prefix if for integers. Use "sz" for strings, I have changed them above accordingly, take a look.
__________________

Last edited by fysiks; 07-29-2009 at 02:37.
fysiks is online now
jim_yang
Veteran Member
Join Date: Aug 2006
Old 07-29-2009 , 03:42   Re: Disable items in the menu
Reply With Quote #4

The proper way it to use menu_makecallback to set a callback, then add this callback in menu_additem, then return ITEM_ENABLE or ITEM_DISABLE in the callback function
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
zwfgdlc
Senior Member
Join Date: May 2006
Old 07-29-2009 , 03:49   Re: Disable items in the menu
Reply With Quote #5

create a callback function for menu.

like this,not tested.
PHP Code:
#include <amxmodx>

#define PLUGIN    "Test Menu"
#define AUTHOR    "Alucard"
#define VERSION    "1.0"

new p_test
new MenuCallback;
new 
menu;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""TestMenu")
    
    
p_test register_cvar("menu_test""0")
    
    
Menu menu_create("\yTest Menu""test_show")
    
MenuCallback menu_makecallback("menu_callback");
    
    
menu_additem(Menu"\wTest 1""1"0,MenuCallback)
    
menu_additem(Menu"\wTest 2""2"0,MenuCallback)
    
menu_additem(Menu"\dTest 3""3", -1,MenuCallback)
    
menu_setprop(Menu,MPROP_EXITNAME,"Salir")
    
menu_setprop(MenuMPROP_EXITMEXIT_ALL)
}

public 
TestMenu(id)
{
    
menu_display(idMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
test_show(idMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6]
    new 
iAccess
    
new iCallback
    
new iName[64]
    
    
menu_item_getinfo(MenuitemiAccessiData5iName63iCallback)
    
    switch(
str_to_num(iData))
    {
        case 
1:
        {
            
client_print(idprint_chat"test 1")
        }
        case 
2:
        {
            
client_print(idprint_chat"test 2")
        }
        case 
3:
        {
            
client_print(idprint_chat"test 3")
        }
    }
    return 
PLUGIN_HANDLED
}  


public 
menu_callback(idMenuitem)
{
    if(
item == 2)
    return 
get_pcvar_num(p_test) ? ITEM_DISABLED ITEM_ENABLED;

zwfgdlc is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-29-2009 , 03:58   Re: Disable items in the menu
Reply With Quote #6

Quote:
Originally Posted by jim_yang View Post
The proper way it to use menu_makecallback to set a callback, then add this callback in menu_additem, then return ITEM_ENABLE or ITEM_DISABLE in the callback function
I figured there was a better way. I don't know much about the callback functionality so I made a work-around.
__________________
fysiks is online now
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-29-2009 , 18:47   Re: Disable items in the menu
Reply With Quote #7

@fysiks

Thx to much...

And i have a question:

PHP Code:
    if( g_bool 
    { 
        
menu_additem(Menu"\dTest 3""99"
    } 
    else 
    { 
        
menu_additem(Menu"\wTest 3""3"0
    } 
PHP Code:
    if( get_pcvar_nump_test 
    { 
        
menu_additem(Menu"\dTest 3""99"
    } 
    else 
    { 
        
menu_additem(Menu"\wTest 3""3"0
    } 
isnt the same?

PHP Code:
        case 99
        { 
            
// "id" selected disabled item. 
            
TestMenu(id// Re-display the menu to emulate "not being able to select that option."  Unfortunately will only work well on page 0. 
             
        

maybe the solution to use another page is "menu_display"

-->

PHP Code:
        case 99
        { 
            
// "id" selected disabled item. 
            
menu_display(idMenu0// 0 = Page 1 | 1 = page 2 ...
             
        

@ zwfgdlc

Thx to much...

And...

PHP Code:
public menu_callback(idMenuitem

    if(
item == 2)
    return 
get_pcvar_num(p_test) ? ITEM_DISABLED ITEM_ENABLED

item == 2 or 3?

cuz...

PHP Code:
    menu_additem(Menu"\wTest 1""1"0,MenuCallback
    
menu_additem(Menu"\wTest 2""2"0,MenuCallback
    
menu_additem(Menu"\dTest 3""3", -1,MenuCallback
And...

PHP Code:
    menu_additem(Menu"\dTest 3""3", -1,MenuCallback
You can explain me what do the "-1"?

thx to all
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-29-2009 , 18:51   Re: Disable items in the menu
Reply With Quote #8

PHP Code:
#include <amxmodx>

#define PLUGIN    "Test Menu"
#define AUTHOR    "Alucard"
#define VERSION    "1.0"

new p_test

new g_hMenu;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""TestMenu")
    
    
p_test register_cvar("menu_test""0")
    
    
g_hMenu menu_create("Test Menu""test_show")
    
    
menu_additem(g_hMenu"Test 1""1")
    
menu_additem(g_hMenu"Test 2""2")
    
menu_additem(g_hMenu"Test 3""3"_menu_makecallback("CallbackTest"))
    
    
menu_setprop(Menu,MPROP_EXITNAME,"Salir")
}

public 
TestMenu(id)
{
    
menu_display(idg_hMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
CallbackTest(idMenuitem)
{
    return 
get_pcvar_nump_test ) ? ITEM_ENABLED ITEM_DISABLED;
}

public 
test_show(idMenuitem)
{
    if(
item == MENU_EXIT)
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6]
    new 
iAccess
    
new iCallback
    
new iName[64]
    
    
menu_item_getinfo(MenuitemiAccessiData5iName63iCallback)
    
    switch(
str_to_num(iData))
    {
        case 
1:
        {
            
client_print(idprint_chat"test 1")
        }
        case 
2:
        {
            
client_print(idprint_chat"test 2")
        }
        case 
3:
        {
            
client_print(idprint_chat"test 3")
        }
    }
    return 
PLUGIN_HANDLED

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-30-2009 , 13:34   Re: Disable items in the menu
Reply With Quote #9

@Exolent

Wow, work perfect and i understand at all...

Thx to much and thx to all.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Reply



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 21:00.


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