Sometimes on my server mysql does'nt load the stats of the player and reset them.
PHP Code:
public client_putinserver(id)
{
Load_MySql(id) // This is line 2623
}
public Load_MySql(id)
{
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error)) // This is line 2540
if(g_SqlTuple == Empty_Handle)
{
set_fail_state(g_Error)
}
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
new Data[1]
Data[0] = id
//we will now select from the table `deathrun` where the steamid match
format(szTemp,charsmax(szTemp),"SELECT * FROM `deathrun` WHERE (`deathrun`.`steamid` = '%s')", szSteamId)
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
SQL_FreeHandle(SqlConnection)
}
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", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) < 1)
{
//.if there are no results found
new szSteamId[32], szName[32]
get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
get_user_name(id, szName, 31) // get user's name
// if its still pending we can't do anything with it
if (equal(szSteamId,"ID_PENDING"))
{
return PLUGIN_HANDLED
}
new szTemp[512]
// now we will insert the values into our table.
format(szTemp,charsmax(szTemp),"INSERT INTO `deathrun` ( `steamid` , `name` , `points` , `lives` , `frags` , `model`)VALUES ('%s','%s','0','0','0','0');",szSteamId, szName)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
else
{
// if there are results found
iPoints[id] = SQL_ReadResult(Query, 2)
iLives[id] = SQL_ReadResult(Query, 3)
iFrags[id] = SQL_ReadResult(Query, 4)
iModel[id] = SQL_ReadResult(Query, 5)
}
Update_Rank(id)
return PLUGIN_HANDLED
}
public Update_Rank(id) // register cmd to this function
{
for(new i; i <= maxplayers; i++)
{
if(is_user_connected(i))
{
Save_MySql(i) // Save all stats to get the correct rank
}
}
new Data[1]
Data[0] = id
new szTemp[512]
format(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `deathrun` WHERE `points` >= %d", iPoints[id])
// Select the count where the points is matching or higher (Incase of equal points)
SQL_ThreadQuery(g_SqlTuple,"Sql_Rank",szTemp,Data,1)
return PLUGIN_CONTINUE
}
public Sql_Rank(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
{
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new count = 0
count = SQL_ReadResult(Query,0)
if(count == 0)
count = 1
new id
id = Data[0]
iRank[id] = count
return PLUGIN_HANDLED
}