More simple way of doing this?
#1

pawn Code:
forward UpdateXPMeter ( playerid );
public UpdateXPMeter ( playerid )
{
    switch ( accInfo [ playerid ] [ Experience ] )
    {
        case 0:
        {
            for( new n; n < MAX_LEVEL_STAGES; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], -1 );
            }
        }
        case 1:
        {
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 0 ], 16777215 );

            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 1 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 2 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 3 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 4 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 5 ], -1 );
        }
        case 2:
        {
            for( new n; n < 2; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], 16777215 );
            }

            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 2 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 3 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 4 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 5 ], -1 );
        }
        case 3:
        {
            for( new n; n < 3; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], 16777215 );
            }
           
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 3 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 4 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 5 ], -1 );
        }
        case 4:
        {
            for( new n; n < 4; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], 16777215 );
            }

            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 4 ], -1 );
            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 5 ], -1 );
        }
        case 5:
        {
            for( new n; n < 5; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], 16777215 );
            }

            PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ 5 ], -1 );
        }
        case MAX_LEVEL_STAGES: // Otherwise known as '6'
        {
            for( new n; n < MAX_LEVEL_STAGES; n ++ )
            {
                PlayerTextDrawColor( playerid, XPLVL [ playerid ] [ n ], 16777215 );
            }
        }
    }
    return true;
}
Anyone have an idea?
Reply
#2

You would actually reduce it by 3 lines if you use if statements instead of switch and case.
Yet switch looks more neater and they claim it's faster.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)