←  Problemy

AMXX.pl: Support AMX Mod X i SourceMod

»

nVault Top 15 czasem dubluje wpisy

  • +
  • -
Żuk - zdjęcie Żuk 09.09.2019

Spoiler

 

Czy jest ktoś w stanie stwierdzić z jakiego powodu potrafi się zdublować np. statystyka z top1 dla gracza, który wejdzie na serwer na całkowicie innym nicku, ip oraz steamid niż gracz, który jest w top1 i czy jakoś można temu zaradzić?

 

 

 

Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 09.09.2019

Wstaw kod poprawnie, bo spłaszczyło go i wyglada jak kupa.

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 09.09.2019

Jak spłaszczyło? U mnie wszystko jest ok.

#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[MAX_PLAYERS + 1][33];
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; 
}
Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 09.09.2019

Nom, wcięc nie ma kompletnie. proszę przeformatować kod, bo naprawdę nie da się tego czytać

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 09.09.2019

#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[MAX_PLAYERS + 1][33];
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; 
}  

a teraz? to jest jakiś problem u was na forum tzn. jak kopiuje kod z wcięciami tutaj z forum to po wklejeniu ich nie ma, z innych for po skopiowaniu lub bezpośrednio z .sma jest ok

Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 10.09.2019

hmmm, może jakaś rozbieżność tu:

enum PlayerData
{
    PlayerName[ 32 ],
    XP
}

new pdData[ MAX_PLAYERS + 1 ][ PlayerData ];
//new g_AuthID[ MAX_PLAYERS + 1 ][ 34 ];
new g_Name[MAX_PLAYERS + 1][33];

Masz strukture przechowującą nick gracza, a tworzysz tablice z nickami

 

 

A sprawdzałeś może czy problem jest tylko w wyświetlaniu, czy też wadliwy wpis jest fizycznie w pliku

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 12.09.2019

Tak tylko jedno służy do wyświetlania nicków w top, a drugie do zapisu na nick.

//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 ) );

chyba pobiera staty prosto z pliku czy się mylę? wiec musi tam byc ten wpis? Raczej zrobie zapis only steam zamiast się męczyć. Ns i tak mało co gra :P


Użytkownik Żuk edytował ten post 12.09.2019 17:15
Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 12.09.2019

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[] ) );
    }
}

w authorized pobierasz do g_name i tego uzywasz potem do zapisu, tylko że gracz moze zmienic nick podczas gry. i tego nie wychwycisz. 

 

w authorized pobieraj nick do pdData tak jak jest to w client_disconnected, g_name wywal calkiem bo nie jest potrzebna. topka uzywa nicku wczytanego z nvault

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 12.09.2019

Sprawdze tyle, że test może potrwać dość długo bo nie wiadomo kiedy się zbuguje lub i nie także dam znać :P

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 14.09.2019

Okej, to nie działa kompletnie. Musi być to zrobione tak jak miałem, ale jak nie wiadomo czemu się zbugowała topka (zdublował mi się 1-szy wynik) to zrobię zapis only steam bez brania pod uwage ns bo innej opcji nie widze :P

Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 14.09.2019

Czemu nie działa?

Odpowiedz

  • +
  • -
Żuk - zdjęcie Żuk 15.09.2019

Tylko 1 osoba była w top ze wszystkimi statystykami 0 0 0 0.

Odpowiedz

  • +
  • -
Rivit - zdjęcie Rivit 15.09.2019

Coś musiałeś zmaścić :P

 

Można by też  coś takiego, że jak gracz zmienia nick to zapisać staty pod aktualnym nickiem, wyzerowac i wczytać z nowego nicku, ale to juz jak wolisz :P

Odpowiedz