Quote:
Originally Posted by Meelo
How to check position in top? I want to make command like /rank but with this top and my own stats all works but i can't get player position.
|
It's not very efficient, especially when you have a lot of records in your vault...I recommend SQL. Only quickly tested.
PHP Code:
public GetRank( id )
{
enum _:Top15Info
{
nVault_Offset,
XP_Value
}
static iSortData[ Max_Player_Support ][ Top15Info ];
new iVault , iRow , iCount , iNextOffset , iCurrentOffset , szKey[ 45 ] , pdVal[ PlayerData ] , bool:bRanked;
//Close and re-open vault so the journal writes to the vault so nvault_util gets most up to date data.
nvault_close( g_Vault );
g_Vault = nvault_open( VaultName );
//Open vault for nvault utility usage.
iVault = nvault_util_open( VaultName );
//Get count of total number of records in the vault.
iCount = nvault_util_count( iVault );
//Loop through all records in the vault.
for ( iRow = 0 ; iRow < iCount && iRow < Max_Player_Support ; iRow++ )
{
//Read record from vault. iNextOffset will hold the position of the next record in the vault.
iNextOffset = nvault_util_read_array( iVault , iNextOffset , szKey , charsmax( szKey ) , pdVal[ PlayerData:0 ] , sizeof( pdVal ) );
//Set nVault_Offset to the byte offset for this players data. This will allow for retrieving any data for this player that needs to appear in the top 15 (name, steam id, etc.)
//iPrevOffset is used since iOffset holds the position of the NEXT record, not current.
iSortData[ iRow ][ nVault_Offset ] = iCurrentOffset;
//Set Player_XP value in array to his XP value. This will be used for sorting.
iSortData[ iRow ][ XP_Value ] = pdVal[ XP ];
//Since nvault_util_read_array() holds the position of the next record, we have to hold the current offset separately.
iCurrentOffset = iNextOffset;
}
//Sort the array.
SortCustom2D( iSortData , min( iCount , Max_Player_Support ) , "CompareXP" );
//Cycle through all records in the vault to see where the player stands in ranking
for ( iRow = 0 ; iRow < iCount ; iRow++ )
{
//Get nVault player data offset value which was set in the above loop.
iCurrentOffset = iSortData[ iRow ][ nVault_Offset ];
//Read data at the players offset so we can get their steam id and compare to player requesting their rank.
nvault_util_read_array( iVault , iCurrentOffset , szKey , charsmax( szKey ) , pdVal[ PlayerData:0 ] , sizeof( pdVal ) );
if ( equal( g_AuthID[ id ] , szKey ) )
{
client_print( id , print_chat , "* Your rank is %d" , iRow + 1 );
bRanked = true;
break;
}
}
if ( !bRanked )
{
client_print( id , print_chat , "* You are not yet ranked" );
}
//Close nvault utility file.
nvault_util_close( iVault );
return PLUGIN_HANDLED;
}
__________________