AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [MySQL] - Stats plugin doesn't work... :( (https://forums.alliedmods.net/showthread.php?t=232961)

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(PLUGINVERSIONAUTHOR)
    
register_event"DeathMsg""event""a" );
    
RegisterHamHam_Spawn"player""fwdPlayerSpawn"); 
    
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"DELETE FROM score WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
ip[18]
    
get_user_ip(id,ip,17,1)
    
    new 
name[64]
    new 
country[46]
    
    
get_user_name idname63);
    
geoip_country ipcountry45 );
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"INSERT INTO `score` (`playerName`, `team`, `score`, `deaths`, `county`, `status`) VALUES (^"%s^", ^"-^", ^"-^", ^"-^", ^"%s^", ^"%s^");"namecountryCONNECT)
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
set_fail_state(Error)
    }
    
SQL_FreeHandle(Query)
    
SQL_FreeHandle(SqlConnection)    
}    

public 
event()
{
    new 
Killer read_data);
    new 
Victim read_data)
    
    new 
Kills[33], Deaths[33];
    
    
Kills[Killer]++
    
Deaths[Victim]++
    
    
//MySQL
    
new ErrorCode;
    new 
Error[512]
    new 
Handle:SqlConnection SQL_Connect(g_SqlTupleErrorCodeError511)
    
    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(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"UPDATE score SET team='ct' WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"UPDATE score SET team='tt' WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"UPDATE score SET team='spec' WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"UPDATE score SET status='1' WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
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_SqlTupleErrorCodeError511)
    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection"UPDATE score SET status='0' WHERE id='%d'"GlobalID[id])
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QueryError511)
        
set_fail_state(Error)
    }
    
SQL_FreeHandle(Query)
    
SQL_FreeHandle(SqlConnection)
    
//MySQL
    
return PLUGIN_CONTINUE



waza123a 01-09-2014 05:04

Re: [MySQL] - Stats plugin doesn't work... :(
 
Questions:

1. Did you run MySQL server ?
2. Did you edited this line with your host and login and pass and db ? g_SqlTuple = SQL_MakeDbTuple("host", "user", "pass", "database")
3. Did you created a table ?
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 ;

matthew16 01-10-2014 14:00

Re: [MySQL] - Stats plugin doesn't work... :(
 
1. Yes
2. Yes
3. Yes

Arkshine 01-10-2014 15:51

Re: [MySQL] - Stats plugin doesn't work... :(
 
Is the plugin running without problems at least? Check with server command "amxx list".

matthew16 01-11-2014 09:22

Re: [MySQL] - Stats plugin doesn't work... :(
 
Little fail:.

country int -> country varchar :D


All times are GMT -4. The time now is 10:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.