PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <csx>
#include <dbi>
#include <cstrike>
#define SQL_HOST "127.0.0.1"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DB "amx"
#define SQL_TABLE "stats"
#define PLUGIN "STATS MYSQL"
#define VERSION "1.0"
#define AUTHOR "k1nader"
#define USER_MAX 32
new g_kills[USER_MAX],g_deaths[USER_MAX],g_teamkilling[USER_MAX],g_vichead[USER_MAX],g_one[USER_MAX],g_shots[USER_MAX],g_hits[USER_MAX],g_damage[USER_MAX],g_odeaths[USER_MAX],g_head[USER_MAX];
new g_time[USER_MAX],g_round[USER_MAX],g_Te[USER_MAX],g_Ct[USER_MAX],g_St[USER_MAX],g_planted[USER_MAX],g_explode[USER_MAX],g_defusing[USER_MAX],g_defused[USER_MAX],AUTHSETINFO[USER_MAX][USER_MAX],g_skill[USER_MAX];
new Kill_Count = 0;
new g_szQuery[128];
new g_error[64],Sql:g_dbc,Result:g_result;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_event("SendAudio", "event_round_end", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw");
register_event("TextMsg", "restart_round", "a", "2&#Game_C", "2&#Game_w");
//register_event("ResetHUD", "SaveClient", "be");
}
public client_putinserver(id)
{
get_user_authid(id,AUTHSETINFO[id],USER_MAX);
set_dateZero(id);
}
public event_round_end()
{
for (new i = 1; i <= get_maxplayers(); i++)
{
if(!is_user_connected(i)) return;
new CsTeams:userTeam = cs_get_user_team(i);
switch(userTeam)
{
case CS_TEAM_T : g_Te[i]++;
case CS_TEAM_CT : g_Ct[i]++;
case CS_TEAM_SPECTATOR : g_St[i]++;
}
g_round[i]++;
get_player_statsx(i);
}
Kill_Count = 0;
}
public client_damage( attacker, victim, damage, wpnindex, hitplace,tk)
{
if(!tk && attacker != victim)
{
g_hits[attacker]++;
g_damage[attacker] += damage;
}
return PLUGIN_CONTINUE;
}
public client_death(Killer, Victim, wpnindex,hitplace,tk)
{
if(tk)
g_teamkilling[Killer]++;
if ((Killer != Victim) && (!tk))
{
g_skill[Killer] += 10;
g_skill[Victim] = g_skill[Victim]-2;
g_kills[Killer]++;
g_deaths[Victim]++;
Kill_Count++;
if(Kill_Count == 1)
{
g_one[Killer]++;
g_odeaths[Victim]++;
}
if(hitplace==1)
{
g_skill[Killer] += 2;
g_head[Killer]++;
g_vichead[Victim]++;
}
}
return PLUGIN_CONTINUE;
}
public bomb_planted(id)
g_planted[id]++;
public bomb_explode(id,defuser)
{
g_skill[id] += 5;
g_explode[id]++;
}
public bomb_defusing(id)
g_defusing[id]++;
public bomb_defused(id)
{
g_skill[id] += 5;
g_defused[id]++;
}
public get_player_statsx(i)
{
new g_iStats[8]
if(get_user_rstats( i, g_iStats,""))
g_shots[i] += g_iStats[4];
}
public restart_round()
{
for (new i = 1; i <= get_maxplayers(); i++)
set_dateZero(i);
}
public set_dateZero(i)
{
g_skill[i] =0;
g_kills[i] =0;
g_one[i] =0;
g_deaths[i] =0;
g_odeaths[i] =0;
g_vichead[i] =0;
g_teamkilling[i] =0;
g_shots[i] =0;
g_hits[i] =0;
g_damage[i] =0;
g_head[i] =0;
g_planted[i] =0;
g_explode[i] =0;
g_defusing[i] =0;
g_defused[i] =0;
g_time[i] =0;
g_round[i] =0;
g_Te[i] =0;
g_Ct[i] =0;
g_St[i] =0;
}
SaveClient(i)
{
new one[12],kills[12],deaths[12],odeaths[12],vichead[12],teamkilling[12],shots[12];
new hits[12],damage[12],head[12],planted[12],explode[12],defusing[12],defused[12],lasttime[12];
new round[12],Te[12],Ct[12],St[12],skill[12];
g_dbc = dbi_connect(SQL_HOST,SQL_USER,SQL_PASS,SQL_DB,g_error,63);
if (g_dbc == SQL_FAILED)
{
log_amx("Can not connect to MySQL Server")
}
else
{
g_result = dbi_query(g_dbc,"SELECT * FROM `%s` WHERE steamid = '%s'",SQL_TABLE,AUTHSETINFO[i])
while (dbi_nextrow(g_result) > 0 )
{
dbi_result(g_result,"skill",skill,11);
dbi_result(g_result,"kills",kills,11);
dbi_result(g_result,"one",one,11);
dbi_result(g_result,"deaths",deaths,11);
dbi_result(g_result,"odeaths",odeaths,11);
dbi_result(g_result,"vichead",vichead,11);
dbi_result(g_result,"teamkilling",teamkilling,11);
dbi_result(g_result,"shots",shots,11);
dbi_result(g_result,"hits",hits,11);
dbi_result(g_result,"damage",damage,11);
dbi_result(g_result,"head",head,11);
dbi_result(g_result,"planted",planted,11);
dbi_result(g_result,"explode",explode,11);
dbi_result(g_result,"defusing",defusing,11);
dbi_result(g_result,"defused",defused,11);
dbi_result(g_result,"time",lasttime,11);
dbi_result(g_result,"round",round,11);
dbi_result(g_result,"Te",Te,11);
dbi_result(g_result,"Ct",Ct,11);
dbi_result(g_result,"St",St,11);
}
g_kills[i] = str_to_num(kills) + g_kills[i];
g_skill[i] = str_to_num(skill) + g_skill[i];
g_one[i] = str_to_num(one) + g_one[i];
g_deaths[i] = str_to_num(deaths) + g_deaths[i];
g_odeaths[i] = str_to_num(odeaths) + g_odeaths[i];
g_vichead[i] = str_to_num(vichead) + g_vichead[i];
g_teamkilling[i] = str_to_num(teamkilling) + g_teamkilling[i];
g_shots[i] = str_to_num(shots) + g_shots[i];
g_hits[i] = str_to_num(hits) + g_hits[i];
g_damage[i] = str_to_num(damage) + g_damage[i];
g_head[i] = str_to_num(head) + g_head[i];
g_planted[i] = str_to_num(planted) + g_planted[i];
g_explode[i] = str_to_num(explode) + g_explode[i];
g_defusing[i] = str_to_num(defusing) + g_defusing[i];
g_defused[i] = str_to_num(defused) + g_defused[i];
g_time[i] = str_to_num(lasttime) + g_time[i];
g_round[i] = str_to_num(round) + g_round[i];
g_Te[i] = str_to_num(Te) + g_Te[i];
g_Ct[i] = str_to_num(Ct) + g_Ct[i];
g_St[i] = str_to_num(St) + g_St[i];
formatex(g_szQuery, charsmax(g_szQuery),
"UPDATE `%s` SET `date` = NOW(),`kills` = '%i',`one` = '%i',`deaths` = '%i',`odeaths` = '%i',`vichead` = '%i',`teamkilling` = '%i',`shots` = '%i',`hits` = '%i',`damage` = '%i',`head` = '%i',`planted` = '%i',`explode` = '%i',`defusing` = '%i',`defused` = '%i',`time` = '%i',`round` = '%i',`Te` = '%i',`Ct` = '%i',`St` = '%i',`skill` = '%i' WHERE `steamid` = '%s'",
SQL_TABLE,g_kills[i],g_one[i],g_deaths[i],g_odeaths[i],g_vichead[i],g_teamkilling[i],g_shots[i],g_hits[i],g_damage[i],g_head[i],g_planted[i],g_explode[i],g_defusing[i],g_defused[i],g_time[i],g_round[i],g_Te[i],g_Ct[i],g_St[i],g_skill[i],AUTHSETINFO[i]);
dbi_free_result(g_result);
}
dbi_close(g_dbc)
}
public client_disconnect (id)
SaveClient(id);