Raised This Month: $ Target: $400
 0% 

Stupid menu, heeelp


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
h3llzOr
Member
Join Date: Nov 2011
Old 09-28-2012 , 17:31   Stupid menu, heeelp
Reply With Quote #1

Hello all, can you help me with a problem about a menu ?
Initial code :
Code:
public MENU_ChangeRace( id, iRaceXP[MAX_RACES] )
{
    
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];

    // Get our race names
    for ( i = 0; i < get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 0; i < get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // Add the "Select a Hero" message if necessary
        if ( i == 4 )
        {
            pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_HERO" );
        }
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            /*
            new iRaceLimit = get_pcvar_num( CVAR_wc3_race_limit );
            new bool:bAllowRace = true;

            if ( iRaceLimit > 0 )
            {
                new iTotal[MAX_RACES];

                // Get how many people are using each race
                new iPlayers[32], iNumPlayers, i, iTarget;
                get_players( iPlayers, iNumPlayers );

                for ( i = 0; i < iNumPlayers; i++ )
                {
                    iTarget = iPlayers[i];

                    if ( iTarget != id && p_data[iTarget][P_RACE] > 0 && p_data[iTarget][P_RACE] <= get_pcvar_num( CVAR_wc3_races ) )
                    {
                        iTotal[p_data[iTarget][P_RACE]]++;
                    }
                }
                
                // Now if we have more races selected than iRaceLimit provides us with, then we need to increase iRaceLimit
                while ( HLPR_TotalUsingRaces( iTotal ) > iRaceLimit * get_playersnum() )
                {
                    iRaceLimit++;
                }

                // Check to see if there was an increase that was necessary
                if ( iRaceLimit > get_pcvar_num( CVAR_wc3_race_limit ) )
                {
                    WC3_Log( true, "Error, increase wc3_race_limit to at least %d", iRaceLimit );
                }

                if ( iTotal[i+1] >= iRaceLimit )
                {
                    bAllowRace = false;

                }
            }*/

            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }

    iKeys |= (1<<i);
    
    // This is needed so we can make the Auto-Select option "0" if the number of races is 9
    if ( get_pcvar_num( CVAR_wc3_races ) == 9 )
    {
        i = -1;
    }

    pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_RACE_FOOTER", i + 1 );
    
    // Add a cancel button to the bottom
    if ( get_pcvar_num( CVAR_wc3_races ) != 9 )
    {
        iKeys |= (1<<9);

        pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    }
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

public _MENU_ChangeRace( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( get_pcvar_num( CVAR_wc3_races ) < 9 && key - 1 == get_pcvar_num( CVAR_wc3_races ) )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iAutoSelectKey = KEY_0;
    
    if ( get_pcvar_num( CVAR_wc3_races ) != 9 )
    {
        iAutoSelectKey = get_pcvar_num( CVAR_wc3_races )
    }
    
    // Auto select a race
    if ( key == iAutoSelectKey )
    {
        iRace = random_num( 1, get_pcvar_num( CVAR_wc3_races ) );
    }

    // Otherwise race is set
    else
    {
        iRace = key + 1;
    }

    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}
And my version ( that i'm tyred to try to repair, because when i test it don't work, the server crashes, and doesn't appear in logs what is the problem ) :
Code:
// Function will display the changerace menu
public MENU_ChangeRace( id, iRaceXP[MAX_RACES] )
{
    
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = clamp( get_pcvar_num( CVAR_wc3_races ), 1, MAX_RACES );

    // Get our race names
    for ( i = 0; i < RACES_PER_PAGE; i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 0; i < RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            /*
            new iRaceLimit = get_pcvar_num( CVAR_wc3_race_limit );
            new bool:bAllowRace = true;

            if ( iRaceLimit > 0 )
            {
                new iTotal[MAX_RACES];

                // Get how many people are using each race
                new iPlayers[32], iNumPlayers, i, iTarget;
                get_players( iPlayers, iNumPlayers );

                for ( i = 0; i < iNumPlayers; i++ )
                {
                    iTarget = iPlayers[i];

                    if ( iTarget != id && p_data[iTarget][P_RACE] > 0 && p_data[iTarget][P_RACE] <= get_pcvar_num( CVAR_wc3_races ) )
                    {
                        iTotal[p_data[iTarget][P_RACE]]++;
                    }
                }
                
                // Now if we have more races selected than iRaceLimit provides us with, then we need to increase iRaceLimit
                while ( HLPR_TotalUsingRaces( iTotal ) > iRaceLimit * get_playersnum() )
                {
                    iRaceLimit++;
                }

                // Check to see if there was an increase that was necessary
                if ( iRaceLimit > get_pcvar_num( CVAR_wc3_race_limit ) )
                {
                    WC3_Log( true, "Error, increase wc3_race_limit to at least %d", iRaceLimit );
                }

                if ( iTotal[i+1] >= iRaceLimit )
                {
                    bAllowRace = false;

                }
            }*/

            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }

    // Add a next button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. %L", id, "WORD_NEXT" );
    }

    // Add a cancel button to the bottom
    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

public _MENU_ChangeRace( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( key == KEY_0 )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iNextPageKey = KEY_9;
        
    // Auto select a race
    if ( key == iNextPageKey )
    {
        MENU_ChangeRaceTwo( id );
    }
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}

public MENU_ChangeRaceTwo( id )
{
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = clamp( get_pcvar_num( CVAR_wc3_races ), 1, MAX_RACES );
    new iRaceXP[MAX_RACES];

    // Get our race names
    for ( i = 8; i < RACES_PER_PAGE_TWO; i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 1; i < RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }

    // Add a back button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. %L", id, "WORD_BACK" );
    }

    // Add a cancel button to the bottom
    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

public _MENU_ChangeRaceTwo( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( key == KEY_0 )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iBackPageKey = KEY_9;
    new iRaceXP[MAX_RACES];
        
    // Auto select a race
    if ( key == iBackPageKey )
    {
        MENU_ChangeRace( id, iRaceXP );
    }
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}
I have been try to create an 2nd page in changerace menu, but the server crashes when i'm press any button and i don't know how to solve it !
Please some help...
h3llzOr is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-28-2012 , 19:51   Re: Stupid menu, heeelp
Reply With Quote #2

What are the errors? (in logs or in the server console when it crashes)

Also, you should attach the whole .sma file.
__________________
fysiks is offline
h3llzOr
Member
Join Date: Nov 2011
Old 09-29-2012 , 08:07   Re: Stupid menu, heeelp
Reply With Quote #3

In server consola and in logs dosn't appear any errors, but the server crashes when i press any button of menui think the problem is with that "iRaceXP[MAX_RACES]" but i not sure...
h3llzOr is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-29-2012 , 08:18   Re: Stupid menu, heeelp
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Also, you should attach the whole .sma file.
This will give us a better idea of what could be going wrong and how to help you.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
h3llzOr
Member
Join Date: Nov 2011
Old 09-29-2012 , 08:53   Re: Stupid menu, heeelp
Reply With Quote #5

It's from warcraft 3.0 frozen throne by Geesu, but i do some modification, 19 levels, 3 item and also i try to create new races...

menus.inl
Code:
public MENU_War3Menu( id )
{
    static pos, szMenu[256], keys;
    keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<9);
    pos = 0;

    // Add the title
    pos += formatex( szMenu[pos], 255-pos, "%L^n^n", id, "MENU_WAR3MENU" );

    // Add the actual options to the menu
    pos += formatex( szMenu[pos], 255-pos, "\w1. %L^n", id, "SKILLS_MENU" );
    pos += formatex( szMenu[pos], 255-pos, "\w2. %L^n", id, "RACE_MENU" );
    pos += formatex( szMenu[pos], 255-pos, "\w3. %L^n", id, "ITEM_MENU" );
    pos += formatex( szMenu[pos], 255-pos, "\w4. %L^n", id, "HELP" );
    pos += formatex( szMenu[pos], 255-pos, "\w5. %L^n", id, "ADMIN_MENU_TITLE" );
    pos += formatex( szMenu[pos], 255-pos, "^n\w0. %L", id, "WORD_EXIT" );

    // Display the menu
    show_menu( id, keys, szMenu, -1 );

    return;
}

public _MENU_War3Menu( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch ( key )
    {
        case 0:    menu_Skill_Options( id );
        case 1:    menu_Race_Options( id );
        case 2:    menu_Item_Options( id );
        case 3:    MOTD_War3help( id );
        case 4:    menu_Admin_Options( id );
    }
    
    return PLUGIN_HANDLED;
}

public menu_Skill_Options( id )
{

    new pos = 0, i, menu_body[512], menuitems[3][32]
    new keys = (1<<0)|(1<<1)|(1<<2)|(1<<8)|(1<<9)


    format(menuitems[0],31,"%L",id,"SELECT_SKILLS")
    format(menuitems[1],31,"%L",id,"SKILLS_INFORMATION")
    format(menuitems[2],31,"%L",id,"RESELECT_SKILLS")

    pos += format(menu_body[pos], 511-pos, "%L^n^n",id,"MENU_SKILLS_OPTIONS")
    for (i = 0; i<3; i++){
        pos += format(menu_body[pos], 511-pos, "\w%d. %s^n",i+1,menuitems[i])
    }
    pos += format(menu_body[pos], 511-pos, "^n^n\w9. %L",id,"BACK_STRING")
    pos += format(menu_body[pos], 511-pos, "^n\w0. %L",id,"WORD_EXIT")
    show_menu(id,keys,menu_body,-1)

    return PLUGIN_CONTINUE
}

public _menu_Skill_Options(id,key){
    
    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch (key){
        case 0:    MENU_SelectSkill( id );
        case 1:    MOTD_SkillsInfo( id );
        case 2:    CMD_Handle( id, "resetskills", true );
        case 8: MENU_War3Menu(id)
        default: return PLUGIN_HANDLED;
    }

    return PLUGIN_HANDLED;
}

public menu_Race_Options(id){

    new pos = 0, i, menu_body[512], menuitems[4][32]
    new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<8)|(1<<9)

    format(menuitems[0],31,"%L",id,"CHANGE_RACE")
    format(menuitems[1],31,"%L",id,"SHOW_LEVEL")
    format(menuitems[2],31,"%L",id,"RESET_XP")
    format(menuitems[3],31,"%L",id,"SHOW_PLAYER_SKILLS")

    pos += format(menu_body[pos], 511-pos, "%L^n^n",id,"MENU_RACE_OPTIONS")
    for (i = 0; i<4; i++){
        pos += format(menu_body[pos], 511-pos, "\w%d. %s^n",i+1,menuitems[i])
    }
    pos += format(menu_body[pos], 511-pos, "^n^n\w9. %L",id,"BACK_STRING")
    pos += format(menu_body[pos], 511-pos, "^n\w0. %L",id,"WORD_EXIT")
    show_menu(id,keys,menu_body,-1)

    return PLUGIN_CONTINUE
}

public _menu_Race_Options(id,key){

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch (key){
        case 0:    WC3_ChangeRaceStart( id );
        case 1:    WC3_ShowRaceInfo( id );
        case 2:    MENU_ResetXP( id );
        case 3:    MOTD_PlayerSkills( id, true );
        case 8: MENU_War3Menu(id)
        default: return PLUGIN_HANDLED;
    }

    return PLUGIN_HANDLED;
}

public menu_Item_Options(id){

    new pos = 0, i, menu_body[512], menuitems[4][32]
    new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<8)|(1<<9)

    format(menuitems[0],31,"%L",id,"SHOPMENU1_OPTION")
    format(menuitems[1],31,"%L",id,"SHOPMENU2_OPTION")
    format(menuitems[2],31,"%L",id,"SHOW_SHOPMENU1_INFO")
    format(menuitems[3],31,"%L",id,"SHOW_SHOPMENU2_INFO")

    pos += format(menu_body[pos], 511-pos, "%L^n^n",id,"MENU_ITEM_OPTIONS")
    for (i = 0; i<4; i++){
        pos += format(menu_body[pos], 511-pos, "\w%d. %s^n",i+1,menuitems[i])
    }
    pos += format(menu_body[pos], 511-pos, "^n^n\w9. %L",id,"BACK_STRING")
    pos += format(menu_body[pos], 511-pos, "^n\w0. %L",id,"WORD_EXIT")
    show_menu(id,keys,menu_body,-1)

    return PLUGIN_CONTINUE
}

public _menu_Item_Options(id,key){

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch (key){
        case 0:    MENU_Shopmenu( id, 0 );
        case 1:    MENU_Shopmenu( id, 9 );
        case 2:    MOTD_ItemsInfo( id, 0 );
        case 3:    MOTD_ItemsInfo( id, 9 );
        case 8: MENU_War3Menu(id);
        default: return PLUGIN_HANDLED;
    }

    return PLUGIN_HANDLED;
}

public menu_Admin_Options(id){

    if ( id && !( get_user_flags( id ) & XP_GetAdminFlag() ) )
    {
            client_print(id,print_center,"%s %L",g_MODclient, id,"YOU_HAVE_NO_ACCESS")
            return PLUGIN_HANDLED
    }

    new pos = 0, i, menu_body[512], menuitems[3][32]
    new keys = (1<<0)|(1<<1)|(1<<2)|(1<<8)|(1<<9)

    format(menuitems[0],31,"%L",id,"GIVE_IND_XP")
    format(menuitems[1],31,"%L",id,"GIVE_MULT_XP")
    format(menuitems[2],31,"%L",id,"SAVE_ALL_XP")

    pos += format(menu_body[pos], 511-pos, "%L^n^n",id,"MENU_ADMIN_MENU")
    for (i = 0; i<3; i++){
        pos += format(menu_body[pos], 511-pos, "\w%d. %s^n",i+1,menuitems[i])
    }
    pos += format(menu_body[pos], 511-pos, "^n^n\w9. %L",id,"BACK_STRING")
    pos += format(menu_body[pos], 511-pos, "^n\w0. %L",id,"WORD_EXIT")
    show_menu(id,keys,menu_body,-1)

    return PLUGIN_CONTINUE
}

public _menu_Admin_Options(id,key){

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch (key){
        case 0:{
            g_menuOption[id] = 1
            g_menuSettings[id] = 50
            menu_PlayerXP_Options(id,g_menuPosition[id] = 0)
        }
        case 1:{
            g_menuOption[id] = 1
            g_menuSettings[id] = 50
            menu_TeamXP_Options(id)
        }
        case 2: DB_SaveAll( false );
        case 8: MENU_War3Menu(id)
    }

    return PLUGIN_HANDLED;
}

public menu_PlayerXP_Options(id,pos){

    if (pos < 0){
        menu_Admin_Options(id)
        return PLUGIN_CONTINUE
    }

    get_players(g_menuPlayers[id],g_menuPlayersNum[id])
    new menuBody[512]
    new b = 0
    new i
    new name[32], team[4], title[128], back[16], exitstring[16]
    new start = pos * 7
    if (start >= g_menuPlayersNum[id])
        start = pos = g_menuPosition[id] = 0
    format(title,127,"%L",id,"MENU_GIVE_PLAYERS_XP")
    new len = format(menuBody,511, "%s\R%d/%d^n\w^n",title,pos+1,(g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0 )))
    new end = start + 7
    new keys = (1<<9)|(1<<7)

    if (end > g_menuPlayersNum[id])
        end = g_menuPlayersNum[id]

    for(new a = start; a < end; ++a){
        i = g_menuPlayers[id][a]
        get_user_name(i,name,31)
        get_user_team(i,team,3)
        keys |= (1<<b)
        len += format(menuBody[len],511-len,"\w%d. %s^n\w",++b,name)
    }

    format(title,127,"%L",id,"GIVE")
    len += format(menuBody[len],511-len,"^n8. %s  %d XP^n",title,g_menuSettings[id])

    format(back,15,"%L",id,"BACK_STRING")

    if (end != g_menuPlayersNum[id]){
        format(menuBody[len],511-len,"^n9. %L...^n0. %s", id,"MORE_STRING", pos ? back : back)
        keys |= (1<<8)
    }
    else{
        format(exitstring,15,"%L",id,"WORD_EXIT")
        format(menuBody[len],511-len,"^n0. %s", pos ? back : exitstring)
    }


    show_menu(id,keys,menuBody,-1)
    return PLUGIN_CONTINUE

}

public _menu_PlayerXP_Options(id,key){

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch(key){
        case 7:{
            ++g_menuOption[id]
            if (g_menuOption[id]>6){
                g_menuOption[id]=1
            }
            switch(g_menuOption[id]){
                case 1: g_menuSettings[id] = 50
                case 2: g_menuSettings[id] = 100
                case 3: g_menuSettings[id] = 500
                case 4: g_menuSettings[id] = 1000
                case 5: g_menuSettings[id] = 5000
                case 6: g_menuSettings[id] = 10000
            }
            menu_PlayerXP_Options(id,g_menuPosition[id])
        }
        case 8: menu_PlayerXP_Options(id,++g_menuPosition[id])
        case 9: return PLUGIN_HANDLED;
        default:{
            new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key]
            client_print(player,print_chat,"%s %L",g_MODclient, id,"THE_ADMIN_JUST_GAVE_YOU_XP",g_menuSettings[id])
            p_data[player][P_XP] += g_menuSettings[id]

            XP_Check( player );

            menu_PlayerXP_Options(id,g_menuPosition[id])
        }
    }

    return PLUGIN_HANDLED;
}

public menu_TeamXP_Options(id){

    new pos = 0, i, menu_body[512], menuitems[3][32], give[16]
    new keys = (1<<0)|(1<<1)|(1<<2)|(1<<7)|(1<<8)|(1<<9)

    format(menuitems[0],31,"%L",id,"TERRORISTS")
    format(menuitems[1],31,"%L",id,"CT")
    format(menuitems[2],31,"%L",id,"EVERYONE")

    pos += format(menu_body[pos], 511-pos, "%L^n^n",id,"MENU_TEAM_XP")
    for (i = 0; i<3; i++){
        pos += format(menu_body[pos], 511-pos, "\w%d. %s^n",i+1,menuitems[i])
    }
    format(give,15,"%L",id,"GIVE")
    pos += format(menu_body[pos], 511-pos,"^n8. %s  %d XP^n",give,g_menuSettings[id])
    pos += format(menu_body[pos], 511-pos, "^n^n\w9. %L",id,"BACK_STRING")
    pos += format(menu_body[pos], 511-pos, "^n\w0. %L",id,"WORD_EXIT")
    show_menu(id,keys,menu_body,-1)

    return PLUGIN_CONTINUE
}

public _menu_TeamXP_Options(id,key){

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }

    switch(key){
        case 0:
        {
            ADMIN_GiveXP( id, "@T", g_menuSettings[id] );
            menu_TeamXP_Options(id)
        }
        case 1:{
            ADMIN_GiveXP( id, "@CT", g_menuSettings[id] );
            menu_TeamXP_Options(id)
        }
        case 2:{
            ADMIN_GiveXP( id, "@ALL", g_menuSettings[id] );
            menu_TeamXP_Options(id)
        }
        case 7:{
            ++g_menuOption[id]
            if (g_menuOption[id]>6){
                g_menuOption[id]=1
            }
            switch(g_menuOption[id]){
                case 1: g_menuSettings[id] = 50
                case 2: g_menuSettings[id] = 100
                case 3: g_menuSettings[id] = 500
                case 4: g_menuSettings[id] = 1000
                case 5: g_menuSettings[id] = 5000
                case 6: g_menuSettings[id] = 10000
            }
            menu_TeamXP_Options(id)
        }
        case 8: menu_Admin_Options(id)
    }

    return PLUGIN_HANDLED;
}

public MENU_ResetXP(id)
{

   client_print( id, print_center, "This option has been disabled!" );
}

public _MENU_ResetXP( id, key )
{

   client_print( id, print_center, "This option has been disabled!" );
}

// Function will display the changerace menu
public MENU_ChangeRace( id, iRaceXP[MAX_RACES] )
{
    
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = clamp( get_pcvar_num( CVAR_wc3_races ), 1, MAX_RACES );

    // Get our race names
    for ( i = 0; i < RACES_PER_PAGE; i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 0; i < RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            /*
            new iRaceLimit = get_pcvar_num( CVAR_wc3_race_limit );
            new bool:bAllowRace = true;

            if ( iRaceLimit > 0 )
            {
                new iTotal[MAX_RACES];

                // Get how many people are using each race
                new iPlayers[32], iNumPlayers, i, iTarget;
                get_players( iPlayers, iNumPlayers );

                for ( i = 0; i < iNumPlayers; i++ )
                {
                    iTarget = iPlayers[i];

                    if ( iTarget != id && p_data[iTarget][P_RACE] > 0 && p_data[iTarget][P_RACE] <= get_pcvar_num( CVAR_wc3_races ) )
                    {
                        iTotal[p_data[iTarget][P_RACE]]++;
                    }
                }
                
                // Now if we have more races selected than iRaceLimit provides us with, then we need to increase iRaceLimit
                while ( HLPR_TotalUsingRaces( iTotal ) > iRaceLimit * get_playersnum() )
                {
                    iRaceLimit++;
                }

                // Check to see if there was an increase that was necessary
                if ( iRaceLimit > get_pcvar_num( CVAR_wc3_race_limit ) )
                {
                    WC3_Log( true, "Error, increase wc3_race_limit to at least %d", iRaceLimit );
                }

                if ( iTotal[i+1] >= iRaceLimit )
                {
                    bAllowRace = false;

                }
            }*/

            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }

    // Add a next button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. %L", id, "WORD_NEXT" );
    }

    // Add a cancel button to the bottom
    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

/*HLPR_TotalUsingRaces( iTotalRaces[MAX_RACES] )
{
    new iTotal = 0;
    for ( new i = 1; i <= get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        WC3_Log( true, "%d", i );
        iTotal += iTotalRaces[i];
    }

    return iTotal;
}*/


public _MENU_ChangeRace( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( key == KEY_0 )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iNextPageKey = KEY_9;
        
    // Auto select a race
    if ( key == iNextPageKey )
    {
        MENU_ChangeRaceTwo( id );
    }
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}

public MENU_ChangeRaceTwo( id )
{
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = clamp( get_pcvar_num( CVAR_wc3_races ), 1, MAX_RACES );
    new iRaceXP[MAX_RACES];

    // Get our race names
    for ( i = 8; i < RACES_PER_PAGE_TWO; i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 1; i < RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }

    // Add a back button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. %L", id, "WORD_BACK" );
    }

    // Add a cancel button to the bottom
    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

public _MENU_ChangeRaceTwo( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( key == KEY_0 )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iBackPageKey = KEY_9;
    new iRaceXP[MAX_RACES];
        
    // Auto select a race
    if ( key == iBackPageKey )
    {
        MENU_ChangeRace( id, iRaceXP );
    }
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}
    

public MENU_ReplaceItem( idUser ) 
 { 

    new szMenu[512] = "", pos = 0; 
    new iKeys = (1<<9)|(1<<0)|(1<<1)|(1<<2); 

    // Add the menu header 
    pos += format( szMenu[pos], charsmax(szMenu)-pos, "%L^n^n", LANG_PLAYER, "MENU_REPLACE_ITEM" ); 

    new szItemName[64], szItemName2[64], szItemName3[64]; 
    LANG_GetItemName( g_iShopMenuItems[idUser][ITEM_SLOT_ONE], idUser, szItemName, charsmax(szItemName) ); 
    LANG_GetItemName( g_iShopMenuItems[idUser][ITEM_SLOT_TWO], idUser, szItemName2, charsmax(szItemName2) ); 
    LANG_GetItemName( g_iShopMenuItems[idUser][ITEM_SLOT_THREE], idUser, szItemName3, charsmax(szItemName3) ); 
    // Add the items 
    pos += format( szMenu[pos], charsmax(szMenu)-pos, "\w1. %s^n", szItemName ); 
    pos += format( szMenu[pos], charsmax(szMenu)-pos, "\w2. %s^n", szItemName2 ); 
    pos += format( szMenu[pos], charsmax(szMenu)-pos, "\w3. %s^n", szItemName3 ); 
    // Add the exit option 
    pos += format( szMenu[pos], charsmax(szMenu)-pos, "^n\d0. %L", LANG_PLAYER, "WORD_EXIT" ); 
    
    // Show the menu 
    show_menu( idUser, iKeys, szMenu, -1 ); 

 return; 
 }

public _menu_ReplaceItem( idUser, iKey ) 
 { 
    if ( !WC3_Check() || iKey == 9 ) 
    { 
        return PLUGIN_HANDLED; 
    } 
    
    // Remove item from item slot one 
    if ( iKey == 0 ) 
    { 
        ITEM_Remove( idUser, ITEM_SLOT_ONE ) 
    } 
    
    // Remove item from itemslot two 
    else if ( iKey == 1 ) 
    { 
        ITEM_Remove( idUser, ITEM_SLOT_TWO ) 
    } 
    else if ( iKey == 2 ) 
    { 
        ITEM_Remove( idUser, ITEM_SLOT_THREE )
    } 

    // Then the user typed "rings" 
    if ( g_iFutureItem[idUser] == -3 ) 
    { 
        ITEM_BuyRings( idUser ); 
    } 
    else 
    { 
        ITEM_Buy( idUser, g_iFutureItem[idUser] ); 
    } 

 return PLUGIN_HANDLED; 
 }

public MENU_Shopmenu( id, iStart )
{

    if ( !ITEM_MenuCanBuyCheck( id ) )
    {
        return;
    }

    // Shopmenu2 can't display if we don't have the correct number of races!
    if ( iStart == MAX_PAGE_ITEMS && get_pcvar_num( CVAR_wc3_races ) <= 4 )
    {
        return;
    }

    new szMenu[512], szItemName[64], pos = 0, i, iItemID;
    new iKeys = (1<<9);

    // Add the header
    if ( iStart == 0 )
    {
        pos += format( szMenu[pos], 511-pos, "%L", id, "MENU_BUY_ITEM" );
    }

    // "Shopmenu 2"
    else if ( iStart == MAX_PAGE_ITEMS )
    {
        pos += format( szMenu[pos], 511-pos, "%L", id, "MENU_BUY_ITEM2" );
    }

    // Lets add the items to the menu!
    for ( i = 0; i < MAX_PAGE_ITEMS; i++ )
    {
        iItemID = iStart + i;

        LANG_GetItemName( iItemID, id, szItemName, 63 );

        // These items don't exist in DOD
        if ( g_MOD == GAME_DOD && ( iItemID == ITEM_SCROLL ) )
        {
            pos += format( szMenu[pos], 511-pos, "\d%d. %s\y\R%d^n", i + 1, szItemName, ITEM_Cost( id, iItemID ) );
        }

        // Everything else is allowed!
        else
        {
            pos += format( szMenu[pos], 511-pos, "\w%d. %s\y\R%d^n", i + 1, szItemName, ITEM_Cost( id, iItemID ) );
            iKeys |= (1<<i);
        }

    }

    pos += format( szMenu[pos], 511-pos, "^n\w0. %L", id, "WORD_EXIT" );

    show_menu( id, iKeys, szMenu, -1 );
}

public _MENU_Shopmenu1( id, iKey )
{
    if ( !WC3_Check() || iKey == 9 )
    {
        return PLUGIN_HANDLED;
    }

    ITEM_Buy( id, iKey );

    return PLUGIN_HANDLED;
}

public _MENU_Shopmenu2( id, iKey )
{
    if ( !WC3_Check() || iKey == 9 )
    {
        return PLUGIN_HANDLED;
    }

    iKey += MAX_PAGE_ITEMS;
    
    ITEM_Buy( id, iKey );

    return PLUGIN_HANDLED;
}

public MENU_SelectSkill( id )
{

    // User has no race, how can we select skills?!?
    if ( p_data[id][P_RACE] == 0 )
    {
        //set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 2)
        WC3_StatusText( id, TXT_TOP_CENTER, "%L", id, "SELECT_RACE_BEFORE_SKILLS" );

        return;
    }

    // They don't choose skills when it's random
    else if ( p_data[id][P_RACE] == RACE_CHAMELEON && get_pcvar_num( CVAR_wc3_cham_random ) )
    {
        //WC3_StatusText( id, TXT_TOP_CENTER, "%s", "Chameleons can't select skills!" );
        CHAM_ConfigureSkills( id );

        return;
    }

    // Lets make sure the user has some available skill points
    new iSkillsUsed = SM_TotalSkillPointsUsed( id );
    if ( iSkillsUsed >= p_data[id][P_LEVEL] )
    {

        //set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 2)
        WC3_StatusText( id, TXT_TOP_CENTER, "%L", id, "ALREADY_SELECTED_SKILL_POINTS" );

        return;
    }

    // Bots don't need a menu now do they??
    if ( is_user_bot( id ) )
    {
        // No race has been selected yet!!
        if ( !SM_SkillAvailable( id ) )
        {
            return;
        }
        
        // Keep giving the bot a random ID until we are full!
        while ( iSkillsUsed < p_data[id][P_LEVEL] )
        {
            SM_GiveRandomSkillPoint( id );

            iSkillsUsed = SM_TotalSkillPointsUsed( id );
        }

        return;
    }

    // OK set up a menu!!!

    new szMsg[512], pos = 0, szSkillName[64];
    new iSkillCounter = 0, iSkillID = 0, iKeys = (1<<9), iSkillLevel;

    // Add the menu header
    pos += formatex( szMsg[pos], 512-pos, "%L", id, "MENU_SELECT_SKILL" );

    iSkillID = SM_GetSkillByPos( id, iSkillCounter );

    while ( iSkillID != -1 )
    {
        iSkillLevel = SM_GetSkillLevel( id, iSkillID, 4 );

        LANG_GetSkillName( iSkillID , id, szSkillName, 63, 1 );
        
        // Add the trainable skills to the menu
        if ( SM_GetSkillType( iSkillID ) == SKILL_TYPE_TRAINABLE )
        {

            // Only add it to the menu if they don't have level 3 already!
            if ( iSkillLevel < MAX_SKILL_LEVEL )
            {

                // User isn't high enough of a level to select this skill yet
                if ( p_data[id][P_LEVEL] <= 2 * iSkillLevel )
                {
                    pos += formatex( szMsg[pos], 512-pos, "\d" );
                }

                // Then the user can choose it!
                else
                {
                    iKeys |= (1<<iSkillCounter);
                }

                pos += formatex( szMsg[pos], 512-pos, "^n%d. %s %L %d\w", iSkillCounter+1, szSkillName, id, "WORD_LEVEL", iSkillLevel + 1 );
            }
        }
        
        // Add the ultimate to the menu
        else if ( SM_GetSkillType( iSkillID ) == SKILL_TYPE_ULTIMATE )
        {

            if ( iSkillLevel < MAX_ULTIMATE_LEVEL )
            {
                // User can't choose ultimate yet :/
                if ( p_data[id][P_LEVEL] <= 9 )
                {
                    pos += formatex( szMsg[pos], 512-pos, "\d" );
                }

                // Then the user is level 6 or above and can select their ultimate!
                else
                {
                    iKeys |= (1<<iSkillCounter);
                }

                pos += formatex( szMsg[pos], 512-pos, "^n%d. %L: %s\w", iSkillCounter+1, id, "WORD_ULTIMATE", szSkillName );
            }
        }

        iSkillCounter++;
        iSkillID = SM_GetSkillByPos( id, iSkillCounter );
    }

    // Add the cancel button to the menu
    pos += formatex( szMsg[pos], 512-pos, "^n^n0. %L", id, "WORD_CANCEL" );

    // Show the menu!
    show_menu( id, iKeys, szMsg, -1 );

    return;
}

public _MENU_SelectSkill( id, iKey )
{

    if ( !WC3_Check() || iKey == 9 )
    {
        return PLUGIN_HANDLED;
    }

    // Determine which key was just selected
    new iSkillID = SM_GetSkillByPos( id, iKey );

    // Set up the skill!
    SM_SetSkill( id, iSkillID );
    
    new iSkillsUsed = SM_TotalSkillPointsUsed( id );
    
    // Then they have another skill to select!!
    if ( iSkillsUsed < p_data[id][P_LEVEL] )
    {
        MENU_SelectSkill( id );
    }

    // No more, lets show them their latest level/XP
    else
    {
        WC3_ShowBar( id );
    }

    return PLUGIN_HANDLED;
}
Last Edit : I do another test, and just 0.cancel work, and others buttons crash the server.
Attached Files
File Type: sma Get Plugin or Get Source (war3ft.sma - 357 views - 21.8 KB)

Last edited by h3llzOr; 09-29-2012 at 09:03.
h3llzOr is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-29-2012 , 15:16   Re: Stupid menu, heeelp
Reply With Quote #6

Since you modified it, you should know exact what code is causing it not to work. Undo that.
__________________
fysiks is offline
h3llzOr
Member
Join Date: Nov 2011
Old 09-29-2012 , 17:25   Re: Stupid menu, heeelp
Reply With Quote #7

but i don't know why doesn't work, just "0. Cancel" work
so put the problem in another way, how i will do 9 next page in changearce menu from war3ft ? and on 2nd page 9 back page a callback function

Last edited by h3llzOr; 09-29-2012 at 19:38.
h3llzOr is offline
h3llzOr
Member
Join Date: Nov 2011
Old 10-01-2012 , 14:53   Re: Stupid menu, heeelp
Reply With Quote #8

hi all again, i have do same new modification and now the server crash only when i pree 9.next page
CODE:
Code:
// Function will display the changerace menu
public MENU_ChangeRace( id )
{
    
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = get_pcvar_num( CVAR_wc3_races );
    new iRaceXP[MAX_RACES];

    // Get our race names
    for ( i = 0; i < get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 0; i < RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // Add the "Select a Hero" message if necessary
        /*if ( i == 4 )
        {
            pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_HERO" );
        }*/
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            /*
            new iRaceLimit = get_pcvar_num( CVAR_wc3_race_limit );
            new bool:bAllowRace = true;

            if ( iRaceLimit > 0 )
            {
                new iTotal[MAX_RACES];

                // Get how many people are using each race
                new iPlayers[32], iNumPlayers, i, iTarget;
                get_players( iPlayers, iNumPlayers );

                for ( i = 0; i < iNumPlayers; i++ )
                {
                    iTarget = iPlayers[i];

                    if ( iTarget != id && p_data[iTarget][P_RACE] > 0 && p_data[iTarget][P_RACE] <= get_pcvar_num( CVAR_wc3_races ) )
                    {
                        iTotal[p_data[iTarget][P_RACE]]++;
                    }
                }
                
                // Now if we have more races selected than iRaceLimit provides us with, then we need to increase iRaceLimit
                while ( HLPR_TotalUsingRaces( iTotal ) > iRaceLimit * get_playersnum() )
                {
                    iRaceLimit++;
                }

                // Check to see if there was an increase that was necessary
                if ( iRaceLimit > get_pcvar_num( CVAR_wc3_race_limit ) )
                {
                    WC3_Log( true, "Error, increase wc3_race_limit to at least %d", iRaceLimit );
                }

                if ( iTotal[i+1] >= iRaceLimit )
                {
                    bAllowRace = false;

                }
            }*/

            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }


    // Add a next button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. \y%L", id, "WORD_NEXT" );
    }

    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

/*HLPR_TotalUsingRaces( iTotalRaces[MAX_RACES] )
{
    new iTotal = 0;
    for ( new i = 1; i <= get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        WC3_Log( true, "%d", i );
        iTotal += iTotalRaces[i];
    }

    return iTotal;
}*/


public _MENU_ChangeRace( id, key )
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( get_pcvar_num( CVAR_wc3_races ) < 9 && key - 1 == get_pcvar_num( CVAR_wc3_races ) )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iCancelKey = KEY_0, iNextPageKey = KEY_9;
    
    // Next Page ( 9 )
    if ( key == iNextPageKey )
    {
        menu_changeracedoi(id);
    }
    
    // Cancel ( 0 )
    if ( key == iCancelKey )
    {
        return PLUGIN_HANDLED;
    }

    // Otherwise race is set
    else
    {
        iRace = key + 1;
    }

    if(iRace == 9)  
    {  
        if(!(get_user_flags(id) & ADMIN_LEVEL_H ))  
        {  
            client_print( id, print_center, "You have not acces to this race!");    

            return PLUGIN_HANDLED;  
        }  
    }
 
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}

public menu_changeracedoi(id)
{
    new szRaceName[MAX_RACES+1][64], i, pos, iKeys = 0, szMenu[512], szXP[16];
    new iTotalRaces = get_pcvar_num( CVAR_wc3_races );
    new iRaceXP[MAX_RACES];

    // Get our race names
    for ( i = 8; i < get_pcvar_num( CVAR_wc3_races ); i++ )
    {
        lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
    }

    pos += formatex( szMenu[pos], 512-pos, "%L", id, "MENU_SELECT_RACE" );

    // Then add the experience column
    if ( get_pcvar_num( CVAR_wc3_save_xp ) )
    {
        pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_LEVEL" );
    }
    else
    {
        pos += formatex( szMenu[pos], 512-pos, "^n^n" );
    }

    // Build the changerace menu (for every race)
    for ( i = 0; RACES_PER_PAGE; i++ )
    {
        num_to_str( iRaceXP[i], szXP, 15 );
        
        // Add the "Select a Hero" message if necessary
        /*if ( i == 4 )
        {
            pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_HERO" );
        }*/
        
        // User's current race
        if ( i == p_data[id][P_RACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // Race the user wants to change to
        else if ( i == p_data[id][P_CHANGERACE] - 1 )
        {
            pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

            iKeys |= (1<<i);
        }

        // All other cases
        else
        {
            new bool:bAllowRace = true;

            // Check to see if the user can choose this race (are there too many of this race?)
            if ( bAllowRace )
            {
                pos += formatex( szMenu[pos], 512-pos, "\w%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );

                iKeys |= (1<<i);
            }

            // If not, display the race, but don't give them a key to press
            else
            {
                pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\y\R%s^n", i + 1, szRaceName[i], ( (get_pcvar_num( CVAR_wc3_save_xp )) ? szXP : " " ) );
            }
        }

    }


    // Add a back button to the bottom
    if ( iTotalRaces > 8 )
    {
        iKeys |= (1<<8);

        pos += format( szMenu[pos], 512-pos, "^n\w9. \y%L", id, "WORD_BACK" );
    }

    iKeys |= (1<<9);
    pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
    
    // Show the menu to the user!
    show_menu( id, iKeys, szMenu, -1 );

    return;
}

public _menu_changeracedoi(id, key)
{

    if ( !WC3_Check() )
    {
        return PLUGIN_HANDLED;
    }
    
    // User pressed 0 (cancel)
    if ( get_pcvar_num( CVAR_wc3_races ) < 9 && key - 1 == get_pcvar_num( CVAR_wc3_races ) )
    {
        return PLUGIN_HANDLED;
    }

    // Save the current race data before we change
    DB_SaveXP( id, false );

    new iRace, iCancelKey = KEY_0, iBackPageKey = KEY_9;
    
    // NExt Page ( 9 )
    if ( key == iBackPageKey )
    {
        MENU_ChangeRace(id);
    }
    
    // Cancel ( 0 )
    if ( key == iCancelKey )
    {
        return PLUGIN_HANDLED;
    }

    // Otherwise race is set
    else
    {
        iRace = key + 1;
    }

    if(iRace == 9)  
    {  
        if(!(get_user_flags(id) & ADMIN_LEVEL_H ))  
        {  
            client_print( id, print_center, "You have not acces to this race!");    

            return PLUGIN_HANDLED;  
        }  
    }
 
    // User currently has a race
    if ( p_data[id][P_RACE] != 0 )
    {

        // Change the user's race at the start of next round
        if ( iRace != p_data[id][P_RACE] )
        {
            
            // Special message for csdm
            if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
            {
                client_print( id, print_center, "Your race will be changed when you respawn" );
            }    
            else
            {
                client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
            }

            p_data[id][P_CHANGERACE] = iRace;
        }

        // Do nothing
        else
        {
            p_data[id][P_CHANGERACE] = 0;
        }
    }

    // User doesn't have a race so give it to him!!!
    else
    {
        WC3_SetRace( id, iRace );
    }

    return PLUGIN_HANDLED;
}
And in logs doesn't appear any errors all look to be fine but it isn't.
Heeeeeeelp please.
h3llzOr is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-01-2012 , 19:29   Re: Stupid menu, heeelp
Reply With Quote #9

So what is the error in the server console when it crashes then?

Also, remember that every time you use a while loop, you create the possibility of an infinite loop (which some people falsely mistake as a "crash").
__________________
fysiks is offline
h3llzOr
Member
Join Date: Nov 2011
Old 10-02-2012 , 04:13   Re: Stupid menu, heeelp
Reply With Quote #10

In server console it isn't any error, just server crash and then is Not Responding and i quit the proces with CTRL+ALT+Delete...

i think the problem is thits :
Code:
// Get our race names  
for ( i = 8; i < get_pcvar_num( CVAR_wc3_races ); i++ )  
{
          lang_GetRaceName( i + 1, id, szRaceName[i], 63 );
}
 // Build the changerace menu (for every race) 
    for ( i = 0; RACES_PER_PAGE; i++ )     
{
         ....
}
And i don't see the while loop in this code...

Last edited by h3llzOr; 10-02-2012 at 04:15.
h3llzOr 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 08:17.


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