基本数据统计
在提问处找到的 很不错的说明:
#include <amxmodx>
#include <cstrike>
#include <amxmisc>
#include <csx>
#include <dbi>
#include <acfun> // 如果你要用就删掉这个
#define Lp_MAX 33
new Set_Money = {0,5500,3300,1100}; // 前三杀敌奖励
new Lp_Kill,Lp_Death,Lp_Tk,Lp_Shot,Lp_Hit,Lp_Damage; // 杀敌,死亡,Tk,开枪,命中,伤害
new Lp_Head,Lp_vHead,Lp_OneK,Lp_OneD,Lp_FK,Lp_FD; // 爆头,被爆头,最先杀敌,最先死亡,最后杀敌,最后死亡
new Lp_Time,Lp_Round,Lp_TE,Lp_CT,Lp_SP; // 在线时间,游戏回合,匪徒回合,警察回合,观战回合
new Lp_Planted,Lp_Explode,Lp_Defusing,Lp_Defused,Lp_DefusBad; // 安装C4,爆破C4,拆除C4,拆除成功,拆除失败
new Kill_Count,Death_Count,Kill_ID,Death_ID;// 杀敌计数,死亡计数,杀敌ID,死亡ID
new g_host, g_user, g_pass, g_dbname, g_error,amx_sql_stats,Sql:g_dbc,Result:g_result
new User_Mid; // 玩家Mid
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;
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++; // 玩家回合数
switch(cs_get_user_team(id)) // 团队数
{
case CS_TEAM_T:{Lp_TE++;}
case CS_TEAM_CT:{Lp_CT++;}
case CS_TEAM_SPECTATOR:{Lp_SP++;}
}
return PLUGIN_CONTINUE;
}
public Event_Round_Start() // 回合开始
{
Lp_FK++; // 最后杀敌 这里感觉有点不妥 可能会引起数据乱X
Lp_FD++;// 最后死亡
ResetID(); // 复位杀敌/死亡计数等
return PLUGIN_CONTINUE;
}
public Event_Round_End() // 回合结束 因为没有找到好用的攻击次数统计所以暂用 get_user_rstats 来获取攻击次数
{
new Temp_Stats;
for(new i=1; i<=get_playersnum(0);i++)
{
if(get_user_rstats(i,Temp_Stats,"") && (User_Mid > 0)){
Lp_Shot += Temp_Stats;
Save_User_Stats(i);
}
}
return PLUGIN_CONTINUE;
}
public Event_Round_Restart() // 服务器刷新事件
{
ResetID(); // 服务器刷新强制复位
return PLUGIN_CONTINUE;
}
public client_connect(id) // 玩家接入
{
User_Mid = 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;
if(get_user_rstats(id,Temp_Stats,"") && (User_Mid > 0)){
Lp_Shot += Temp_Stats;
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++; // 命中
Lp_Damage += damage; // 伤害
}
return PLUGIN_CONTINUE;
}
public client_death(Killer,Victim,wpnindex,hitplace,TK) // 玩家死亡事件
{
Lp_Death++; // 死亡
Lp_Kill++;// 杀敌
if(TK) {
Lp_Tk++;
} else if(Killer != Victim){
Kill_Count++;
Death_Count++
Kill_ID= Killer;
Death_ID = Victim;
if(Kill_Count == 1){ Lp_OneK++; Lp_OneD++;} // 更新玩家 最先杀敌 最先第一死亡
if(hitplace==1){ // 如果死亡时是被击中头部 更新玩家爆头/被爆头
Lp_Head++;
Lp_vHead++;
}
if (Kill_Count < 4) { // 前三杀敌奖励
cs_set_user_money(Killer,cs_get_user_money(Killer)+Set_Money);
new Name;
get_user_name(Killer,Name,32);
client_print(0,print_chat,"%s 第%i杀敌! 获得$:%i 奖励",Name,Kill_Count,Set_Money);
}
}
return PLUGIN_CONTINUE;
}
public bomb_planted(id) // 安放C4
{
Lp_Planted++;
return PLUGIN_CONTINUE;
}
public bomb_explode(id,defuser) // C4爆炸
{
Lp_Explode++;
return PLUGIN_CONTINUE;
}
public bomb_defusing(id) // 尝试C4中
{
Lp_Defusing++;
return PLUGIN_CONTINUE;
}
public bomb_defused(id) // C4拆除成功
{
Lp_Defused++;
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 = acfun_get_user_mid(id);
/*
我整合了DeDe Cms的网站管理系统 这里是我在admin_sql 里register_native
这个返回的是 玩家在网站管理系统里的注册序号 如果你要用 可以把它改为get_user_name 或者ip 或者info之类的
切记要把数据库mid字段改为varchar 长度32 我这里用的是int 长度10 如果你不改
直接往里写会杯具的
*/
new name;
get_user_name(id,name,32);
if(User_Mid != 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);
while (dbi_nextrow(g_result) > 0 )
{
Lp_Kill = dbi_result(g_result,"Kill");
Lp_Death = dbi_result(g_result,"Death");
Lp_Tk = dbi_result(g_result,"Tk");
Lp_Shot = dbi_result(g_result,"Shot");
Lp_Hit = dbi_result(g_result,"Hit");
Lp_Damage = dbi_result(g_result,"Damage");
Lp_Head = dbi_result(g_result,"Head");
Lp_vHead = dbi_result(g_result,"vHead");
Lp_OneK = dbi_result(g_result,"OneK");
Lp_OneD = dbi_result(g_result,"OneD");
Lp_FK = dbi_result(g_result,"FK");
Lp_FD = dbi_result(g_result,"FD");
Lp_Time = dbi_result(g_result,"Time");
Lp_Round = dbi_result(g_result,"Round");
Lp_TE = dbi_result(g_result,"TE");
Lp_CT = dbi_result(g_result,"CT");
Lp_SP = dbi_result(g_result,"SP");
Lp_Planted = dbi_result(g_result,"Planted");
Lp_Explode = dbi_result(g_result,"Explode");
Lp_Defusing = dbi_result(g_result,"Defusing");
Lp_Defused = dbi_result(g_result,"Defused");
Lp_DefusBad = 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);
dbi_query(g_dbc,"set names 'utf8'");
new Sql_Text;
new name;
get_user_name(id,name,32);
Lp_Time += 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,Lp_Death,Lp_Tk,Lp_Shot,Lp_Hit,Lp_Damage,Lp_Head,Lp_vHead,Lp_OneK,Lp_OneD,Lp_FK);
len += format(Sql_Text,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,Lp_Time,Lp_Round,Lp_TE,Lp_CT,Lp_SP,Lp_Planted,Lp_Explode,Lp_Defusing,Lp_Defused,Lp_DefusBad,User_Mid);
dbi_query(g_dbc,"%s",Sql_Text);
dbi_close(g_dbc);
}
}
public Reset_User_Stats(id)
{
Lp_Kill = 0;
Lp_Death = 0;
Lp_Tk = 0;
Lp_Shot = 0;
Lp_Hit = 0;
Lp_Damage = 0;
Lp_Head = 0;
Lp_vHead = 0;
Lp_OneK = 0;
Lp_OneD = 0;
Lp_FK = 0;
Lp_FD = 0;
Lp_Time = 0;
Lp_Round = 0;
Lp_TE = 0;
Lp_CT = 0;
Lp_SP = 0;
Lp_Planted = 0;
Lp_Explode = 0;
Lp_Defusing = 0;
Lp_Defused = 0;
Lp_DefusBad = 0;
} 好乱啊,源码吗 支持一下!!! 我也想做这个 不知道你这个好不好用 挺好的
感谢你提供这些! 感谢你提供这些! 感谢你提供这些!
页:
[1]