MySQL doesn't save -
x96664 - 26.09.2013
Hi guys, I have a problem with my MySQL system, it doesn't save player stats.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(Logged[playerid] == 1)
{
new query[128];
format (query, sizeof(query), "SELECT `Name` FROM `players` WHERE `Name` = '%s' LIMIT 0,1", GetPName(playerid));
mysql_function_query(IMDb, query, true, "SaveStats", "i", playerid);
}
return 1;
}
public SaveStats(playerid)
{
new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
new query[512], Float:sHealth, Float:sArmor, Float:sX, Float:sY, Float:sZ, Float:sA;
GetPlayerHealth(playerid, sHealth);
GetPlayerArmour(playerid, sArmor);
GetPlayerPos(playerid, sX, sY, sZ);
GetPlayerFacingAngle(playerid, sA);
format(query, sizeof(query), "UPDATE players SET Health = %.1f, Armor = %.1f, Interior = %i, VW = %i, Skin = %i, X = %.1f, Y = %.1f, Z = %.1f, A = %.1f WHERE Name = '%s'", sHealth, sArmor, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), GetPlayerSkin(playerid), sX, sY, sZ, sA, gName);
mysql_function_query(IMDb, query, false, "", "");
}
return 1;
}
When I leave the server it doesn't save none of these.
Re: MySQL doesn't save -
Konstantinos - 26.09.2013
Erm, why don't you update the data in OnPlayerDisconnect instead of selecting first, check if there are rows.. until then, the player won't be in the server anymore.
Moreover, does it print anything in mysql log?
Re: MySQL doesn't save -
zT KiNgKoNg - 26.09.2013
Okay here's an example that you could take and use for the script you're using or creating. (Taken from my custom script)
pawn Код:
stock SaveStats(playerid)
{
format(Query,sizeof(Query),"UPDATE `Accounts` SET `Time` = '%s' WHERE `Username` = '%s'",
GetTime(),
GetOriginalName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
Re: MySQL doesn't save -
Konstantinos - 26.09.2013
Quote:
Originally Posted by zT KiNgKoNg
Okay here's an example that you could take and use for the script you're using or creating. (Taken from my custom script)
pawn Код:
stock SaveStats(playerid) {
format(Query,sizeof(Query),"UPDATE `Accounts` SET `Time` = '%s' WHERE `Username` = '%s'", GetTime(), GetOriginalName(playerid)); mysql_query(Query); mysql_free_result(); return 1; }
|
He uses threaded queries - something you don't (and you should).
Re: MySQL doesn't save -
zT KiNgKoNg - 26.09.2013
Quote:
Originally Posted by Konstantinos
He uses threaded queries - something you don't (and you should).
|
As this section of code is from a old version of the script, and i will not be giving out anything on the updated version.
Re: MySQL doesn't save -
x96664 - 26.09.2013
Quote:
Originally Posted by Konstantinos
Erm, why don't you update the data in OnPlayerDisconnect instead of selecting first, check if there are rows.. until then, the player won't be in the server anymore.
Moreover, does it print anything in mysql log?
|
Well because if the player isn't logged/regged for some reason it shouldnt save him.
No I had some warnings because of the size but I fixed them and now the logs doesnt print anything.
Re: MySQL doesn't save -
Konstantinos - 26.09.2013
Then check if they are!
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(Logged[playerid] == 1)
{
new query[512], Float:sHealth, Float:sArmor, Float:sX, Float:sY, Float:sZ, Float:sA;
GetPlayerHealth(playerid, sHealth);
GetPlayerArmour(playerid, sArmor);
GetPlayerPos(playerid, sX, sY, sZ);
GetPlayerFacingAngle(playerid, sA);
format(query, sizeof(query), "UPDATE players SET Health = %.1f, Armor = %.1f, Interior = %i, VW = %i, Skin = %i, X = %.1f, Y = %.1f, Z = %.1f, A = %.1f WHERE Name = '%s'", sHealth, sArmor, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), GetPlayerSkin(playerid), sX, sY, sZ, sA, gName);
mysql_function_query(IMDb, query, false, "", "");
}
return 1;
}
By the way, if it doesn't save either then you need to make sure for 2 things. That the player is actually logged in (
Logged[playerid] is 1) and that the fields name are correct written or exist. You can make sure about that by running the query to phpMyAdmin.
Re: MySQL doesn't save -
x96664 - 26.09.2013
Quote:
Originally Posted by Konstantinos
You can make sure about that by running the query to phpMyAdmin.
|
How actually to do it ?
Re: MySQL doesn't save -
Konstantinos - 26.09.2013
Quote:
Originally Posted by x96664
How actually to do it ?
|
pawn Код:
format(query, sizeof(query), "UPDATE players SET Health = %.1f, Armor = %.1f, Interior = %i, VW = %i, Skin = %i, X = %.1f, Y = %.1f, Z = %.1f, A = %.1f WHERE Name = '%s'", sHealth, sArmor, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), GetPlayerSkin(playerid), sX, sY, sZ, sA, gName);
print(query);
Copy the output, add ` ` around the fields' name and execute it to phpMyAdmin > select database, select table > SQL > paste > Go!
Re: MySQL doesn't save -
x96664 - 26.09.2013
Quote:
Originally Posted by Konstantinos
Then check if they are!
pawn Код:
public OnPlayerDisconnect(playerid, reason) { if(Logged[playerid] == 1) { new query[512], Float:sHealth, Float:sArmor, Float:sX, Float:sY, Float:sZ, Float:sA; GetPlayerHealth(playerid, sHealth); GetPlayerArmour(playerid, sArmor); GetPlayerPos(playerid, sX, sY, sZ); GetPlayerFacingAngle(playerid, sA); format(query, sizeof(query), "UPDATE players SET Health = %.1f, Armor = %.1f, Interior = %i, VW = %i, Skin = %i, X = %.1f, Y = %.1f, Z = %.1f, A = %.1f WHERE Name = '%s'", sHealth, sArmor, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), GetPlayerSkin(playerid), sX, sY, sZ, sA, gName); mysql_function_query(IMDb, query, false, "", ""); } return 1; }
By the way, if it doesn't save either then you need to make sure for 2 things. That the player is actually logged in ( Logged[playerid] is 1) and that the fields name are correct written or exist. You can make sure about that by running the query to phpMyAdmin.
|
Actually this works, and there is the print:
Код:
UPDATE players SET `Health` = 100.0, `Armor` = 0.0, `Interior` = 0, `VW` = 0, `Skin` = 0, `X` = 1958.3, `Y` = 1343.1, `Z` = 15.3, `A` = 269.1 WHERE `Name` = 'Ryder_Ballaz'
So it now saves, thank you! REP+