/*********************USE EXTRA MIRROR Protection SYSTEM*********************/
/*********************mmoru.com/board/showthread.php?t=594787*********************/
/*********************Developed by Zombie-Arena.ru*********************/
/*********************Developed by Zombie-Arena.ru*********************/
#include <amxmodx>
#include <hamsandwich>
#include <zombieplague>
#include <sqlx>
native is_user_admin(id)
enum _:NUMZ{
STARTBY,
NMK,
ZMK,
SRK,
HMK,
KILLS,
DIES,
DAMAGE,
INFECT,
INFECTED,
BENEMESIS,
BESURVIVOR,
BEFIRSTZM
}
new g_UserName[33][32];
new g_Loaded[33];
new const Host[]= "HOST",User[]= "USER",Pass[]= "PASS",Db[]= "DB NAME",Table[]="zp_astats",
AuthRow[]="steam",MoneyRow[]= "user_money",g_szSteam[33][40],g_Total[33][NUMZ];
new Handle:SQL_Tuple;
public plugin_cfg(){
register_plugin("[Zp]ASTATS", "2.1nb", "Shel[Zombie-Arena.ru]");
RegisterHam(Ham_Killed, "player", "fw_HamKilled");
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage", 1);
set_task(15.0, "Load_Debug");
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type){
if(victim == attacker||!is_user_alive(attacker) || !is_user_connected(victim))return;g_Total[attacker][DAMAGE] += floatround(damage);
}
public fw_HamKilled(id, attacker, shouldgib){
if(!is_user_connected(id)||!is_user_connected(attacker))return;g_Total[attacker][KILLS]++;g_Total[id][DIES]++;
if(zp_get_user_nemesis(id)){g_Total[attacker][NMK]++;return;}
else if(zp_get_user_zombie(id)){g_Total[attacker][ZMK]++;return;}
else if(zp_get_user_survivor(id)){g_Total[attacker][SRK]++;return;}
else if(!zp_get_user_zombie(id)){g_Total[attacker][HMK]++;return;}
}
public Load_Debug(){
new g_Error[1];
SQL_Tuple=SQL_MakeDbTuple(Host, User, Pass, Db);
new ErrorCode,Handle:SqlConnection=SQL_Connect(SQL_Tuple,ErrorCode,g_Error,charsmax(g_Error));
if(SqlConnection == Empty_Handle) set_fail_state(g_Error);
SQL_FreeHandle(SqlConnection);
}
public QueryHandler(FailState, Handle:Query, Error[], ErrCode, data[], size, Float:querytime){
if(!CheckQuery(FailState, ErrCode, Error)){SQL_FreeHandle(Query);return 1;}
static id; id=data[0];
if(SQL_NumResults(Query)<1) {
new Query[1024]
format( Query, 1023, "INSERT INTO `%s` ( `%s` , `%s`) VALUES ('%s', '0');", Table, AuthRow, MoneyRow, g_szSteam[id] );
SQL_ThreadQueryFormatNoData(SQL_Tuple, "IgnoreHandle", Query );
}
else{
zp_set_user_ammo_packs(id,0);zp_set_user_ammo_packs(id,SQL_ReadResult(Query, 0));zp_set_user_zombie_class(id,SQL_ReadResult(Query, 1));if(equal(g_szSteam[id],"STEAM_ID_LAN") || equal(g_szSteam[id], "VALVE_ID_LAN"))set_user_money(id, 0);
}
SQL_FreeHandle(Query);g_Loaded[id]=true;return 0;
}
public LoadData(task){
new id=task-73218;
if(!is_user_connected(id)) return;
g_szSteam[id][0]='^0';
set_user_money(id, 0);
get_user_authid(id, g_szSteam[id] ,charsmax(g_szSteam));
g_UserName[id][0]='^0';
get_user_name(id,g_UserName[id],31)
new Query[1024];
static data[1]; data[0]=id;
format( Query, 255, "SELECT `%s`,`zmclass` FROM `%s` WHERE `%s`='%s'",MoneyRow, Table, AuthRow, g_szSteam[id] );
SQL_ThreadQueryFormat(SQL_Tuple,"QueryHandler", Query, data, 1 );
}
public Save_Data(id){
if(!g_Loaded[id])return;
static sQuery[4096],iLen,iValue, zmClass;iLen=0;
new current_time=get_systime();
iValue=zp_get_user_ammo_packs(id);zmClass=zp_get_user_next_class(id);
new g_admin;
if(is_user_admin(id))g_admin=1;
iLen += formatex(sQuery[iLen], charsmax(sQuery) - iLen,"UPDATE `%s` SET \
`%s`='%i', `kills`=`kills` + %d, \
`total_damage`=`total_damage` + %d, `nemesis_kills`=`nemesis_kills` + %d, \
`zombie_kills`=`zombie_kills` + %d, `survivor_kills`=`survivor_kills` + %d, \
`human_kills`=`human_kills` + %d, ",Table, MoneyRow, iValue,g_Total[id][KILLS],g_Total[id][DAMAGE],
g_Total[id][NMK],g_Total[id][ZMK],g_Total[id][SRK],g_Total[id][HMK]);
iLen += formatex(sQuery[iLen], charsmax(sQuery) - iLen,"`infect`=`infect` + %d,`infected`=`infected` + %d,\
`benemesis`=`benemesis` + %d,`besurvivor`=`besurvivor` + %d,`befirstzm`=`befirstzm` + %d, \
`joined`=%d,`leaved`=%d,`seconline`=`seconline` + %d,`zmclass`=%d,`nick`=^"%s^",`dies`=`dies` + %d, \
`ever_has_acces`=`ever_has_acces` + %d,`acces_now`=%d WHERE `%s`.`%s`='%s'"
,g_Total[id][INFECT],
g_Total[id][INFECTED],g_Total[id][BENEMESIS],
g_Total[id][BESURVIVOR],g_Total[id][BEFIRSTZM],
g_Total[id][STARTBY],
current_time,(current_time - g_Total[id][STARTBY]),
zmClass,g_UserName[id],g_Total[id][DIES], g_admin, g_admin, Table, AuthRow, g_szSteam[id]);
SQL_ThreadQueryFormatNoData(SQL_Tuple, "IgnoreHandle", sQuery);
g_Total[id][NMK]=0;g_Total[id][ZMK]=0;g_Total[id][SRK]=0;g_Total[id][HMK]=0;g_Total[id][KILLS]=0;g_Total[id][INFECTED]=0;g_Total[id][BEFIRSTZM]=0;g_Total[id][INFECT]=0;g_Total[id][BENEMESIS]=0;g_Total[id][BESURVIVOR]=0;g_Total[id][DAMAGE]=0;g_Total[id][STARTBY]=0;g_Total[id][DIES]=0;
}
public IgnoreHandle(FailState,Handle:Query,Error[],ErrCode,Data[],DataSize){
CheckQuery(FailState, ErrCode, Error);
SQL_FreeHandle(Query);
return 1;
}
public plugin_end(){if(SQL_Tuple)SQL_FreeHandle(SQL_Tuple);}
public client_putinserver(id){
g_Loaded[id]=false;zp_set_user_ammo_packs(id,0);set_task(random_float(16.0, 19.0),"LoadData",id+73218);
g_Total[id][NMK]=0;g_Total[id][ZMK]=0;g_Total[id][SRK]=0;g_Total[id][HMK]=0;g_Total[id][KILLS]=0;g_Total[id][INFECTED]=0;g_Total[id][BEFIRSTZM]=0;g_Total[id][INFECT]=0;g_Total[id][BENEMESIS]=0;g_Total[id][BESURVIVOR]=0;g_Total[id][DAMAGE]=0;g_Total[id][STARTBY]=0;g_Total[id][STARTBY]=get_systime();g_Total[id][DIES]=0;
}
public client_disconnect(id){
if(!g_Loaded[id]){if(task_exists(id+73218)){remove_task(id+73218);}}
Save_Data(id);
}
public set_user_money(id, value)zp_set_user_ammo_packs(id,value);
stock bool:CheckQuery(FailState, ErrCode, Error[]){
if(FailState == TQUERY_SUCCESS)
return true;
else
if(FailState == TQUERY_CONNECT_FAILED)
log_amx("Load - Could not connect to SQL database. [%d] %s", ErrCode, Error);
else if(FailState == TQUERY_QUERY_FAILED)
log_amx("Load Query failed. [%d] %s", ErrCode, Error);
return false;
}
stock SQL_ThreadQueryFormat(Handle:Db_Tuple, const handler[], const query[], const data[]="", dataSize=0, any:...){
static szQueryFormat[1024];
vformat(szQueryFormat, charsmax(szQueryFormat), query, 6);
return SQL_ThreadQuery(Db_Tuple, handler, szQueryFormat, data, dataSize);
}
stock SQL_ThreadQueryFormatNoData(Handle:Db_Tuple, const handler[], const query[], any:...){
static szQueryFormat[5000];
vformat(szQueryFormat, charsmax(szQueryFormat), query, 4);
return SQL_ThreadQuery(Db_Tuple, handler, szQueryFormat);
}
public zp_user_infected_post(id, infector, nemesis){
if(infector){g_Total[infector][INFECT]++;g_Total[id][INFECTED]++;}
else if(!nemesis){g_Total[id][BEFIRSTZM]++;}
else{g_Total[id][BENEMESIS]++;}
}
public zp_user_humanized_post(id, survivor){if(survivor){g_Total[id][BESURVIVOR]++;}}
/*********************USE EXTRA MIRROR Protection SYSTEM*********************/
/*********************mmoru.com/board/showthread.php?t=594787*********************/
/*********************Developed by Zombie-Arena.ru*********************/
/*********************Developed by Zombie-Arena.ru*********************/