/* Plugin generated by AMXX-Studio */
//PENGUEN
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fvault>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "penguen"
#define is_valid_player(%1) (0<%1<=32)
#define TASKID 998877
#define SAVETIME 10.0
#define MAX_LEVEL 32
#define KILL_EXP 20
#define EXPRATE 100
#define FIRSTEXP 200
new gExp[ 33 ];
new gLevel[ 33 ];
new bool: bPlayerConnected[ 33 ];
new Array: gArrayData;
new const Data[] = "ExpLevel-Top15";
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd( "say /topr", "cmdShowTopLevels" );
register_event( "DeathMsg", "evDeathMsg", "a" );
gArrayData = ArrayCreate( 32 );
set_task( 5.0, "taskControl", TASKID, "", 0, "b" );
}
public taskControl( )
{
static size, i, szKey[ 32 ], szData[ 32 ], szData2[ 2 ][ 32 ];
size = fvault_size( Data );
ArrayClear( gArrayData );
for( i = 0; i < size; i++ ) {
fvault_get_keyname( Data, i, szKey, charsmax( szKey ) );
fvault_get_data( Data, szKey, szData, charsmax( szData ) );
parse( szData, szData2[ 0 ], charsmax( szData2[] ), szData2[ 1 ], charsmax( szData2[] ) );
format( szData, charsmax( szData ), "%s %d %d", szKey, str_to_num( szData2[ 0 ] ), str_to_num( szData2[ 1 ] ) );
ArrayPushString( gArrayData, szData );
}
ArraySort( gArrayData, "stats_custom_compare" );
}
public plugin_cfg()
{
fvault_load( Data );
taskControl()
}
public plugin_end()
{
remove_task( TASKID );
ArrayDestroy( gArrayData );
}
public stats_custom_compare( Array:array, item1, item2 )
{
static szData[ 64 ], szKeyData[ 32 ], szItemData[ 2 ][ 32 ], iData[ 2 ];
ArrayGetString( gArrayData, item1, szData, charsmax( szData ) );
parse( szData, szKeyData, charsmax( szKeyData ), szItemData[ 0 ], charsmax( szItemData[] ), szItemData[ 1 ], charsmax( szItemData[] ) );
iData[ 0 ] = 1000 * ( str_to_num( szItemData[ 0 ] ) ) + str_to_num( szItemData[ 1 ] );
//
ArrayGetString( gArrayData, item2, szData, charsmax( szData ) );
parse( szData, szKeyData, charsmax( szKeyData ), szItemData[ 0 ], charsmax( szItemData[] ), szItemData[ 1 ], charsmax( szItemData[] ) );
iData[ 1 ] = 1000 * ( str_to_num( szItemData[ 0 ] ) ) + str_to_num( szItemData[ 1 ] );
return iData[ 1 ] - iData[ 0 ];
}
public client_connect( id )
{
new szData[ 32 ], szName[ 32 ], szData2[ 2 ][ 32 ];
get_user_name( id, szName, charsmax( szName ) );
if( fvault_get_data( Data, szName, szData, charsmax( szData ) ) ) {
parse( szData, szData2[ 0 ], charsmax( szData2[] ), szData2[ 1 ], charsmax( szData2[] ) );
gExp[ id ] = str_to_num( szData2[ 0 ] );
gLevel[ id ] = str_to_num( szData2[ 1 ] );
}
else {
gExp[ id ] = 0;
gLevel[ id ] = 1;
}
bPlayerConnected[ id ] = true;
}
public client_disconnect( id )
{
Saveit( id )
gExp[ id ] = 0;
gLevel[ id ] = 0;
bPlayerConnected[ id ] = false;
}
public Saveit( id )
{
new szData[ 32 ], szName[ 32 ];
get_user_name( id, szName, charsmax( szName ) );
format( szData, charsmax( szData ), "%d %d", gExp[ id ], gLevel[ id ] );
fvault_set_data( Data, szName, szData );
}
public cmdShowTopLevels( id )
{
if( bPlayerConnected[ id ] ) {
static arraysize;
arraysize = ArraySize( gArrayData );
new motd[1024], len
len = format(motd, 1023,"<body bgcolor=#000000><font color=#FFB000><pre>")
len += format(motd[len], 1023-len,"%s %-10s %-10s %s^n", "#", "Oyuncu", "Seviye", "Tecrube" );
static szData[ 64 ], szKeyData[ 32 ], szItemData[ 2 ][ 16 ];
new b = clamp( arraysize, 0, 15 );
for( new i = 0; i < b; i++ ) {
ArrayGetString( gArrayData, i, szData, charsmax( szData ) );
parse( szData, szKeyData, charsmax( szKeyData ), szItemData[ 0 ], charsmax( szItemData[] ), szItemData[ 1 ], charsmax( szItemData[] ) );
len += format(motd[len], 1023-len,"%d %-10s %-10s %s^n", i+1, szKeyData, szItemData[ 1 ], szItemData[ 0 ] )
}
len += format(motd[len], 1023-len,"</body></font></pre>")
show_motd(id, motd, "Exp-Level Top 15")
}
return PLUGIN_CONTINUE;
}
public client_PreThink( id )
{
if( !bPlayerConnected[ id ] )
return PLUGIN_HANDLED;
static Float: fGameTime[ 32 ], bool: bOkay[ 32 ];
if( !bOkay[ id ] ) {
fGameTime[ id ] = get_gametime();
bOkay[ id ] = true;
}
if( get_gametime() - fGameTime[ id ] >= SAVETIME && bOkay[ id ] ) {
Saveit( id );
fGameTime[ id ] = 0.0;
bOkay[ id ] = false;
}
set_hudmessage( 255, 0, 0, 0.62, 0.92, 1, 6.0, 3.0, 0.1, 0.1 );
show_hudmessage( id, "Tecrube : [%d] || Seviye : [%d]", gExp[ id ], gLevel[ id ] );
return PLUGIN_CONTINUE;
}
public evDeathMsg()
{
new victim, attacker;
attacker = read_data( 1 );
victim = read_data( 2 );
if( is_valid_player( attacker ) && is_valid_player( victim ) ) {
if( attacker != victim ) {
if( gLevel[ attacker ] >= MAX_LEVEL ) return;
if( !bPlayerConnected[ attacker ] ) return;
gExp[ attacker ] += KILL_EXP;
if( gExp[ attacker ] >= ( FIRSTEXP + ( gLevel[ attacker ] * EXPRATE ) ) ) {
gLevel[ attacker ]++;
gExp[ attacker ] = 0;
}
}
}
}