Command to save accounts
#1

Hi,
I need your help.
My gamemod is connect with a MySql DB but there is a problem.
When I register an account, at the relog the account result registered but all things that I has are lost.

I need a command to save accounts stats from the server. Someone can help me?

Example:
/savedb (the command will save accounts stats)
Reply
#2

You are not saving the player's stats when they quit, or disconnect. Instead of a command, just put the saving code in OnPlayerDisconnect(playerid, reason).

BTW, if you supplied your DB Name and the fields you would like to save, I can give you the code for it.
Reply
#3

So, this is my OnPlayerDisconnect.

PHP Code:
public OnPlayerDisconnect(playeridreason) {
    if(
usingcarwash == playerid)
    {
        
SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        
usingcarwash = -1;
        
Update3DTextLabelText(entrancetext0x008B00FF"Autolavaggio libero, suona il clacson per lavare\nla tua auto, ($5)");
    }
    
Delete3DTextLabel(playerID[playerid]);
    
#if defined FOR_EACH
    
Itter_Remove(HSVictimplayerid);
    
#endif
    
for(new i=0;i<4;i++)
    {
    
RemovePlayerAttachedObject(playerid,i);
    }
    if(
RentedVehicle[playerid]!=0)
    {
    
vehicleVariables[RentedVehicle[playerid]][Rented]=0;
    
SetVehicleToRespawn(RentedVehicle[playerid]);
    
RentedVehicle[playerid]=0;
    }
    
DrugOnPlayerDisconnect(playeridreason);
    
KillTimer(timer[playerid]);
    
KillTimer(timer2[playerid]);
    
TextDrawDestroy(Fuel0[playerid]);
    
TextDrawDestroy(Speedom[playerid]);
    if(
PlayerAccount[playerid][Logged]) SavePlayerAccount(playerid);
    
FadePlayerDisconnect(playerid);
    
TextDrawDestroy(Speedo[playerid]);
    if (
BizRobPlayer==playerid)
    {
        
BizRobPlayer 255;
        
CanRob 0;
        
BizRobTime = -1;
        
SendClientMessageToAll(COLOR_LIGHTBLUE"Il rapinatore si и disconnesso, rapina fallita.");
    }
    for(new 
vehid=0;vehid<MAX_VEHICLES;vehid++)
        {
            
GetPlayerName(playeridpnamesizeof (pname));
            if(
strlen(pname)==strlen(vehicleVariables[vehid][vOwner]) && !strcmp(pname,vehicleVariables[vehid][vOwner],false,MAX_PLAYER_NAME) && vehicleVariables[vehid][vOwned])
            {
            
SavePlayerVehicle(vehid);
            
DestroyVehicle(vehicleVariables[vehid][vVehicleScriptID]);
            }
            }
     
SavePlayerAccount(playerid);
    return 
1;

Here my DB name:
PHP Code:
#define SQL_DB "fenice17_project" 
Here an image of my DB:


I need to save:
- Moneys
- Houses
- Levels & Experience
- Vehicles
- Businesses
- Objects like cigarettes, bandages, glasses exc...
Reply
#4

The query should be like this:

Code:
format(x, sizeof(x), "UPDATE `users` SET p_level = %i, p_case = %i, p_score = %i WHERE Name = '%s'", pInfo[playerid][pLevel], pInfo[playerid][pCash], pInfo[playerid][pScore], pInfo[playerid][pName]);
Reply
#5

Quote:
Originally Posted by MP2
View Post
The query should be like this:

Code:
format(x, sizeof(x), "UPDATE `users` SET p_level = %i, p_case = %i, p_score = %i WHERE Name = '%s'", pInfo[playerid][pLevel], pInfo[playerid][pCash], pInfo[playerid][pScore], pInfo[playerid][pName]);
I have to add this under OnPlayerDisconnect? If not, where?
Reply
#6

Yes. Check if they are registered, though.
Reply
#7

Quote:
Originally Posted by MP2
View Post
Yes. Check if they are registered, though.
Here the errors:


Here the new OnPlayerDisconnect (16910 is the first line):
PHP Code:
public OnPlayerDisconnect(playeridreason) {
    
format(xsizeof(x), "UPDATE `users` SET p_level = %i, p_case = %i, p_score = %i WHERE Name = '%s'"pInfo[playerid][pLevel], pInfo[playerid][pCash], pInfo[playerid][pScore], pInfo[playerid][pName]);
    if(
usingcarwash == playerid)
    {
        
SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        
usingcarwash = -1;
        
Update3DTextLabelText(entrancetext0x008B00FF"Autolavaggio libero, suona il clacson per lavare\nla tua auto, ($5)");
    }
    
Delete3DTextLabel(playerID[playerid]);
    
#if defined FOR_EACH
    
Itter_Remove(HSVictimplayerid);
    
#endif
    
for(new i=0;i<4;i++)
    {
    
RemovePlayerAttachedObject(playerid,i);
    }
    if(
RentedVehicle[playerid]!=0)
    {
    
vehicleVariables[RentedVehicle[playerid]][Rented]=0;
    
SetVehicleToRespawn(RentedVehicle[playerid]);
    
RentedVehicle[playerid]=0;
    }
    
DrugOnPlayerDisconnect(playeridreason);
    
KillTimer(timer[playerid]);
    
KillTimer(timer2[playerid]);
    
TextDrawDestroy(Fuel0[playerid]);
    
TextDrawDestroy(Speedom[playerid]);
    if(
PlayerAccount[playerid][Logged]) SavePlayerAccount(playerid);
    
FadePlayerDisconnect(playerid);
    
TextDrawDestroy(Speedo[playerid]);
    if (
BizRobPlayer==playerid)
    {
        
BizRobPlayer 255;
        
CanRob 0;
        
BizRobTime = -1;
        
SendClientMessageToAll(COLOR_LIGHTBLUE"Il rapinatore si и disconnesso, rapina fallita.");
    }
    for(new 
vehid=0;vehid<MAX_VEHICLES;vehid++)
        {
            
GetPlayerName(playeridpnamesizeof (pname));
            if(
strlen(pname)==strlen(vehicleVariables[vehid][vOwner]) && !strcmp(pname,vehicleVariables[vehid][vOwner],false,MAX_PLAYER_NAME) && vehicleVariables[vehid][vOwned])
            {
            
SavePlayerVehicle(vehid);
            
DestroyVehicle(vehicleVariables[vehid][vVehicleScriptID]);
            }
            }
     
SavePlayerAccount(playerid);
    return 
1;

Reply
#8

x needs to be defined as an array and you need to send the query.
Reply
#9

Quote:
Originally Posted by dr.pepper
View Post
x needs to be defined as an array
Can u show me an example? Cause my array show others errors.
Reply
#10

pawn Code:
new x[1024];
add this CallBack:

pawn Code:
forward SendQuery(query[]);
public SendQuery(query[]) {
    CheckSQL();
    if (mysql_query(query)) {
        printf("[MYSQL] MySQL query successful. (%s)", query);
    }
    else {
        printf("[MYSQL] MySQL query unsuccessful. (%s)", query);
        return false;
    }
    return 1;
}
then

pawn Code:
format(x, sizeof(x), "UPDATE `users` SET p_level = %i, p_case = %i, p_score = %i WHERE Name = '%s'", pInfo[playerid][pLevel], pInfo[playerid][pCash], pInfo[playerid][pScore], pInfo[playerid][pName]);
SendQuery(x);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)