Raised This Month: $ Target: $400
 0% 

Stupid menu, heeelp


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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