Raised This Month: $ Target: $400
 0% 

Save Points On mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-01-2013 , 15:15   Re: Save Points On mysql
Reply With Quote #1

I did something with mysql but i have some debug errors...
Code:
L 05/01/2013 - 21:01:40: Start of error session.
L 05/01/2013 - 21:01:40: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20130501.log")
L 05/01/2013 - 21:01:40: [MySQL] Thread worker was unable to start.
L 05/01/2013 - 21:01:40: [AMXX] Displaying debug trace (plugin "points.amxx")
L 05/01/2013 - 21:01:40: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 05/01/2013 - 21:01:40: [AMXX]    [0] points.sma::register_client (line 526)
Here is the part of mysql...
PHP Code:
#include <amxmodx>
#include <sqlx>

new points[33];

new 
Host[]     = "blahblah"
new User[]    = "blahblah"
new Pass[]     = "blahblah"
new Db[]     = "blahblah"

new Handle:g_SqlTuple
new g_Error[512]

public 
plugin_init() 
{
    
set_task(1.0"MySql_Init"
}

public 
MySql_Init()
{
    
// we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    
// ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
// stop the plugin with an error message
    
set_fail_state(g_Error)
    
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS user_points (name varchar(32),points INT(11))")
    
    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
        
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
    
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection)   
}

public 
plugin_end()
{
    
// free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    
SQL_FreeHandle(g_SqlTuple)
}

public 
Load_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `user_points` WHERE (`user_points`.`name` = '%s')"szName)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }
    
    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        
//.if there are no results found
        
        
new szName[32]
        
get_user_name(idszNamecharsmax(szName))
        new 
szTemp[512]
        
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `user_points` ( `name` , `points`)VALUES ('%s','0');"szName)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
// if there are results found
        
points[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    
format(szTemp,charsmax(szTemp),"UPDATE `user_points` SET `points` = '%i' WHERE `user_points`.`name` = '%s';",points[id], szName)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
Save_MySql(id)

__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science

Last edited by oxygen935; 05-01-2013 at 15:22.
oxygen935 is offline
Send a message via Skype™ to oxygen935
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 05-01-2013 , 18:13   Re: Save Points On mysql
Reply With Quote #2

Quote:
Originally Posted by oxygen935 View Post
I did something with mysql but i have some debug errors...
Code:
L 05/01/2013 - 21:01:40: Start of error session.
L 05/01/2013 - 21:01:40: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20130501.log")
L 05/01/2013 - 21:01:40: [MySQL] Thread worker was unable to start.
L 05/01/2013 - 21:01:40: [AMXX] Displaying debug trace (plugin "points.amxx")
L 05/01/2013 - 21:01:40: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 05/01/2013 - 21:01:40: [AMXX]    [0] points.sma::register_client (line 526)
I'm told that is because you are calling a Threaded Query when the map is changing. There is a thread in the Issues section that has a workaround, or you can ignore the error or bug the AMXX Devs to fix it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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