AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   little menu problem (https://forums.alliedmods.net/showthread.php?t=241157)

wAyz 05-29-2014 06:45

little menu problem
 
1 Attachment(s)
Hi,

when I toggle the option on my 2nd menu page I want to stay at that page but I dont
really know to do that.

Code:

...
                case 8: {
                        cmdBlockSounds(id);
                        cmdShowSettingsMenu(id);
                }
...

Instead I'm going to the first one which is just logic, but any idea how to stay at the 2nd?
I'm using new menu system.

jimaway 05-29-2014 06:52

Re: little menu problem
 
Code:

/**
 * Displays a menu to one client.  This should never be called from a handler
 * when the item is less than 0 (i.e. calling this from a cancelled menu will
 * result in an error).
 *
 * @param id                        Client index.
 * @param menu                        Menu resource identifier.
 * @param page                        Page to start from (starting from 0).
 * @noreturn
 * @error                                Invalid menu resource or client index.
 */
native menu_display(id, menu, page=0);


wAyz 05-29-2014 06:54

Re: little menu problem
 
Quote:

Originally Posted by jimaway (Post 2143904)
Code:

/**
 * Displays a menu to one client.  This should never be called from a handler
 * when the item is less than 0 (i.e. calling this from a cancelled menu will
 * result in an error).
 *
 * @param id                        Client index.
 * @param menu                        Menu resource identifier.
 * @param page                        Page to start from (starting from 0).
 * @noreturn
 * @error                                Invalid menu resource or client index.
 */
native menu_display(id, menu, page=0);


I tried this:

Code:

...
                case 8: {
                        cmdBlockSounds(id);
                        menu_display(id, menu, 2)
                }
...

am I wrong with that? Doesn't work.

Flick3rR 05-29-2014 06:57

Re: little menu problem
 
Maybe, if this doesn't work, you should post a bit more of the code to see what exactly 'menu' is and which cases you switch, etc, etc...

wAyz 05-29-2014 06:58

Re: little menu problem
 
Code:

public cmdShowSettingsMenu(id) {
        if(!is_user_alive(id) || !is_user_localhost(id)) {
                return PLUGIN_HANDLED;
        }
       
        new sTemp[128];
        new menu = menu_create("\yKZ Demo Plugin: \wSettings", "handlerShowSettingsMenu") ;
       
        formatex(sTemp, charsmax(sTemp), "\wAuto heal 10'000 HP:%s", g_bHealsOnMap ? (get_pcvar_num(g_pcvarAutoheal) == 1 ? "\y ON" : "\r OFF") : "\d Couldn't find HP booster");
        menu_additem(menu, sTemp, "1");
       
        formatex(sTemp, charsmax(sTemp), "\wGod mode:%s", get_pcvar_num(g_pcvarGodmode) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "2");
       
        formatex(sTemp, charsmax(sTemp), "\wShow timer:%s", g_bShowTimer[id] ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "3");
       
        formatex(sTemp, charsmax(sTemp), "\wSave start angles:%s", get_pcvar_num(g_pcvarStartAngles) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "4");       
       
        formatex(sTemp, charsmax(sTemp), "\wSave cp angles:%s", get_pcvar_num(g_pcvarCPAngles) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "5");
       
        formatex(sTemp, charsmax(sTemp), "\wBlock join to CT:%s", get_pcvar_num(g_pcvarBlockCT) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "6");
       
        formatex(sTemp, charsmax(sTemp), "\wShow demo attempts:%s", get_pcvar_num(g_pcvarAttempt) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "7");
       
        formatex(sTemp, charsmax(sTemp), "\wBlock startround sounds:%s^n", get_pcvar_num(g_pcvarBlockSounds) == 1 ? "\y ON" : "\r OFF");
        menu_additem(menu, sTemp, "8");
       
        menu_display(id, menu, 0);
       
        return PLUGIN_HANDLED;
}





public handlerShowSettingsMenu(id, menu, item) {
        if(item == MENU_EXIT) {
                menu_destroy(menu);
               
                return PLUGIN_HANDLED;
        }
       
        new sData[6];
        new iAccess, iCallback;
       
        menu_item_getinfo(menu, item, iAccess, sData, charsmax(sData), _, _, iCallback);
       
        switch(str_to_num(sData)) {
                case 1: {
                        cmdAutoheal(id);
                        cmdShowSettingsMenu(id);
                }
                case 2: {
                        cmdGodmode(id);
                        cmdShowSettingsMenu(id);
                }
                case 3: {
                        cmdTimer(id);
                        cmdShowSettingsMenu(id);
                }
                case 4: {
                        cmdStartAngles(id);
                        cmdShowSettingsMenu(id);
                }
                case 5: {
                        cmdCPAngles(id);
                        cmdShowSettingsMenu(id);
                }
                case 6: {
                        cmdBlockCT(id);
                        cmdShowSettingsMenu(id);
                }
                case 7: {
                        cmdAttempt(id);
                        cmdShowSettingsMenu(id);
                }
                case 8: {
                        cmdBlockSounds(id);
                        cmdShowSettingsMenu(id);
                }
        }
       
        menu_destroy(menu);
       
        return PLUGIN_HANDLED;
}


jimaway 05-29-2014 07:04

Re: little menu problem
 
Page to start from (starting from 0).

Code:

menu_display(id, menu, 1)

wAyz 05-29-2014 07:07

Re: little menu problem
 
Quote:

Originally Posted by jimaway (Post 2143914)
Page to start from (starting from 0).

Code:

menu_display(id, menu, 1)

That seems to work better but the whole menu is closing after I toggle it more
than one time o0

jimaway 05-29-2014 07:12

Re: little menu problem
 
you are destroying the menu, and it isn't re-created

i suggest you create the menu into a global variable and change the ON/OFF text in menu callback. destroy the menu in plugin_end


All times are GMT -4. The time now is 09:37.

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