| matthew16 |
01-07-2014 13:01 |
[MySQL] - Stats plugin doesn't work... :(
Why don't work this? :D
it was like when in game press 'TAB' and show a lot of info
(I'm newbie in pawn scripting)
PHP Code:
#include <amxmodx>
#include <sqlx>
#include <geoip>
#include <cstrike>
#include <hamsandwich>
#define PLUGIN "N/A"
#define VERSION "1.0"
#define AUTHOR "N/A"
#define CONNECT "connect.."
/*
CREATE TABLE IF NOT EXISTS `score` (
`id` int(11) NOT NULL auto_increment,
`team` varchar(255) default NULL,
`playerName` varchar(255) default NULL,
`score` int(11) default NULL,
`deaths` int(11) default NULL,
`country` int(11) default NULL,
`status` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
*/
new Handle:g_SqlTuple
// ------------------
new GlobalID[33];
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event( "DeathMsg", "event", "a" );
RegisterHam( Ham_Spawn, "player", "fwdPlayerSpawn", 1 );
set_task(5.0, "CheckStatus", _, _, _, "b")
}
public plugin_cfg()
{
g_SqlTuple = SQL_MakeDbTuple("host", "user", "pass", "database")
}
public client_disconnect(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "DELETE FROM score WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public client_connect(id)
{
GlobalID[id] = random(1500) * random(1500)
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new ip[18]
get_user_ip(id,ip,17,1)
new name[64]
new country[46]
get_user_name ( id, name, 63);
geoip_country ( ip, country, 45 );
new Handle:Query = SQL_PrepareQuery(SqlConnection, "INSERT INTO `score` (`playerName`, `team`, `score`, `deaths`, `county`, `status`) VALUES (^"%s^", ^"-^", ^"-^", ^"-^", ^"%s^", ^"%s^");", name, country, CONNECT)
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
public event()
{
new Killer = read_data( 1 );
new Victim = read_data( 2 )
new Kills[33], Deaths[33];
Kills[Killer]++
Deaths[Victim]++
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET score='%d', deaths='%d' WHERE id='%d'", Kills[Killer], Deaths[Victim], GlobalID[Killer])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public fwdPlayerSpawn(id) {
if(cs_get_user_team(id) == CS_TEAM_CT)
{
CT(id);
}
else if(cs_get_user_team(id) == CS_TEAM_T)
{
TT(id);
} else {
SPEC(id);
}
return PLUGIN_CONTINUE
}
public CT(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET team='ct' WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public TT(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET team='tt' WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public SPEC(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET team='spec' WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public CheckStatus(id){
if(is_user_alive(id))
{
ALIVE(id);
} else {
DEATH(id);
}
}
public ALIVE(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET status='1' WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
public DEATH(id){
//MySQL
new ErrorCode;
new Error[512]
new Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, Error, 511)
new Handle:Query = SQL_PrepareQuery(SqlConnection, "UPDATE score SET status='0' WHERE id='%d'", GlobalID[id])
if(!SQL_Execute(Query))
{
SQL_QueryError(Query, Error, 511)
set_fail_state(Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
//MySQL
return PLUGIN_CONTINUE
}
|