#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < hamsandwich >
#include < ColorChat >
#include < csx >
#include < cstrike >
//#pragma semicolon 1
#define ADMIN_ACCESS ADMIN_IMMUNITY
#define is_user_player(%1) ( 1 <= %1 <= g_MaxPlayers )
#define PLUGIN_NAME "Sistem de puncte"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "A Demon God"
new const g_szTag[ ] = "[M3S]";
new const szWriteCvarsPoints[ ] = "addons/amxmodx/configs/points/points.cfg";
new const szLocationPoints[ ] = "addons/amxmodx/configs/points";
const PEV_SPEC_TARGET = pev_iuser2;
new g_iUserPoints[ 33 ];
new File[ 128 ];
enum _:iCvars {
EnableBombEvents,
PointsPerHS,
PointsBombPlanted,
PointsBombExploded,
PointsBombDefused,
AddPointsNewRound,
};
new g_iCvar[ iCvars ];
#define INFO_ZERO 0
#define NTOP 15
#define TIME 60.0
new toppoints[33],topnames[33][33],topauth[33][33],Data[64];
public plugin_init( )
{
register_plugin( PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR );
register_event( "DeathMsg", "event_DeathMsg", "a" );
register_clcmd( "say /skill", "ClCmdSayPoints");
register_clcmd( "say_team /skill", "ClCmdSayPoints");
register_clcmd( "say /showskill", "ClCmdSayPointsAll");
register_clcmd( "say_team /showskill", "ClCmdSayPointsAll");
register_clcmd( "say /puncte", "TopPUNCTE");
register_clcmd( "say_team /puncte", "TopPUNCTE");
g_iCvar[ EnableBombEvents ] = register_cvar( "points_bombevents_rewards", "1" );
g_iCvar[ PointsPerHS ] = register_cvar( "points_per_headshot", "2" );
g_iCvar[ PointsBombPlanted ] = register_cvar( "points_bomb_planted", "1" );
g_iCvar[ PointsBombExploded ] = register_cvar( "points_bomb_exploded", "1" );
g_iCvar[ PointsBombDefused ] = register_cvar( "points_bomb_defused", "1" );
new DataDir[ 64 ];
get_datadir( DataDir, 63 );
format( File, 127, "%s/Puncte.dat", DataDir );
get_datadir(Data, 63);
read_top();
}
public plugin_precache( )
{
server_cmd( "exec %s", szWriteCvarsPoints );
if( !dir_exists( szLocationPoints ) )
mkdir( szLocationPoints );
if( !file_exists( szWriteCvarsPoints ) ) {
write_file( szWriteCvarsPoints, "// In acest fisier se afla cvar-urile legate despre puncte:");
write_file( szWriteCvarsPoints, " ");
write_file( szWriteCvarsPoints, "points_bombevents_rewards ^"1^" // 0: Dezactivat | 1: Activat -> Puncte obtinute pe plantarea/dezamorsarea/explodearea bombei" );
write_file( szWriteCvarsPoints, "points_per_headshot ^"2^" // Cate puncte sa primesti pe HeadShot !" );
write_file( szWriteCvarsPoints, "points_bomb_planted ^"1^" // Cate puncte sa primesti pe plantarea bombei" );
write_file( szWriteCvarsPoints, "points_bomb_exploded ^"1^" // Cate puncte sa primesti pe explodarea bombei" );
write_file( szWriteCvarsPoints, "points_bomb_defused ^"1^" // Cate puncte sa primesti pe dezamorsarea bombei" );
}
}
public plugin_natives()
{
register_native( "get_user_points", "native_get_user_points", 1 );
register_native( "set_user_points", "native_set_user_points", 1 );
}
public native_get_user_points( id )
{
if(is_user_steam(id))
{
return g_iUserPoints[ id ];
}
return PLUGIN_CONTINUE;
}
public native_set_user_points( id, points )
{
if(is_user_steam(id))
{
g_iUserPoints[ id ] = points;
}
return PLUGIN_CONTINUE;
}
public client_putinserver( id )
{
if(is_user_steam(id))
{
LoadUserPoints( id );
}
if(!is_user_bot(id)) {
set_task(TIME,"RefreshTime",id,_,_,"b",0);
}
return PLUGIN_CONTINUE;
}
public RefreshTime(id) {
checkandupdatetop(id,g_iUserPoints[id]);
return PLUGIN_HANDLED;
}
public client_disconnect( id )
{
if(is_user_steam(id))
{
SaveUserPoints( id );
}
return PLUGIN_CONTINUE;
}
public save_top() {
new path[128];
formatex(path, 127, "%s/TopPuncte.dat", Data);
if( file_exists(path) ) {
delete_file(path);
}
new Buffer[256];
new f = fopen(path, "at");
for(new i = INFO_ZERO; i < NTOP; i++)
{
formatex(Buffer, 255, "^"%s^" ^"%s^" ^"%d^"^n",topnames,topauth, toppoints );
fputs(f, Buffer);
}
fclose(f);
}
public checkandupdatetop(id, points) {
new authid[35],name[32];
get_user_name(id, name, 31);
get_user_authid(id, authid ,34);
for (new i = INFO_ZERO; i < NTOP; i++)
{
if( points > toppoints)
{
new pos = i;
while( !equal(topnames[pos],name) && pos < NTOP )
{
pos++;
}
for (new j = pos; j > i; j--)
{
formatex(topauth[j], 31, topauth[j-1]);
formatex(topnames[j], 31, topnames[j-1]);
toppoints[j] = toppoints[j-1];
}
formatex(topauth, 31, authid);
formatex(topnames, 31, name);
toppoints= points;
ColorChat(0, BLUE,"^4%s^3 %s^1 este pe locul^4 %i^1 in Top Puncte, cu^3 %d^1 punct%s.", g_szTag, name,(i+1),points,points == 1 ? "" : "e");
save_top();
break;
}
else if( equal(topnames, name))
break;
}
}
public read_top() {
new Buffer[256],path[128];
formatex(path, 127, "%s/TopPuncte.dat", Data);
new f = fopen(path, "rt" ),i = INFO_ZERO;
while( !feof(f) && i < NTOP+1)
{
fgets(f, Buffer, 255);
new points[25];
parse(Buffer, topnames, 31, topauth, 31, points, 25);
toppoints[i]= str_to_num(points);
i++;
}
fclose(f);
}
public TopPUNCTE(id)
{
new loc1 = get_statsnum();
new loc2 = get_statsnum();
new loc3 = get_statsnum();
new loc4 = get_statsnum();
new loc5 = get_statsnum();
new loc6 = get_statsnum();
new loc7 = get_statsnum();
new loc8 = get_statsnum();
new iMax = get_statsnum();
static buffer[2368], name[135], len=0;
len = format(buffer, 2367-len,"<STYLE>body{background:#232323;color:#cfcbc2;font-family:sans-serif}table{border-style:solid;border-width:1px;border-color:#FFFFFF;font-size:13px}</STYLE><table align=center width=100%% cellpadding=2 cellspacing=0");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#52697B><th width=4%% > # <th width=24%%> Nume Jucator <th width=24%%>SteamID <th width=24%%> Puncte");
if(iMax>NTOP) iMax=NTOP
loc1=1
loc2=2
loc3=3
loc4=4
loc5=5
loc6=6
loc7=7
loc8=8
for (new i = 0; i < loc1 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=red> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 1; i < loc2 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=blue> %s </font><td> %s<td> %d</font>", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 2; i < loc3 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=yellow> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 3; i < loc4 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=orange> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 4; i < loc5 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=pink> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 5; i < loc6 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=purple> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 6; i < loc7 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=green> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 7; i < loc8 && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td><font color=violet> %s </font><td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
for (new i = 8; i < iMax && 2367-len > 0; i++)
{
if( toppoints[i] == 0) {
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s", (i+1), "-", "-", "-");
//i = NTOP
}
else
{
name = topnames[i];
while( containi(name, "<") != -1 ) replace(name, 31, "<", "<");
while( containi(name, ">") != -1 ) replace(name, 31, ">", ">");
len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td> %s <td> %s<td> %d", (i+1), name,topauth[i], toppoints[i]);
}
}
len += format(buffer[len], 2367-len, "</table>");
//len += format(buffer[len], 2367-len, "<tr align=bottom font-size:11px><Center><br><br>Primii %d Jucatori Cu Cele Mai Multe Puncte Acumulate</Center>",NTOP);
static strin[125];
format(strin,124, "Top %d PUNCTE",NTOP);
show_motd(id, buffer, strin);
}
public event_DeathMsg( )
{
new iKiller = read_data( 1 );
new iVictim = read_data( 2 );
new iHeadshot = read_data( 3 );
if(is_user_steamk(iKiller))
{
if( !is_user_connected( iKiller ) || !is_user_connected( iVictim ) )
{
return 0;
}
if( iKiller == iVictim )
{
return 0;
}
if( iHeadshot )
{
g_iUserPoints[iKiller] += get_pcvar_num( g_iCvar[ PointsPerHS ] );
if(is_user_steamv(iVictim))
{
g_iUserPoints[iVictim] -= 2;
}
}
else
{
g_iUserPoints[iKiller]++;
if(is_user_steamv(iVictim))
{
g_iUserPoints[iVictim]--;
}
}
}
return 1;
}
public ClCmdSayPoints( id )
{
if(is_user_steam(id))
{
ColorChat( id, TEAM_COLOR, "^x04%s^x01 Ai %i puncte", g_szTag, g_iUserPoints[id]);
}
else
{
ColorChat(id, TEAM_COLOR, "^x04%s^x01 Nu ai^x03 Steam^x01 acest sistem este doar steam only.", g_szTag);
}
return PLUGIN_CONTINUE;
}
public ClCmdSayPointsAll( id )
{
if(is_user_steam(id))
{
ColorChat(0, TEAM_COLOR, "^x04%s^x01 %s are %i puncte, Skill:^x03 Silver II", g_szTag, get_name(id), g_iUserPoints[id]);
}
else
{
ColorChat(id, TEAM_COLOR, "^x04%s^x01 Nu ai^x03 Steam^x01 acest sistem este doar steam only.", g_szTag);
}
return PLUGIN_CONTINUE;
}
public bomb_planted( id )
{
if(is_user_steam(id))
{
if( get_pcvar_num( g_iCvar[ EnableBombEvents ] ) == 0 || !is_user_connected( id ) )
return PLUGIN_CONTINUE;
g_iUserPoints[ id ] += get_pcvar_num( g_iCvar[ PointsBombPlanted ] );
}
return PLUGIN_CONTINUE;
}
public bomb_explode( id )
{
if(is_user_steam(id))
{
if( get_pcvar_num( g_iCvar[ EnableBombEvents ] ) == 0 || !is_user_connected( id ) )
return PLUGIN_CONTINUE;
g_iUserPoints[ id ] += get_pcvar_num( g_iCvar[ PointsBombExploded ] );
}
return PLUGIN_CONTINUE;
}
public bomb_defused( id )
{
if(is_user_steam(id))
{
if( get_pcvar_num( g_iCvar[ EnableBombEvents ] ) == 0 || !is_user_connected( id ) )
return PLUGIN_CONTINUE;
g_iUserPoints[ id ] += get_pcvar_num( g_iCvar[ PointsBombDefused ] );
}
return PLUGIN_CONTINUE;
}
public SaveUserPoints( id )
{
new AuthID[ 32 ];
get_user_name( id , AuthID , 31 ) ;
static Data[ 1024 ];
formatex( Data, sizeof( Data ) - 1, "^"%i^"", g_iUserPoints[ id ] );
new Save[ 512 ];
format( Save, 511, "^"%s^" %s", AuthID, Data );
new Line[ 128 ], Linie, IsPlayer = false, Arg1[ 32 ];
new FileOpen = fopen( File, "rt" );
while( !feof( FileOpen ) ) {
fgets( FileOpen, Line, 127 );
trim( Line );
parse( Line, Arg1, 31 );
if( equali( Arg1, AuthID ) ) {
write_file( File, Save, Linie );
IsPlayer = true;
break;
}
Linie++;
}
fclose( FileOpen );
if( !IsPlayer )
{
write_file( File, Save, -1 );
}
}
public LoadUserPoints( id )
{
new AuthID[ 32 ];
get_user_name( id , AuthID , 31 ) ;
new Line[ 128 ], IsPlayer = false, Arg1[ 32 ], Arg2[ 32 ];
new FileOpen = fopen( File, "rt" );
while( !feof( FileOpen ) ) {
fgets( FileOpen, Line, 127 );
trim( Line );
parse( Line, Arg1, 31, Arg2, 31 );
if( equali( Arg1, AuthID ) ) {
g_iUserPoints[ id ] = str_to_num( Arg2 );
IsPlayer = true;
break;
}
}
fclose( FileOpen );
if( !IsPlayer )
{
g_iUserPoints[ id ] = 1;
}
}
stock get_name( id )
{
new szName[ 32 ];
get_user_name( id, szName, sizeof ( szName ) -1 );
return szName;
}
stock bool:is_user_vip( id )
{
if( get_user_flags( id ) & read_flags( "h" ) )
return true;
return false;
}
stock bool:is_user_steam(id)
{
static dp_pointer;
if (dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", id);
server_exec();
return (get_pcvar_num(dp_pointer) == 2) ? true : false;
}
return false;
}
stock bool:is_user_steamk(iKiller)
{
static dp_pointer;
if (dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", iKiller);
server_exec();
return (get_pcvar_num(dp_pointer) == 2) ? true : false;
}
return false;
}
stock bool:is_user_steamv(iVictim)
{
static dp_pointer;
if (dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", iVictim);
server_exec();
return (get_pcvar_num(dp_pointer) == 2) ? true : false;
}
return false;
}