hi, i'm new in amx and i'm try develop a basic skill calc with mysql, but is not working if someone can help.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <dbi>
#define PLUGIN "pontos"
#define VERSION "1.0"
#define AUTHOR "author"
#define CVAR_CHHOST "wwwreg_host"
#define CVAR_CHUSER "wwwreg_user"
#define CVAR_CHPASS "wwwreg_pass"
#define CVAR_CHDB "wwwreg_db"
#define TABLE "users"
//Stats
new skill[33]
new CDeath[33] //Death count
new CKill[33] //Kill count
new CHSG[33] //HS Giv
new CHST[33] //HS Tak
new SpawnCount[33]
//Stats display
new RankSkill[33] //global rank by skill
new RankCSStats[33] //global rank by csstats
new RankCSServer[33] //server rank by skill
new RankSkillServer[33] //server rank by csstats
new PlayerLastAim[33]
new warmup_status
new live_status
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("DeathMsg", "hook_death", "a")
register_clcmd("say .skill", "teste");
register_cvar(CVAR_CHHOST, "***")
register_cvar(CVAR_CHUSER, "****")
register_cvar(CVAR_CHPASS, "****")
register_cvar(CVAR_CHDB, "****")
new Sql:sql
if (!connect(sql)) {
log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
pause("a")
return
}
else
server_print("[%s] Connected successfully to SQL database.", PLUGIN)
dbi_close(sql)
warmup_status = get_cvar_pointer ( "warmup" )
live_status = get_cvar_pointer ( "live" )
}
public client_authorized(id) {
if (is_user_bot(id))
return PLUGIN_CONTINUE
new pontos[32]
new authid[32]
get_user_authid(id,authid,31)
new Sql:sql
if (!connect(sql))
return false
const LONGER = 128
new query[LONGER + 1]
format(query, LONGER, "SELECT `pontos` FROM users WHERE `steamid` = ^"%s^" LIMIT 1", authid)
new Result:result = dbi_query(sql, query)
//Loop through the result set
while (result && dbi_nextrow(result)>0) {
new qry[32]
//Get the column/field called "keyname" from the result set
dbi_result(result, "pontos", qry, 32)
set_user_info(id,"pontos",qry)
pontos = qry;
}
skill[id] = pontos[id];
dbi_close(sql)
return PLUGIN_CONTINUE
}
public hook_death ()
{
if(get_pcvar_num(live_status) == 1 && get_pcvar_num(warmup_status) == 0 || get_pcvar_num(live_status) == 2 && get_pcvar_num(warmup_status) == 0)
{
new attacker = read_data(1);
new victim = read_data(2);
new attackerteam = get_user_team(attacker);
new victimteam = get_user_team(victim);
if((attacker == victim) || (!attacker))
{
skill[victim] -= 10;
}
else
{
skill[attacker] += 10;
skill[victim] -= 8;
}}
}
public client_disconnect(id)
{
new Arg[32]
new steamid[32]
read_argv(1, Arg, 32)
if (skill[id] < 100)
{
skill[id] = 100;
}
new Sql:sql
if (!connect(sql))
return false
const LONGER = 128
new query[LONGER + 1]
format(qpnt, LONGER, "UPDATE `users` SET `pontos`=%i WHERE `steamid`=^"%s^"", skill[id], steamid)
dbi_query(sql, qpnt)
dbi_close(sql)
}
bool:connect(&Sql:sql) {
const LEN = 128
new host[LEN], user[LEN], pass[LEN], db[LEN], error_msg[LEN]
get_cvar_string(CVAR_CHHOST, host, LEN - 2)
get_cvar_string(CVAR_CHUSER, user, LEN - 2)
get_cvar_string(CVAR_CHPASS, pass, LEN - 2)
get_cvar_string(CVAR_CHDB, db, LEN - 2)
sql = dbi_connect(host, user, pass, db, error_msg, LEN - 2)
if (!sql) {
log_amx("ERROR - Can't connect to SQL db: %s", error_msg)
return false
}
return true
}
warmup and live is for know if game is live and calc skill.