AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Disable items in the menu (https://forums.alliedmods.net/showthread.php?t=98762)

Alucard^ 07-29-2009 00:33

Disable items in the menu
 
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?

IneedHelp 07-29-2009 00:45

Re: Disable items in the menu
 
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


fysiks 07-29-2009 02:10

Re: Disable items in the menu
 
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.

jim_yang 07-29-2009 03:42

Re: Disable items in the menu
 
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

zwfgdlc 07-29-2009 03:49

Re: Disable items in the menu
 
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;



fysiks 07-29-2009 03:58

Re: Disable items in the menu
 
Quote:

Originally Posted by jim_yang (Post 884620)
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.

Alucard^ 07-29-2009 18:47

Re: Disable items in the menu
 
@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

Exolent[jNr] 07-29-2009 18:51

Re: Disable items in the menu
 
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



Alucard^ 07-30-2009 13:34

Re: Disable items in the menu
 
@Exolent

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

Thx to much and thx to all.


All times are GMT -4. The time now is 18:29.

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