|
- #include <amxmodx>
- #include <cstrike>
- #include <amxmisc>
- #include <csx>
- #include <dbi>
- #include <acfun> // 如果你要用就删掉这个
- #define Lp_MAX 33
- new Set_Money[4] = {0,5500,3300,1100}; // 前三杀敌奖励
- new Lp_Kill[Lp_MAX],Lp_Death[Lp_MAX],Lp_Tk[Lp_MAX],Lp_Shot[Lp_MAX],Lp_Hit[Lp_MAX],Lp_Damage[Lp_MAX]; // 杀敌,死亡,Tk,开枪,命中,伤害
- new Lp_Head[Lp_MAX],Lp_vHead[Lp_MAX],Lp_OneK[Lp_MAX],Lp_OneD[Lp_MAX],Lp_FK[Lp_MAX],Lp_FD[Lp_MAX]; // 爆头,被爆头,最先杀敌,最先死亡,最后杀敌,最后死亡
- new Lp_Time[Lp_MAX],Lp_Round[Lp_MAX],Lp_TE[Lp_MAX],Lp_CT[Lp_MAX],Lp_SP[Lp_MAX]; // 在线时间,游戏回合,匪徒回合,警察回合,观战回合
- new Lp_Planted[Lp_MAX],Lp_Explode[Lp_MAX],Lp_Defusing[Lp_MAX],Lp_Defused[Lp_MAX],Lp_DefusBad[Lp_MAX]; // 安装C4,爆破C4,拆除C4,拆除成功,拆除失败
- new Kill_Count,Death_Count,Kill_ID,Death_ID; // 杀敌计数,死亡计数,杀敌ID,死亡ID
- new g_host[Lp_MAX], g_user[Lp_MAX], g_pass[Lp_MAX], g_dbname[Lp_MAX], g_error[Lp_MAX],amx_sql_stats[Lp_MAX],Sql:g_dbc,Result:g_result
- new User_Mid[Lp_MAX]; // 玩家Mid[UserId]
- public plugin_init()
- {
- register_plugin("MySql数据统计", "1.3.7", "小坏/root@lovehuai.cn");
- register_event("SendAudio", "Event_Round_End", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw"); // 回合结束
- register_event("TextMsg", "Event_Round_Restart", "a", "2&#Game_C", "2&#Game_w") // 服务器刷新事件
- register_logevent("Event_Round_Start", 2, "1=Round_Start"); // 回合开始 ggystudio说不要用HLTV事件 于是乎咱的插件就都换这个了 - -!
- register_event("ResetHUD", "Event_User_ResetHUD", "be", "1=0", "2=0"); // 玩家HUD刷新
- // register_logevent("Event_Round_End", 2, "1=Round_End"); // 回合结束
- // register_logevent("Event_Round_Restart", 2, "1&Restart_Round_"); // 服务器刷新事件
-
- register_cvar("stats_sql_host", "127.0.0.1");
- register_cvar("stats_sql_user", "root");
- register_cvar("stats_sql_pass", "love");
- register_cvar("stats_sql_db", "amx");
- register_cvar("stats_sql_table", "dwstats");
-
- new configsDir[64];
- get_configsdir(configsDir, 63);
- server_cmd("exec %s/stats_sql.cfg", configsDir);
- server_exec();
- return PLUGIN_CONTINUE;
- }
- public plugin_cfg()
- {
- get_cvar_string("stats_sql_host",g_host,Lp_MAX);
- get_cvar_string("stats_sql_user",g_user,Lp_MAX);
- get_cvar_string("stats_sql_pass",g_pass,Lp_MAX);
- get_cvar_string("stats_sql_db",g_dbname,Lp_MAX);
- get_cvar_string("stats_sql_table", amx_sql_stats, Lp_MAX);
- return PLUGIN_CONTINUE
- }
- public Event_User_ResetHUD(id) // 玩家HUD刷新
- {
- Lp_Round[id]++; // 玩家回合数
- switch(cs_get_user_team(id)) // 团队数
- {
- case CS_TEAM_T:{Lp_TE[id]++;}
- case CS_TEAM_CT:{Lp_CT[id]++;}
- case CS_TEAM_SPECTATOR:{Lp_SP[id]++;}
- }
- return PLUGIN_CONTINUE;
- }
- public Event_Round_Start() // 回合开始
- {
- Lp_FK[Kill_ID]++; // 最后杀敌 这里感觉有点不妥 可能会引起数据乱X
- Lp_FD[Death_ID]++; // 最后死亡
- ResetID(); // 复位杀敌/死亡计数等
- return PLUGIN_CONTINUE;
- }
- public Event_Round_End() // 回合结束 因为没有找到好用的攻击次数统计所以暂用 get_user_rstats 来获取攻击次数
- {
- new Temp_Stats[8];
- for(new i=1; i<=get_playersnum(0);i++)
- {
- if(get_user_rstats(i,Temp_Stats,"") && (User_Mid[i] > 0)){
- Lp_Shot[i] += Temp_Stats[4];
- Save_User_Stats(i);
- }
- }
- return PLUGIN_CONTINUE;
- }
- public Event_Round_Restart() // 服务器刷新事件
- {
- ResetID(); // 服务器刷新强制复位
- return PLUGIN_CONTINUE;
- }
- public client_connect(id) // 玩家接入
- {
- User_Mid[id] = 0;
- Reset_User_Stats(id);
- return PLUGIN_CONTINUE;
- }
- public client_putinserver(id) // 玩家进入到游戏
- {
- Get_User_StatS3(id)
- return PLUGIN_CONTINUE;
- }
- public client_disconnect(id) // 玩家断开连接
- {
- new Temp_Stats[8];
- if(get_user_rstats(id,Temp_Stats,"") && (User_Mid[id] > 0)){
- Lp_Shot[id] += Temp_Stats[4];
- Save_User_Stats(id);
- }
- reset_user_wstats(id); // 删掉
- return PLUGIN_CONTINUE;
- }
- public client_damage(attacker,victim,damage,wpnindex,hitplace,TK) // 玩家受到伤害
- {
- if(!TK && attacker != victim){
- Lp_Hit[attacker]++; // 命中
- Lp_Damage[attacker] += damage; // 伤害
- }
- return PLUGIN_CONTINUE;
- }
- public client_death(Killer,Victim,wpnindex,hitplace,TK) // 玩家死亡事件
- {
- Lp_Death[Victim]++; // 死亡
- Lp_Kill[Killer]++; // 杀敌
- if(TK) {
- Lp_Tk[Killer]++;
- } else if(Killer != Victim){
- Kill_Count++;
- Death_Count++
- Kill_ID = Killer;
- Death_ID = Victim;
- if(Kill_Count == 1){ Lp_OneK[Killer]++; Lp_OneD[Victim]++;} // 更新玩家 最先杀敌 最先第一死亡
- if(hitplace==1){ // 如果死亡时是被击中头部 更新玩家爆头/被爆头
- Lp_Head[Killer]++;
- Lp_vHead[Victim]++;
- }
- if (Kill_Count < 4) { // 前三杀敌奖励
- cs_set_user_money(Killer,cs_get_user_money(Killer)+Set_Money[Kill_Count]);
- new Name[32];
- get_user_name(Killer,Name,32);
- client_print(0,print_chat,"%s 第%i杀敌! 获得$:%i 奖励",Name,Kill_Count,Set_Money[Kill_Count]);
- }
- }
- return PLUGIN_CONTINUE;
- }
- public bomb_planted(id) // 安放C4
- {
- Lp_Planted[id]++;
- return PLUGIN_CONTINUE;
- }
- public bomb_explode(id,defuser) // C4爆炸
- {
- Lp_Explode[id]++;
- return PLUGIN_CONTINUE;
- }
- public bomb_defusing(id) // 尝试C4中
- {
- Lp_Defusing[id]++;
- return PLUGIN_CONTINUE;
- }
- public bomb_defused(id) // C4拆除成功
- {
- Lp_Defused[id]++;
- return PLUGIN_CONTINUE;
- }
- public ResetID() // 最新杀敌/死亡 杀敌/死亡ID复位[冲0]
- {
- Kill_Count = 0;
- Death_Count = 0;
- Kill_ID = 0;
- Death_ID = 0;
- }
- public Get_User_StatS3(id)
- {
- User_Mid[id] = acfun_get_user_mid(id);
- /*
- 我整合了DeDe Cms的网站管理系统 这里是我在admin_sql 里register_native
- 这个返回的是 玩家在网站管理系统里的注册序号 如果你要用 可以把它改为get_user_name 或者ip 或者info之类的
- 切记要把数据库mid字段改为varchar 长度32 我这里用的是int 长度10 如果你不改
- 直接往里写会杯具的
- */
- new name[33];
- get_user_name(id,name,32);
- if(User_Mid[id] != 0)
- {
- g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,Lp_MAX);
- if (g_dbc == SQL_FAILED)
- {
- log_amx("数据库连接失败");
- } else {
- g_result = dbi_query(g_dbc,"SELECT * FROM `%s` WHERE mid = '%i'",amx_sql_stats,User_Mid[id]);
- while (dbi_nextrow(g_result) > 0 )
- {
- Lp_Kill[id] = dbi_result(g_result,"Kill");
- Lp_Death[id] = dbi_result(g_result,"Death");
- Lp_Tk[id] = dbi_result(g_result,"Tk");
- Lp_Shot[id] = dbi_result(g_result,"Shot");
- Lp_Hit[id] = dbi_result(g_result,"Hit");
- Lp_Damage[id] = dbi_result(g_result,"Damage");
- Lp_Head[id] = dbi_result(g_result,"Head");
- Lp_vHead[id] = dbi_result(g_result,"vHead");
- Lp_OneK[id] = dbi_result(g_result,"OneK");
- Lp_OneD[id] = dbi_result(g_result,"OneD");
- Lp_FK[id] = dbi_result(g_result,"FK");
- Lp_FD[id] = dbi_result(g_result,"FD");
- Lp_Time[id] = dbi_result(g_result,"Time");
- Lp_Round[id] = dbi_result(g_result,"Round");
- Lp_TE[id] = dbi_result(g_result,"TE");
- Lp_CT[id] = dbi_result(g_result,"CT");
- Lp_SP[id] = dbi_result(g_result,"SP");
- Lp_Planted[id] = dbi_result(g_result,"Planted");
- Lp_Explode[id] = dbi_result(g_result,"Explode");
- Lp_Defusing[id] = dbi_result(g_result,"Defusing");
- Lp_Defused[id] = dbi_result(g_result,"Defused");
- Lp_DefusBad[id] = dbi_result(g_result,"DefusBad");
- }
- dbi_free_result(g_result);
- dbi_close(g_dbc);
- }
- }
- }
- public Save_User_Stats(id)
- {
- g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,Lp_MAX);
- if (g_dbc == SQL_FAILED)
- {
- log_amx("数据库连接失败");
- } else {
- dbi_query(g_dbc,"INSERT INTO `%s` (`mid`) VALUES ('%i');",amx_sql_stats,User_Mid[id]);
- dbi_query(g_dbc,"set names 'utf8'");
- new Sql_Text[641];
- new name[33];
- get_user_name(id,name,32);
- Lp_Time[id] += get_user_time(id);
- new len = format(Sql_Text,640,"UPDATE `%s` SET `name` = '%s',`date` = '%i',`Kill` = '%i',`Death` = '%i',`Tk` = '%i',`Shot` = '%i',`Hit` = '%i',`Damage` = '%i',`Head` = '%i',`vHead` = '%i',`OneK` = '%i',`OneD` = '%i',`FK` = '%i',",
- amx_sql_stats,name,get_systime(),Lp_Kill[id],Lp_Death[id],Lp_Tk[id],Lp_Shot[id],Lp_Hit[id],Lp_Damage[id],Lp_Head[id],Lp_vHead[id],Lp_OneK[id],Lp_OneD[id],Lp_FK[id]);
- len += format(Sql_Text[len],640-len,"`FD` = '%i',`Time` = '%i',`Round` = '%i',`TE` = '%i',`CT` = '%i',`SP` = '%i',`Planted` = '%i',`Explode` = '%i',`Defusing` = '%i',`Defused` = '%i',`DefusBad` = '%i' WHERE `mid` ='%i';",
- Lp_FD[id],Lp_Time[id],Lp_Round[id],Lp_TE[id],Lp_CT[id],Lp_SP[id],Lp_Planted[id],Lp_Explode[id],Lp_Defusing[id],Lp_Defused[id],Lp_DefusBad[id],User_Mid[id]);
- dbi_query(g_dbc,"%s",Sql_Text);
- dbi_close(g_dbc);
- }
- }
- public Reset_User_Stats(id)
- {
- Lp_Kill[id] = 0;
- Lp_Death[id] = 0;
- Lp_Tk[id] = 0;
- Lp_Shot[id] = 0;
- Lp_Hit[id] = 0;
- Lp_Damage[id] = 0;
- Lp_Head[id] = 0;
- Lp_vHead[id] = 0;
- Lp_OneK[id] = 0;
- Lp_OneD[id] = 0;
- Lp_FK[id] = 0;
- Lp_FD[id] = 0;
- Lp_Time[id] = 0;
- Lp_Round[id] = 0;
- Lp_TE[id] = 0;
- Lp_CT[id] = 0;
- Lp_SP[id] = 0;
- Lp_Planted[id] = 0;
- Lp_Explode[id] = 0;
- Lp_Defusing[id] = 0;
- Lp_Defused[id] = 0;
- Lp_DefusBad[id] = 0;
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|