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

How to: Menu with 10+ Options in one page


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 03-13-2013 , 11:33   How to: Menu with 10+ Options in one page
Reply With Quote #1

Did you ever wonder how to make a menu with more then 10 options in one page , and you can select any of them without force players to bind keys?

We will create menu with 9 options and add more with addtext, then we will catch which slot the player has pressed and wait 0.2( Cvar ) seconds to press one more .
If he press second slot in this time it will execute (if first choose was 2 and second 1 ) - 21
Else the first chosen option will be executed in 0.2 seconds

Here is the code with comments ( hope i did well with them )

PHP Code:
#include <amxmodx>

new g_fButton33 // Here we will store the first slot pressed by the player
new g_sButton33 // Here we will store the second slot pressed by the player
new g_Task33 // Here we will store if there was a task when opening the menu

new Float:g_fTime33 // Here we will store the time when player pressed slot1

new g_pWaitFloat:WAIT

public plugin_init() 
{
    
register_plugin"How to make more options in one page""1.0""eMinEm" )
    
    
register_clcmd"say /menu""catch_buttons" // register command for opening the menu
    
    
g_pWait register_cvar"menu_waittime""0.2" 
    
// How much to wait for chosing options from the menu
    // Note : If u make it below 0.2 a lot of mistakes can happen when players use the menu
    //       If u make it above 0.4 there will be too much delay when using slot 1-9
    
    
WAIT get_pcvar_floatg_pWait // store the time to wait in global variable so we can use it for our checks
}

public 
client_putinserverid null_allid ); // Make sure the player has the right numbers stored

public catch_buttonsid )
{
    if( 
g_Taskid ] ) // if slot is pressed but there is no second in the given time execute the first chosen slot ( from 0 to 9 )
    
{
        if( 
g_fButtonid ] != set_buttonsidget_gametime( ) );
        else 
null_allid ); // make sure to null all checks so players can open the menu again
        
        
show_menuid0"^n" // Hide the menu after the item is executed or if item is exit
        
return PLUGIN_HANDLED
    
}
    new 
menu menu_create"Menu""catch_buttons_handler" // Create the menu
    
            /*    Maximum 383 symbols including menu title    */
    
        /*    First type of formatting the menu    */
// Doesnt really matter what you will put in the options , you just want to show players what will happen if they press "XX"

    /*
    menu_additem( menu, "Option1     \r10. \wOption 10     \r19. \wOption 19", "1", 0 );
    menu_additem( menu, "Option2     \r11. \wOption 11     \r20. \wOption 20", "2", 0 );
    menu_additem( menu, "Option3     \r12. \wOption 12     \r21. \wOption 21", "3", 0 );
    menu_additem( menu, "Option4     \r13. \wOption 13     \r22. \wOption 22", "4", 0 );
    menu_additem( menu, "Option5     \r14. \wOption 14     \r23. \wOption 23", "5", 0 );
    menu_additem( menu, "Option6     \r15. \wOption 15     \r24. \wOption 24", "6", 0 );
    menu_additem( menu, "Option7     \r16. \wOption 16", "7", 0 );
    menu_additem( menu, "Option8     \r17. \wOption 17", "8", 0 );
    menu_additem( menu, "Option9     \r18. \wOption 18", "9", 0 );
    */
    // If you want more options use addtext as in the example below
    
        /*    Second type of formatting the menu    */
        
    
menu_additemmenu"Option1""1" );
    
menu_additemmenu"Option1""2" );
    
menu_additemmenu"Option1""3" );
    
menu_additemmenu"Option1""4" );
    
menu_additemmenu"Option1""5" );
    
menu_additemmenu"Option1""6" );
    
menu_additemmenu"Option1""7" );
    
menu_additemmenu"Option1""8" );
    
menu_additemmenu"Option1""9" );
    
menu_addtextmenu"\r10. \wOption10");
    
menu_addtextmenu"\r11. \wOption11");
    
menu_addtextmenu"\r12. \wOption12");
    
menu_addtextmenu"\r13. \wOption13");
    
menu_addtextmenu"\r14. \wOption14");
    
menu_addtextmenu"\r15. \wOption15");
    
menu_addtextmenu"\r16. \wOption16");
    
menu_addtextmenu"\r17. \wOption17");
    
menu_addtextmenu"\r18. \wOption18");
    
menu_addtextmenu"\r19. \wOption19");
    
menu_addtextmenu"\r20. \wOption20");
    
menu_addtextmenu"\r21. \wOption21");
    
menu_addtextmenu"\r22. \wOption22");
    
menu_addtextmenu"\r23. \wOption23");
    
menu_addtextmenu"\r24. \wOption24");

    
menu_addblankmenu// Make space between the menu options and Exit
    
menu_additemmenu"Exit""0" ); // Add exit button to the menu
// If we don't add Exit on 0 slot and we don't add 0 slot in our menu, players whould not be able to select items with 0 in it ( like 10, 20.. )
    
    
menu_setpropmenuMPROP_PERPAGE); // No EXIT option in the menu
    
    
menu_displayidmenu); // Show the menu to the player
    
return PLUGIN_HANDLED
}

public 
catch_buttons_handleridmenuitem )
{
    new 
data], szName64 ]
    new 
accesscallback;
    
    
menu_item_getinfomenuitemaccessdata,charsmaxdata ), szName,charsmaxszName ), callback );
    
    new 
key str_to_numdata );
    new 
Float:iTime get_gametime( )
    
    if( 
task_existsid ) ) remove_taskid ); 
    
// If first slot is already chosen a task is waiting for the second , we want to remove it when we press the second slot
    
    
g_fButtonid ] < ? ( g_fButtonid ] = key ) : ( g_sButtonid ] = key ); // Check which button we want to store , first or second one
    
g_fTimeid ] = iTime // Set the time when the slot is pressed
    
set_buttonsidiTime )
    
    
menu_destroymenu )
    return 
PLUGIN_HANDLED
}

set_buttonsidFloat:iTime )
{
    if( 
g_sButtonid ] < // If no second slot pressed yet
    
{
        if( 
iTime g_fTimeid ] <= WAIT // Check if there is time to press second one
        
{
            
catch_buttonsid ); // Show him the menu to press the second one
            
g_Taskid ] = // We now know that there is a task set
            
set_taskWAIT"catch_buttons"id // Show the menu again
        
}
        else 
        {
            
exec_selectedidg_fButtonid ], -// If no second button pressed execute the first one
            
null_allid )
        }
    }
    else 
    {
        
exec_selectedidg_fButtonid ], g_sButtonid ] ) // If there is a second button pressed execute selection
        
null_allid )
    }
}

null_allid )
{
    
g_fButtonid ] = -// We want to use slot 0 too
    
g_sButtonid ] = -// Same as above
    
g_fTimeid ] = 0.0
    g_Task
id ] = 0
}

exec_selectedidfslotsslot )
{
    new 
szChoice], iChoice
    
    sslot 
formatexszChoicecharsmaxszChoice ), "%d"fslot ) : formatexszChoicecharsmaxszChoice ), "%d%d"fslotsslot );
    
// Check if we have second slot chosen , if yes format them both , if not format only the first one
    
    
iChoice str_to_numszChoice )
    
    
// Here is what will actually happen when player choose something from the menu
    
switch( iChoice )
    {
        case 
1client_printidprint_chat"Selected item : %d"iChoice );
        case 
2client_printidprint_chat"Selected item : %d"iChoice );
        case 
3client_printidprint_chat"Selected item : %d"iChoice );
        case 
4client_printidprint_chat"Selected item : %d"iChoice );
        case 
5client_printidprint_chat"Selected item : %d"iChoice );
        case 
6client_printidprint_chat"Selected item : %d"iChoice );
        case 
7client_printidprint_chat"Selected item : %d"iChoice );
        case 
8client_printidprint_chat"Selected item : %d"iChoice );
        case 
9client_printidprint_chat"Selected item : %d"iChoice );
        case 
10client_printidprint_chat"Selected item : %d"iChoice );
        case 
11client_printidprint_chat"Selected item : %d"iChoice );
        case 
12client_printidprint_chat"Selected item : %d"iChoice );
        case 
13client_printidprint_chat"Selected item : %d"iChoice );
        case 
14client_printidprint_chat"Selected item : %d"iChoice );
        case 
15client_printidprint_chat"Selected item : %d"iChoice );
        case 
16client_printidprint_chat"Selected item : %d"iChoice );
        case 
17client_printidprint_chat"Selected item : %d"iChoice );
        case 
18client_printidprint_chat"Selected item : %d"iChoice );
        case 
19client_printidprint_chat"Selected item : %d"iChoice );
        case 
20client_printidprint_chat"Selected item : %d"iChoice );
        case 
21client_printidprint_chat"Selected item : %d"iChoice );
        case 
22client_printidprint_chat"Selected item : %d"iChoice );
        case 
23client_printidprint_chat"Selected item : %d"iChoice );
        case 
24client_printidprint_chat"Selected item : %d"iChoice );
        
        default:  
client_printidprint_center"Item : %d does not exist"iChoice ); 
        
// If player choose slot above 24( or how much we add ), tell him that this item does not exist
    
}

And here it is without comments :
Spoiler


I don't know if this can be useful to someone , but i like it and decided to share it with you.

I'm open to criticism and ideas, so feel free to post here.
Also if you think something can be done better or this method is not good, feel free to trash my post ;)
__________________
Alekkkk is offline
Send a message via Skype™ to Alekkkk
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 03-13-2013 , 14:46   Re: How to: Menu with 10+ Options in one page
Reply With Quote #2

Not sure but how you gonna press number 10, 11, 12, .. ?
__________________
Retired.
Xalus is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 03-13-2013 , 14:52   Re: How to: Menu with 10+ Options in one page
Reply With Quote #3

Quote:
then we will catch which slot the player has pressed and wait 0.2( Cvar ) seconds to press one more .
If he press second slot in this time it will execute (if first choose was 2 and second 1 ) - 21
__________________
Alekkkk is offline
Send a message via Skype™ to Alekkkk
quilhos
Veteran Member
Join Date: Jun 2010
Old 03-13-2013 , 15:23   Re: How to: Menu with 10+ Options in one page
Reply With Quote #4

Quote:
Originally Posted by Xalus View Post
Not sure but how you gonna press number 10, 11, 12, .. ?
__________________
ELO RATING SYSTEM - SQL [COMPLETE]
Quote:
Originally Posted by Liverwiz View Post
DDDRRRRAAAAMMMMAAAAA!!!???

Put this shit on pause while i go get some popcorn!!
quilhos is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 03-13-2013 , 15:29   Re: How to: Menu with 10+ Options in one page
Reply With Quote #5

Are you asking me the same question ?

Press 1 then 0 and you have pressed 10..
__________________
Alekkkk is offline
Send a message via Skype™ to Alekkkk
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-14-2013 , 00:22   Re: How to: Menu with 10+ Options in one page
Reply With Quote #6

The only downside to accepting 1 and 2 character selections is that if they don't type the second one quick enough they get the wrong option. Nothing major.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-14-2013 , 02:14   Re: How to: Menu with 10+ Options in one page
Reply With Quote #7

May be not major but important, usualy when you know a menu you don't wait to choose option because time is strategic on cs (can be on any mod).
Anyway, menus with 2 or more pages are just ok.

This tip can be used though, if someone thinks it's cool.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 03-14-2013 , 06:19   Re: How to: Menu with 10+ Options in one page
Reply With Quote #8

fysiks - yes , in the first few uses of the menu , new users may make a wrong selection, but i'm sure that if they use the menu more then 2-3 times there will be no problem about that

ConnorMcLeod - i know that ~0.2 seconds delay in choosing something from menu can be fatal , but it still depends on how you will format you menu.

The main purpose of this method was for different format then the shown in the first post

Let's say you have more then 3 menus with les then 4 options and it will be good if you can show them at one time without messing their content.

You can still format one menu without any delay on chosing using this method

Something like this :
Code:
1. Menu 1
     1.1 Item1
     1.2 Item2
     1.3 Item3

2. Menu 2
     2.1 Item1
     2.2 Item2
     2.3 Item3

3. Menu 3
     etc.
With this format anyone will know that they can't press 1 for using a menu option , they should pres for example 1-1 and this will have no delay exept typing the numbers
__________________

Last edited by Alekkkk; 03-14-2013 at 06:21.
Alekkkk is offline
Send a message via Skype™ to Alekkkk
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-14-2013 , 07:45   Re: How to: Menu with 10+ Options in one page
Reply With Quote #9

Would be better to wait for the player to do +use when they choose a menu option. Say, there's a menu:
1. Item 1
2. Item 2
...
10. Item 10
When the player presses 1, the menu remains on the screen but looks like this:
1. Item 1
2. Item 2
...
10. Item 10
The player may then proceed to press 0, which switches the item highlight to the 10th option:
1. Item 1
2. Item 2
...
10. Item 10
And/Or press +use (default E) key to actually make a selection.
__________________
hleV is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-14-2013 , 15:21   Re: How to: Menu with 10+ Options in one page
Reply With Quote #10

This is a nice idea, but it sucks for players playing on 800x600.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
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 19:21.


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