|
楼主 |
发表于 2005-6-2 12:43:50
|
显示全部楼层
来自 中国–广东–广州–天河区
下面在的代码
#include <amxmodx>
#include <amxmisc>
#include <dbi>
//#include <lang>
#include <fun>
new Sql:dbc
new Result:result
public plugin_init() {
register_plugin("SQL Entertainment","0.1","lai-xiwan_cn")
set_task(0.1,"sql_init")
}
public sql_init() {
new host[64], username[32], password[32], dbname[32], error[32]
get_cvar_string("amx_sql_host",host,64)
get_cvar_string("amx_sql_user",username,32)
get_cvar_string("amx_sql_pass",password,32)
get_cvar_string("amx_sql_db",dbname,32)
dbc = dbi_connect(host,username,password,dbname,error,32)
if (dbc == SQL_FAILED)
log_amx("[AMXX] SQL Connection Failed")
else
{
dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `Entertainment` (`csname` VARCHAR(32) NOT NULL,`steamid` VARCHAR(32) NOT NULL,`csip` VARCHAR(64) NOT NULL,`csid` VARCHAR(64) NOT NULL,`csdata` VARCHAR(64) NOT NULL,`num` INT NOT NULL, PRIMARY KEY(csid,csname))")
}
}
public client_infochanged(id) {
new steamid[32]
get_user_authid(id,steamid,31)
new csname[32]
get_user_name(id,csname,31)
new csip[64]
get_user_ip(id,csip,63,1)
new csid=get_user_userid(id)
new csdata=get_user_frags(id)
result = dbi_query(dbc,"SELECT * FROM Entertainment WHERE csname = '%s'",csname)
if (dbi_num_rows(result) < 1) {
new newname[32]
get_user_name(id,newname,31)
if ( equal(newname,"csname") ){
return PLUGIN_HANDLED
}
result = dbi_query(dbc,"INSERT INTO Entertainment (csname,steamid,csip,csid,csdata,num) values ('%s','%s','%s','%d','%d',1)",csname,steamid,csip,csid,csdata)
dbi_free_result(result)
}else{
result = dbi_query(dbc,"UPDATE Entertainment SET num=num+1, csdata=csdata WHERE csname = '%s'",csname)
dbi_free_result(result)
}
dbi_free_result(result)
return PLUGIN_HANDLED
} |
|