14.12.2015, 13:58
So hello, i started using mysql and made a simple login/register system the problem is when the player registers gets 20k money, 1score and when he leaves it dosen't save. but when i edit the player in mysql database and give him 20k go to a shop and lose 2 dollars it saves.
my register code:
my save player function and onplayerdisconnect
my register code:
PHP код:
if(dialogid==DIALOG_REGISTER)
{
if(response)
{
new name[MAX_PLAYER_NAME],query[128],passwort[35];
GetPlayerName(playerid,name,sizeof(name));
if(strlen(inputtext)>3)
{
mysql_escape_string(inputtext,passwort,dbhandle);
format(query,sizeof(query),"INSERT INTO user (username,password) VALUES ('%s',MD5('%s')) ",name,passwort);
mysql_function_query(dbhandle,query,false,"","");
TogglePlayerSpectating(playerid, false);
SetSpawnInfo(playerid, 0, 240, 405.7584,-1540.9410,32.2734,230.5244, 0,0,0,0,0,0);
SpawnPlayer(playerid);
SetPlayerMoney(playerid, 20000);
SetPlayerScore(playerid, 1);
pInfo[playerid][logged] = 1;
}
PHP код:
savePlayer(playerid)
{
if(pInfo[playerid][logged]==0)return 1;
//Speichern level,money
new query[128];
format(query,sizeof(query),"UPDATE user SET level='%i',money='%i' WHERE id='%i'",pInfo[playerid][level],GetPlayerMoney(playerid),pInfo[playerid][id]);
mysql_function_query(dbhandle,query,false,"","");
return 1;
}
resetPlayer(playerid)
{
pInfo[playerid][level]=0;
pInfo[playerid][logged]=0;
pInfo[playerid][id]=0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
savePlayer(playerid);
resetPlayer(playerid);
return 1;
}