AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu bug (https://forums.alliedmods.net/showthread.php?t=107089)

uxMal 10-22-2009 14:55

Menu bug
 
Hey i have problems with my dynamic menu...


It works fine if i have so many items that i have more than 1 page but if i have only 3 items,
i add blanks with menu_addblank(menu,1); to have a fixed option on place 7.

But the value of place 7 is then -3 (MENU_EXIT)

It's only when theres only one page...

Exolent[jNr] 10-22-2009 14:55

Re: Menu bug
 
Show us your code.

uxMal 10-22-2009 14:59

Re: Menu bug
 
Sorry forgot the code Oo

//Not so clean, i know, it's quite old code
PHP Code:

new count=0;
    for(new 
0<= MAXPLAYERSi++)
    {
        if(
count == 6)
        {
            
menu_addblank(menu,0);
            new 
choice[32],msg[4],info[5];
            
formatex(info,4,"133%d",type)
            
formatex(msg,3,"M_%d",type);
            
formatex(choice,31,"\y%L",LANG_PLAYER,msg);
            if(
types[id] == 0types[id] = 1;
            
menu_additem(menu,choice,info,0,-1);
            
count 0;
        }
        if(
is_user_connected(i) && !(get_user_flags(i) & ADMIN_NOBLOCK_LVL) && id != i)
        {
            new 
buffer[37],ind[4];
            
get_user_name(i,buffer,30);
            switch((
usr states[i] : usrstate[id][i])) 
            {
                case 
1:
                {
                    
format(buffer,36,"%s   \rV",buffer);
                }
                case 
2:
                {
                    
format(buffer,36,"%s   \rC",buffer);
                }
                case 
3:
                {
                    
format(buffer,36,"%s   \rV C",buffer);
                }
                
            }
            
formatex(ind,3,"%d",i);
            
menu_additem(menu,buffer,ind,0,-1);
            
count++;
        }
        
        
        
    }
    if(
count != 0
    {
        for(new 
count;6;i++)
        {
            
menu_addblank(menu,1);    
        }
        
        
menu_addblank(menu,0);
        new 
choice[32],msg[4],info[5];
        
formatex(info,4,"133%d",type)
        
formatex(msg,3,"M_%d",type);
        
formatex(choice,31,"\y%L",LANG_PLAYER,msg);
        if(
types[id] == 0types[id] = 1;
        
menu_additem(menu,choice,info,0,-1);
        
count 0;
    }
    
    
menu_display(id,menu,page);


Handler code is irrelevant because the item id is -3 without modifing anything in the handler


Btw its working fine if i'm not adding the blanks

Hawk552 10-22-2009 15:14

Re: Menu bug
 
The reason is that you're using menu_addblank() with slot set to 0. This causes it to not increase the number of total slots, so 7 is beyond the range of the menu. If you have 5 items and 2 blanks (with slot=0), then your total range is 5.

Also, your range starts at 0. So if you have 5 items, keys 0-4 are valid but 5 is not. It is similar to arrays.

uxMal 10-22-2009 15:30

Re: Menu bug
 
Yes, i think understand your point but i don't think its my problem because if i'm not using menu_addblank(slot=0), it is the same...

To fill the menu up im using addblank with slot=1 so at number 7 in the menu is my fixed menu item (not id 7)

Sorry if i misunterstood smth

Hawk552 10-22-2009 17:56

Re: Menu bug
 
PHP Code:

    if(count == 6)
        {
            
menu_addblank(menu,0); 

PHP Code:

    if(count != 0
    {
        for(new 
count;6;i++)
        {
            
menu_addblank(menu,1);    
        }
        
        
menu_addblank(menu,0); 

?

uxMal 10-22-2009 18:07

Re: Menu bug
 
I uncommented the statements for testing
cause the blanks with no slot are just for the look

Hawk552 10-22-2009 18:08

Re: Menu bug
 
I want to help you, but your code doesn't make any sense and it's difficult to follow. It would also help if you explained what exactly you're trying to do.

uxMal 10-22-2009 18:32

Re: Menu bug
 
So heres the full code of the function, i thought it is not needed but here
PHP Code:

public adminmenu(id,type,page
{
    if(
get_playersnum() <= 1)
    {
        
client_printc(id,id,"\g[Mute++] \o%L",LANG_PLAYER,"NOT_ENOUGH_PLAYER");
        return;
    }
    new 
usr;
    if((
get_user_flags(id) & ADMIN_MUTE_LVL) && !gMode[id]) usr 1;
    new 
menu menu_create((usr "\rAdmin Mute Menu" "\rMute Menu"), "mute_handler");
    
    
    new 
count=0;
    for(new 
0<= MAXPLAYERSi++)
    {
        if(
count == 6)
        {
            
menu_addblank(menu,0);
            new 
choice[32],msg[4],info[5];
            
formatex(info,4,"133%d",type)
            
formatex(msg,3,"M_%d",type);
            
formatex(choice,31,"\y%L",LANG_PLAYER,msg);
            if(
types[id] == 0types[id] = 1;
            
menu_additem(menu,choice,info,0,-1);
            
count 0;
        }
        if(
is_user_connected(i) && !(get_user_flags(i) & ADMIN_NOBLOCK_LVL) && id != i)
        {
            new 
buffer[37],ind[4];
            
get_user_name(i,buffer,30);
            switch((
usr states[i] : usrstate[id][i])) 
            {
                case 
1:
                {
                    
format(buffer,36,"%s   \rV",buffer);
                }
                case 
2:
                {
                    
format(buffer,36,"%s   \rC",buffer);
                }
                case 
3:
                {
                    
format(buffer,36,"%s   \rV C",buffer);
                }
                
            }
            
formatex(ind,3,"%d",i);
            
menu_additem(menu,buffer,ind,0,-1);
            
count++;
        }
        
        
        
    }
    if(
count != 0
    {
        for(new 
count;6;i++)
        {
            
menu_addblank(menu,1);    
        }
        
        
menu_addblank(menu,0);
        new 
choice[32],msg[4],info[5];
        
formatex(info,4,"133%d",type)
        
formatex(msg,3,"M_%d",type);
        
formatex(choice,31,"\y%L",LANG_PLAYER,msg);
        if(
types[id] == 0types[id] = 1;
        
menu_additem(menu,choice,info,0,-1);
        
count 0;
    }
    
    
menu_display(id,menu,page);


This function does the following it creates a menu with all players in it.

on one page slot 1-6 are players slot 7 is mute voice/chat and the other 3 are forward, back and exit

It is for a mute plugin, if you select slot 7 it switches from mute chat to mute voice and vice versa.

The count variable saves the number of player currently on one page because the structure is as said above
1-6 players
7 mute chat / mute voice
blank without slot
8-10 back, forward, exit

I hope this helped you unterstand the code better

fysiks 10-22-2009 19:21

Re: Menu bug
 
So, it's like the banmenu that comes with AMX Mod X. It might be easier to do with original style menu.


All times are GMT -4. The time now is 17:34.

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