Here's another method which allows a Min\Max range for each rank. Also included is a SetRank function which will assign a rank to a player based on his XP points.
PHP Code:
//Constants for each rank, easier to use than number ranks
enum Ranks
{
Noob, // 0
Rookie, // 1
Good, // 2
Best, // 3
Pro // 4
}
//XP/point ranges for each rank.
new const RankXP[ Ranks ][ 2 ] =
{
{ 0 , 100 }, //Noob 0-100 pts
{ 101 , 200 }, //Rookie 101-200 pts
{ 201 , 300 }, //Good 201-300 pts
{ 301 , 400 }, //Best 301-400 pts
{ 401 , 999999999 } //Pro 401+ pts
}
//This is used only to print/display the rank a player currently has.
new const RankName[ Ranks ][] =
{
"Noob",
"Rookie",
"Good",
"Best",
"Pro"
}
//Create 2 arrays, g_XP[] is the number of XP points each player has;
//g_PlayerRank is the players current Rank (assigned by SetRank function)
new g_XP[ 33 ] , Ranks:g_PlayerRank[ 33 ];
public SetRank( id )
{
//Loop through all of our ranks (See above enum)
for ( new Ranks:i = Noob ; i <= Pro ; i++ )
{
//Check if player is in current rank, suppose the player had 320 XP pts, this
//condition would be met at Pro rank since the XP range is 301-400.
// if ( 301 <= 320 <= 400 ) would be true so we assign Pro rank to player.
if ( RankXP[ i ][ 0 ] <= g_XP[ id ] <= RankXP[ i ][ 1 ] )
{
g_PlayerRank[ id ] = i;
break;
}
}
client_print( 0 , print_chat , "XP=%d Rank=%s" , g_XP[ id ] , RankName[ g_PlayerRank[ id ] ] );
}
__________________