Hi, since i use MySql i have a bug on every plugin i use with MySql, i never found the problem.. till now!
The more players are on the server, the more often it happens. Currently there are 18/18 players on the server from ~12am till 1am and it happens like 2-3 times every day, so it's not much, but still annoying.
I store the money in the database and give it to them when they rejoin the server.
The database-structure looks like:
steamid - name - money - more but not important
But sometimes it happens that there are more entries for the same steamid and the money for the steamid is 0 or just the half.
Example correct:
STEAM_1:123 - Schwabba - 1000000
Examples wrong:
STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - -500000
or:
STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - 500000
or:
STEAM_1:123 - Schwabba - 500000
STEAM_1:123 - Schwabba - 0
or:
STEAM_1:123 - Schwabba - 0
STEAM_1:123 - Schwabba - 0
Sometimes there are 10 entries for the same player.
PHP Code:
public Load_MySql(id)
{
if(g_sql_ready)
{
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
format(szTemp,charsmax(szTemp),"SELECT * FROM `furienmoney` WHERE (`furienmoney`.`steamid` = '%s')", szSteamId)
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", 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) // The bug have to be here
{
new szSteamId[32], szName[32], szQuotedName[64]
get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
get_user_name(id, szName, 31) // get user's name
SQL_QuoteString(g_SqlConnection, szQuotedName, 63, szName)
// if its still pending we can't do anything with it
if (equal(szSteamId,"ID_PENDING"))
{
return PLUGIN_HANDLED
}
new szTemp[512]
new time = get_systime()
// now we will insert the values into our table.
format(szTemp,charsmax(szTemp),"INSERT INTO `furienmoney` ( `steamid` , `name` , `money`) VALUES ('%s','%s','0');",
szSteamId, szQuotedName, time, time)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
Save_MySql(id)
}
else
{
// if there are results found
iMoney[id] = SQL_ReadResult(Query, 2)
iMoney2[id] = SQL_ReadResult(Query, 2)
new szLogname[32], szLogauth[32];
get_user_name(id, szLogname, charsmax(szLogname));
get_user_authid(id, szLogauth, charsmax(szLogauth));
log_to_file("Moneylog.txt", "Loaded %i$ of %s (%s).", iMoney[id], szLogname, szLogauth)
set_task(0.2,"give_money", id)
}
g_loaded[id] = true
return PLUGIN_HANDLED
}
public Save_MySql(id)
{
if(g_loaded[id] && iStart[id])
{
new szSteamId[32], szTemp[512], szName[32], szQuotedName[64], money
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_user_name(id, szName, 31)
SQL_QuoteString(g_SqlConnection, szQuotedName, 63, szName)
money = iMoney[id] - iMoney2[id]
format(szTemp,charsmax(szTemp),"UPDATE `furienmoney` SET `name` = '%s', `money` = `money` +%i WHERE `furienmoney`.`steamid` = '%s';",szQuotedName,money,szSteamId)
iMoney2[id] = iMoney[id]
new szLogname[32], szLogauth[32];
get_user_name(id, szLogname, charsmax(szLogname));
get_user_authid(id, szLogauth, charsmax(szLogauth));
log_to_file("Moneylog.txt", "Changed money of %s (%s) to %i$.", szLogname, szLogauth, iMoney[id])
}
}
Someone know how that happens?