Raised This Month: $ Target: $400
 0% 

Mysql Problems, Reseting.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 05-11-2015 , 16:18   Re: Mysql Problems, Reseting.
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
You are calling Save_PlayerLevel() at client_disconnect() which could be your problem. Show us your Save_PlayerLevel() function.
Thats because players usually had problems with reseting when the map changed (Not always), and client_disconnect is called when map changes.

Saving hooks/functions:
PHP Code:
public client_authorized(Id

    
get_user_authid(Idg_Steam[Id], charsmax(g_Steam[])) // Lets get SteamID just once. Safe for client_disconnect saving 
    
    
if(g_SQL_Id == Empty_Handle
        
set_task(4.0,"LoadShit",Id TASK_SQL
    
    else 
        
LoadShit(Id TASK_SQL


public 
LoadShit(Id)
{
    if(
g_SQL_Id == Empty_Handle)
    {
        
// something is wrong with the connection (maybe offline / wrong ip / user / password)
        
return
    }
    
    
Id-= TASK_SQL
    
    Clear_PlayerLevel
(Id)
    
Load_PlayerLevel(Id)
}  

public 
client_disconnect(id
    
Save_PlayerLevel(id)


public 
fw_Killed(id) {
    if(
is_user_connected(id))
        
Save_PlayerLevel(id)

Mysql Functions:
PHP Code:
public MySQL_Init()
{
    
server_print("[MySQL] Initializing...")
    
    
g_SQL_Id SQL_MakeDbTuple(SQL_HOSTSQL_USERNAMESQL_PASSWORDSQL_DB)
    
    new 
ErrorCodeHandle:SqlConnection SQL_Connect(g_SQL_IdErrorCodeg_SQL_Errorcharsmax(g_SQL_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_SQL_Error)
    
    new 
Handle:Queries
    
    
// Level
    
Queries SQL_PrepareQuery(SqlConnection"CREATE TABLE IF NOT EXISTS Level (Steamid varchar(32), Level INT(8), Exp INT(16))")
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queriesg_SQL_Errorcharsmax(g_SQL_Error))
        
set_fail_state(g_SQL_Error)
    }
    
    
    
// Free
    
SQL_FreeHandle(Queries)
    
SQL_FreeHandle(SqlConnection
    
    
server_print("[MySQL] Initialize: Completed!")


public 
Load_PlayerLevel(id)
{
    static 
szAuthId[33];
    
get_user_authid(idszAuthId32); 
    
    static 
Data[1]; Data[0] = id
    
    format
(g_SQL_Querycharsmax(g_SQL_Query),"SELECT * FROM `Level` WHERE (`Level`.`Steamid` = '%s')"szAuthId)
    
SQL_ThreadQuery(g_SQL_Id"SQLHandle_LoadLevel"g_SQL_QueryDatasizeof(Data))
}

public 
Save_PlayerLevel(id)
{
    static 
szAuthId[33];
    
get_user_authid(idszAuthId32); 
    
    
format(g_SQL_Querycharsmax(g_SQL_Query),"UPDATE `Level` SET `Level` = '%i', `Exp` = '%i' WHERE `Level`.`Steamid` = '%s';"g_PlayerLevel[id], g_PlayerExp[id], szAuthId)
    
SQL_ThreadQuery(g_SQL_Id"SQLHandle_Ignore"g_SQL_Query)
}

public 
Clear_PlayerLevel(id)
{
    
g_PlayerLevel[id] = 1
    g_PlayerExp
[id] = 0
}

public 
SQLHandle_LoadLevel(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        
log_amx("[MySQL] Error (Load): Could not connect to SQL Database. [%d] %s"ErrcodeError)
    else if(
FailState == TQUERY_QUERY_FAILED)
        
log_amx("[MySQL] Error (Load): Query failed. [%d] %s"ErrcodeError)
    
    static 
idid Data[0]
    if(
SQL_NumResults(Query) < 1
    { 
// if there are no results found
        
static szAuthId[33];
        
get_user_authid(idszAuthId32); 
        
        
format(g_SQL_Querycharsmax(g_SQL_Query), "INSERT INTO `Level` ( `Steamid` , `Level` , `Exp`)VALUES ('%s' , '1' , '0');"szAuthId)
        
SQL_ThreadQuery(g_SQL_Id"SQLHandle_Ignore"g_SQL_Query)
        } else {
        
g_PlayerLevel[id] = SQL_ReadResult(Query1)
        
g_PlayerExp[id] = SQL_ReadResult(Query2)
    }
    
    return 
PLUGIN_HANDLED
}  

public 
SQLHandle_Ignore(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    
SQL_FreeHandle(Query)
    return 
PLUGIN_HANDLED

__________________
Contact: Steam
Videos: Youtube

Last edited by SkumTomteN; 05-11-2015 at 16:20.
SkumTomteN is offline
 



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 18:43.


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