View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-31-2019 , 20:52   Re: [TUT] nVault Top 15
Reply With Quote #10

Quote:
Originally Posted by Meelo View Post
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 GetRankid )
{
    
enum _:Top15Info
    
{
        
nVault_Offset,
        
XP_Value
    
}
    
    static 
iSortDataMax_Player_Support ][ Top15Info ];
    
    new 
iVault iRow iCount iNextOffset iCurrentOffset szKey45 ] , pdValPlayerData ] , bool:bRanked;
    
    
//Close and re-open vault so the journal writes to the vault so nvault_util gets most up to date data.
    
nvault_closeg_Vault );
    
g_Vault nvault_openVaultName );
    
    
//Open vault for nvault utility usage.
    
iVault nvault_util_openVaultName );
    
    
//Get count of total number of records in the vault.
    
iCount nvault_util_countiVault );
    
    
//Loop through all records in the vault.
    
for ( iRow 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_arrayiVault iNextOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
        
//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.
        
iSortDataiRow ][ nVault_Offset ] = iCurrentOffset;
        
        
//Set Player_XP value in array to his XP value. This will be used for sorting.
        
iSortDataiRow ][ XP_Value ] = pdValXP ];
        
        
//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.
    
SortCustom2DiSortData miniCount Max_Player_Support ) , "CompareXP" );
    
    
//Cycle through all records in the vault to see where the player stands in ranking
    
for ( iRow iRow iCount iRow++ )
    {
        
//Get nVault player data offset value which was set in the above loop.
        
iCurrentOffset iSortDataiRow ][ 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_arrayiVault iCurrentOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
        if ( 
equalg_AuthIDid ] , szKey ) )
        {
            
client_printid print_chat "* Your rank is %d" iRow );
            
bRanked true;
            break;
        }
    
    }
    
    if ( !
bRanked )
    {
        
client_printid print_chat "* You are not yet ranked" );
    }
    
    
//Close nvault utility file.
    
nvault_util_closeiVault );
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 08-01-2019 at 19:01.
Bugsy is offline