Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

Zmiana zapisu z sid na nick nvault


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
3 odpowiedzi w tym temacie

#1 Żuk

    Wszechwidzący

  • Użytkownik

Reputacja: 11
Początkujący

  • Postów:291
  • Lokalizacja:Katowice
Offline

Napisano 19.08.2019 18:32

Czy taka zmiana będzie działać, czy trzeba coś jeszcze zrobić? Niżej zakomendowałem linie które zmieniłem i pod nimi są te moje. CHodzi o to, że oryginalnie zapis jest na sid, u mnie ns'y maja steam_id_lan i nie zapisuje kazdego z nich z osobna, tylko wszystkie staty sa przypisane do steam_id_lan i w topce robia sie potem problemy

#include <amxmodx>
#include <nvault>
#include <nvault_util>
#include <nvault_array>

//Allocate additional memory to plugin to prevent stack error
#pragma dynamic 16384

new const Version[] = "0.1";

new const VaultName[] = "XP_Top15_Example";

//This determines the max number of players that will be included in your top 15 calculation. It is best to keep this at a 
//value <= the max players that you expect to have data saved in the vault. If the number of player data saved exceeds this
//value then your top 15 will not be accurate since some players will be left out.
const Max_Player_Support = 3000;

//Components of data that will be saved for each player.
enum PlayerData
{
    PlayerName[ 32 ],
    XP
}

new pdData[ MAX_PLAYERS + 1 ][ PlayerData ];
/////new g_AuthID[ MAX_PLAYERS + 1 ][ 34 ];
new g_Name[33][32];
new bool:g_BotOrHLTV[ MAX_PLAYERS + 1 ];
new g_Vault;

//In your plugin, you set a players XP using the below:
//pdData[ id ][ XP ] = 12345;
    
public plugin_init() 
{
    register_plugin( "nVault Top 15" , Version , "bugsy" );
    
    register_clcmd( "say top15" , "ShowTop15" );
    register_clcmd( "say loadtestdata" , "LoadTestData" );
    
    if ( ( g_Vault = nvault_open( VaultName ) ) == INVALID_HANDLE )
    {
        set_fail_state( "Failed to open vault" );
    }
}

public plugin_end() 
{
    nvault_close( g_Vault );
}

public client_authorized( id )
{
    if ( !( g_BotOrHLTV[ id ] = bool:( is_user_bot( id ) || is_user_hltv( id ) ) ) )
    {
        //Get players' steam-id so it can be used to retrieve their data from the vault.
     ///////////////   get_user_authid( id , g_AuthID[ id ] , charsmax( g_AuthID[] ) );
        get_user_name(id, g_Name[id], 32)
        //Retrieve player data from vault. 
    ////////////////  nvault_get_array( g_Vault , g_AuthID[ id ] , pdData[ id ][ PlayerData:0 ] , sizeof( pdData[] ) );
        nvault_get_array( g_Vault , g_Name[ id ] , pdData[ id ][ PlayerData:0 ] , sizeof( pdData[] ) );
    }
}

public client_disconnect( id )
{
    if ( !g_BotOrHLTV[ id ] )
    {
        //To avoid having to monitor for name changes in-game, the players name is retrieved and saved when disconnecting.
        get_user_name( id , pdData[ id ][ PlayerName ] , charsmax( pdData[][ PlayerName ] ) );
        
        //Save player data to vault.
      /////////////  nvault_set_array( g_Vault , g_AuthID[ id ] , pdData[ id ][ PlayerData:0 ] , sizeof( pdData[] ) );
        nvault_set_array( g_Vault , g_Name[ id ] , pdData[ id ][ PlayerData:0 ] , sizeof( pdData[] ) );
    }
}

public ShowTop15( id )
{
    enum _:Top15Info
    {
        nVault_Offset,
        XP_Value
    }
    
    static iSortData[ Max_Player_Support ][ Top15Info ];
    
    new iVault , iRow , iCount , iNextOffset , iCurrentOffset , szKey[ 45 ] , iAvailablePlayers , pdVal[ PlayerData ];
    new szMOTD[ 1501 ] , iPos;
    
    //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" );

    //Prepare top 15 MOTD.
    iPos = formatex( szMOTD , charsmax( szMOTD ) , "<body bgcolor=#000000><font color=#98f5ff><pre>" );
    iPos += formatex( szMOTD[ iPos ] , charsmax( szMOTD ) - iPos , "%2s %-22.22s %3s^n" , "#" , "Name" , "XP" );
    
    //This will account for if the vault has less than 15 player data records stored.
    iAvailablePlayers = min( iCount , 15 );
    
    //Build the top 15. iAvailablePlayers is set to the smaller of 15 or the total records in the vault.
    for ( iRow = 0 ; iRow < iAvailablePlayers ; 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 retrieve their name to be displayed in the top 15.
        nvault_util_read_array( iVault , iCurrentOffset , szKey , charsmax( szKey ) , pdVal[ PlayerData:0 ] , sizeof( pdVal ) );
        
        //Format line in MOTD.
        iPos += formatex( szMOTD[ iPos ] , charsmax( szMOTD ) - iPos ,"%2d %-22.22s %3d^n", ( iRow + 1 ) , pdVal[ PlayerName ] , pdVal[ XP ] );
    }
    
    //Close nvault utility file.
    nvault_util_close( iVault );
    
    formatex( szMOTD[ iPos ], charsmax( szMOTD ) - iPos , "</body></font></pre>" );
    
    show_motd( id , szMOTD , "XP Top 15" );
    
    return PLUGIN_HANDLED;
}

public LoadTestData()
{
    new szAuthID[ 10 ] , pdData[ PlayerData ] , iRow , iXP;
    
    for ( iRow = 0 ; iRow < 100 ; iRow++ )
    {
        formatex( szAuthID , charsmax( szAuthID ) , "STEAM_%d" , iRow );
        
        iXP = random( 9999 );
        
        formatex( pdData[ PlayerName ] , charsmax( pdData[ PlayerName ] ) , "Player_%d [%d]" , iRow , iXP );
        pdData[ XP ] = iXP;
        
        nvault_set_array( g_Vault , szAuthID , pdData[ PlayerData:0 ] , sizeof( pdData ) );
    }
    
    return PLUGIN_HANDLED;
}

public CompareXP( elem1[] , elem2[] ) 
{ 
    if ( elem1[ 1 ] > elem2[ 1 ] ) 
        return -1; 
    else if(elem1[ 1 ] < elem2[ 1 ] ) 
        return 1; 
    
    return 0; 
}  

  • +
  • -
  • 0

#2 Rivit

    Godlike

  • Support Team

Reputacja: 1 319
Godlike

  • Postów:4 380
Offline

Napisano 19.08.2019 20:07

Raczej tak, ale czemu nie sprawdzisz sam zamiast pytać? :D

Generalnie można to było zrobić w taki chamski sposób:

w client_authorized zamienić get_user_auth na get_user_name i tyle, ale twoj sposob tez jest ok


  • +
  • -
  • 1

#3 Żuk

    Wszechwidzący

  • Autor tematu
  • Użytkownik

Reputacja: 11
Początkujący

  • Postów:291
  • Lokalizacja:Katowice
Offline

Napisano 19.08.2019 20:54

Nie mogę bo mam problemy z pc dość spore, a nie mam nikogo ogarniętego kto by to na serwie sprawdził:P wole jak ktoś fachowym okiem oceni kod

 

 

new g_Name[33][32];

 

a nie powinno tam jeszcze być [maxplayers+1] ?


  • +
  • -
  • 0

#4 Rivit

    Godlike

  • Support Team

Reputacja: 1 319
Godlike

  • Postów:4 380
Offline

Napisano 19.08.2019 20:59

nie, ale skoro plugin jest pisany takim stylem to mozesz dac tak:

new g_Name[MAX_PLAYERS + 1][33];

  • +
  • -
  • 0




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych