Raised This Month: $32 Target: $400
 8% 

[TUT] nVault Top 15


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2019 , 08:42   Re: [TUT] nVault Top 15
Reply With Quote #21

I would need to see your full code
__________________
Bugsy is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 11-21-2019 , 13:34   Re: [TUT] nVault Top 15
Reply With Quote #22

Quote:
Originally Posted by Bugsy View Post
I would need to see your full code
PHP Code:
#include <amxmodx>
#include <nvault>
#include <nvault_util>
#include <nvault_array>
#include <hamsandwich>
#include <zombieplague>

#pragma dynamic 16384

#define MAX_PLAYERS 32


enum PlayerData
{
    
PlayerName[32],
    
kills,
    
deaths,
    
damage,
    
hits
}

const 
MaxPlayerSupport 3000

new pdData[MAX_PLAYERS 1][ PlayerData ]
new 
g_AuthID[MAX_PLAYERS 1][34]
new 
bool:g_BotOrHLTV[MAX_PLAYERS 1]

new 
g_Vault
new const VaultName[] = "stats_113"

public plugin_init()
{
    
register_plugin("stats""1.0""")

    
RegisterHam(Ham_TakeDamage"player""fw_HamTakeDamage");
    
register_clcmd("say /test""ShowTop")
    
register_clcmd("say /testinfo""ShowStats")


    if ( ( 
g_Vault nvault_openVaultName ) ) == INVALID_HANDLE )
    {
        
set_fail_state"Failed to open vault" );
    }
}

public 
plugin_end()
    
nvault_close(g_Vault)

public 
client_authorized(id)
{
    if ( !( 
g_BotOrHLTVid ] = bool:( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
get_user_authididg_AuthIDid ], charsmaxg_AuthID[] ) )
        
nvault_get_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[] ) );
    }
}
public 
client_disconnect(id)
{
    if( !
g_BotOrHLTVid ])
    {
        
get_user_nameid pdDataid ][ PlayerName ], charsmaxpdData[][ PlayerName ] ) )
        
nvault_set_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[] ) );
    }
}

public 
zp_user_infected(idattacker)
{
    if(
zp_get_user_first_zombie(id))
        return;
    
    
pdData[id][deaths]++
    if(
is_user_alive(attacker) && attacker != id)
        
pdData[attacker][kills]++
}

public 
fw_HamTakeDamage(victiminflictorattackerFloat:fDamagem_Damagebits )
{
    if(
is_user_alive(attacker) && attacker != victim)
    {
        
pdData[attacker][damage] += floatround(fDamage)
        
pdData[attacker][hits]++
    }
}

public 
ShowStats(id)
{
    if(!
is_user_connected(id))
        return;

    
client_print(idprint_chat"You have %i Kills, %i Deaths, %d Damage, %i Hits"pdData[id][kills], pdData[id][deaths], pdData[id][damage], pdData[id][hits])
}

public 
ShowTop(id)
{
    
enum _:Info
    
{
        
nVaultOffset,
        
iKills,
        
iDeaths,
        
iDamage,
        
iHits
    
}

    static 
iSortData[MaxPlayerSupport][Info]

    new 
iVault iRow iCount iNextOffset iCurrentOffset szKey45 ] , iAvailablePlayers pdValPlayerData ];
    new 
szMOTD2128 ] , iPos

    nvault_close
g_Vault );
    
g_Vault nvault_openVaultName );

    
iVault nvault_util_open(VaultName)
    
iCount nvault_util_count(iVault)

    for ( 
iRow iRow iCount && iRow MaxPlayerSupport iRow++ )
    {
        
iNextOffset nvault_util_read_arrayiVault iNextOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
iSortDataiRow ][ nVaultOffset ] = iCurrentOffset;
        
iSortDataiRow ][ iKills ] = pdValkills ];
        
iSortDataiRow ][ iDeaths ] = pdValdeaths ];
        
iSortDataiRow ][ iDamage ] = pdValdamage ];
        
iSortDataiRow ][ iHits ] = pdValhits ];

        
iCurrentOffset iNextOffset;
    }

    
SortCustom2DiSortData miniCount MaxPlayerSupport ) , "CompareStats" );
    
iPos formatexszMOTD charsmaxszMOTD ) , "<body bgcolor=#000000><font color=#98f5ff><pre>" );
    
iPos += formatexszMOTDiPos ] , charsmaxszMOTD ) - iPos "%2s %-22.22s %3s %3s %3s %3s^n" "#" "  Name " " Kills "" Deaths "" Damage "" Hits ")
    
iAvailablePlayers miniCount 15 );

    for ( 
iRow iRow iAvailablePlayers iRow++ )
    {
        
iCurrentOffset iSortDataiRow ][ nVaultOffset ];
        
nvault_util_read_arrayiVault iCurrentOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
iPos += formatexszMOTDiPos ] , charsmaxszMOTD ) - iPos ,"%2d  %-22.22s   %3d   %3d   %3d   %3d^n", ( iRow ) , pdValPlayerName ] , pdValkills ], pdVal[deaths], pdVal[damage], pdVal[hits] );
    }
    
nvault_util_closeiVault );
    
formatexszMOTDiPos ], charsmaxszMOTD ) - iPos "</body></font></pre>" );
    
show_motdid szMOTD "ZP Stats" );
    return 
PLUGIN_HANDLED;
}

public 
CompareStatselem1[] , elem2[] ) 

    if ( 
elem1] > elem2] ) 
        return -
1
    else if(
elem1] < elem2] ) 
        return 
1
    
    return 
0

ZaX is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2019 , 17:42   Re: [TUT] nVault Top 15
Reply With Quote #23

The way it was designed stores only their score and nvault file offset in the iSortData array (which is 2 dimensions!) that gets sorted by the score value. Once sorted, a loop goes through the results reading the vault data at the offset in the second dimension. This means you can retrieve all data stored for the player in the vault within the for loop after the sort occurs.

Code:
iSortData[ iRow ][ nVaultOffset ] = iCurrentOffset;
iSortData[ iRow ][ iKills ] = pdVal[ kills ];
iSortData[ iRow ][ iDeaths ] = pdVal[ deaths ];
iSortData[ iRow ][ iDamage ] = pdVal[ damage ];
iSortData[ iRow ][ iHits ] = pdVal[ hits ];
iCurrentOffset = iNextOffset; SortCustom2D( iSortData , min( iCount , MaxPlayerSupport ) , "CompareStats" );
__________________

Last edited by Bugsy; 11-21-2019 at 18:16.
Bugsy is offline
ivani6651
Member
Join Date: Feb 2017
Old 11-30-2019 , 11:53   Re: [TUT] nVault Top 15
Reply With Quote #24

@Bugsy Can you help with this code? Does not count and save stats in top15 (kills, deaths). Will you be able to fix it?
PHP Code:
#include <amxmodx>
#include <nvault>
#include <nvault_util>
#include <nvault_array>
#include <hamsandwich>
#include <zombieplague>

#pragma dynamic 16384

#define MAX_PLAYERS 32


enum PlayerData
{
    
PlayerName[32],
    
kills,
    
deaths,
    
damage,
    
hits
}

const 
MaxPlayerSupport 3000

new pdData[MAX_PLAYERS 1][ PlayerData ]
new 
g_AuthID[MAX_PLAYERS 1][34]
new 
bool:g_BotOrHLTV[MAX_PLAYERS 1]

new 
g_Vault
new const VaultName[] = "stats_113"

public plugin_init()
{
    
register_plugin("stats""1.0""")

    
RegisterHam(Ham_TakeDamage"player""fw_HamTakeDamage");
    
register_clcmd("say /test""ShowTop")
    
register_clcmd("say /testinfo""ShowStats")


    if ( ( 
g_Vault nvault_openVaultName ) ) == INVALID_HANDLE )
    {
        
set_fail_state"Failed to open vault" );
    }
}

public 
plugin_end()
    
nvault_close(g_Vault)

public 
client_authorized(id)
{
    if ( !( 
g_BotOrHLTVid ] = bool:( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
get_user_authididg_AuthIDid ], charsmaxg_AuthID[] ) )
        
nvault_get_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[] ) );
    }
}
public 
client_disconnect(id)
{
    if( !
g_BotOrHLTVid ])
    {
        
get_user_nameid pdDataid ][ PlayerName ], charsmaxpdData[][ PlayerName ] ) )
        
nvault_set_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[] ) );
    }
}

public 
zp_user_infected(idattacker)
{
    if(
zp_get_user_first_zombie(id))
        return;
    
    
pdData[id][deaths]++
    if(
is_user_alive(attacker) && attacker != id)
        
pdData[attacker][kills]++
}

public 
fw_HamTakeDamage(victiminflictorattackerFloat:fDamagem_Damagebits )
{
    if(
is_user_alive(attacker) && attacker != victim)
    {
        
pdData[attacker][damage] += floatround(fDamage)
        
pdData[attacker][hits]++
    }
}

public 
ShowStats(id)
{
    if(!
is_user_connected(id))
        return;

    
client_print(idprint_chat"You have %i Kills, %i Deaths, %d Damage, %i Hits"pdData[id][kills], pdData[id][deaths], pdData[id][damage], pdData[id][hits])
}

public 
ShowTop(id)
{
    
enum _:Info
    
{
        
nVaultOffset,
        
iKills,
        
iDeaths,
        
iDamage,
        
iHits
    
}

    static 
iSortData[MaxPlayerSupport][Info]

    new 
iVault iRow iCount iNextOffset iCurrentOffset szKey45 ] , iAvailablePlayers pdValPlayerData ];
    new 
szMOTD2128 ] , iPos

    nvault_close
g_Vault );
    
g_Vault nvault_openVaultName );

    
iVault nvault_util_open(VaultName)
    
iCount nvault_util_count(iVault)

    for ( 
iRow iRow iCount && iRow MaxPlayerSupport iRow++ )
    {
        
iNextOffset nvault_util_read_arrayiVault iNextOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
iSortDataiRow ][ nVaultOffset ] = iCurrentOffset;
        
iSortDataiRow ][ iKills ] = pdValkills ];
        
iSortDataiRow ][ iDeaths ] = pdValdeaths ];
        
iSortDataiRow ][ iDamage ] = pdValdamage ];
        
iSortDataiRow ][ iHits ] = pdValhits ];

        
iCurrentOffset iNextOffset;
    }

    
SortCustom2DiSortData miniCount MaxPlayerSupport ) , "CompareStats" );
    
iPos formatexszMOTD charsmaxszMOTD ) , "<body bgcolor=#000000><font color=#98f5ff><pre>" );
    
iPos += formatexszMOTDiPos ] , charsmaxszMOTD ) - iPos "%2s %-22.22s %3s %3s %3s %3s^n" "#" "  Name " " Kills "" Deaths "" Damage "" Hits ")
    
iAvailablePlayers miniCount 15 );

    for ( 
iRow iRow iAvailablePlayers iRow++ )
    {
        
iCurrentOffset iSortDataiRow ][ nVaultOffset ];
        
nvault_util_read_arrayiVault iCurrentOffset szKey charsmaxszKey ) , pdValPlayerData:] , sizeofpdVal ) );
        
iPos += formatexszMOTDiPos ] , charsmaxszMOTD ) - iPos ,"%2d  %-22.22s   %3d   %3d   %3d   %3d^n", ( iRow ) , pdValPlayerName ] , pdValkills ], pdVal[deaths], pdVal[damage], pdVal[hits] );
    }
    
nvault_util_closeiVault );
    
formatexszMOTDiPos ], charsmaxszMOTD ) - iPos "</body></font></pre>" );
    
show_motdid szMOTD "ZP Stats" );
    return 
PLUGIN_HANDLED;
}

public 
CompareStatselem1[] , elem2[] ) 

    if ( 
elem1] > elem2] ) 
        return -
1
    else if(
elem1] < elem2] ) 
        return 
1
    
    return 
0


Last edited by ivani6651; 11-30-2019 at 11:54.
ivani6651 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-30-2019 , 12:06   Re: [TUT] nVault Top 15
Reply With Quote #25

You can't change things in my example and expect it to work. As I mentioned above, this is designed to utilize a 2-dimension array. Below, you changed the enumerator for the sort array and are loading it with additional data which this cannot handle.
Code:
//5 dimensions
    enum _:Info
    {
        nVaultOffset,
        iKills,
        iDeaths,
        iDamage,
        iHits
    }
    static iSortData[MaxPlayerSupport][Info]     new iVault , iRow , iCount , iNextOffset , iCurrentOffset , szKey[ 45 ] , iAvailablePlayers , pdVal[ PlayerData ];     new szMOTD[ 2128 ] , iPos     nvault_close( g_Vault );     g_Vault = nvault_open( VaultName );     iVault = nvault_util_open(VaultName)     iCount = nvault_util_count(iVault)     for ( iRow = 0 ; iRow < iCount && iRow < MaxPlayerSupport ; iRow++ )     {         iNextOffset = nvault_util_read_array( iVault , iNextOffset , szKey , charsmax( szKey ) , pdVal[ PlayerData:0 ] , sizeof( pdVal ) );
        iSortData[ iRow ][ nVaultOffset ] = iCurrentOffset;
        iSortData[ iRow ][ iKills ] = pdVal[ kills ];
        iSortData[ iRow ][ iDeaths ] = pdVal[ deaths ];
        iSortData[ iRow ][ iDamage ] = pdVal[ damage ];
        iSortData[ iRow ][ iHits ] = pdVal[ hits ];

Why are you setting all of these additional values in the array to be sorted? If you want to sort or rank based on something other than a single value, you will need to switch back to the enumerator I defined in my example above, and set the XP_Value value accordingly. (kills minus deaths, or whatever you want).

Eg:
Code:
//2 dimensions
enum _:Top15Info {     nVault_Offset,     XP_Value } iSortData[ iRow ][ nVault_Offset ] = iCurrentOffset; //Here you can load the XP_Value with the math you want used for your rank/scoring.
iSortData[ iRow ][ XP_Value ] = pdVal[ kills ] - pdVal[ deaths ];
__________________

Last edited by Bugsy; 12-01-2019 at 01:11.
Bugsy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode