MySQL won't save player vehicles?
#1

Hello guys, after a long time, I have came back with pawno. Now, I'm working on the vehicle MySQL system and the problem is I want to save player vehicles when that player disconnect from the server. I think my code is correct but I don't know why it doesn't work unless I use /savevehs command.
Here is my code:
PHP код:
CMD:savevehs(playeridparams[]){
    new 
string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playeridPERMISSIONONLYTYPE_ERROR);
    
format(stringsizeof(string), "%s has just saved all of the vehicles."GetPlayerNameEx(playerid));
    
ScmToAll(COLOR_GREENstring);
    for(new 
0MAX_VEHICLESi++){
        
SQL_SaveCharacterVehicle(i);
    }
    return 
1;
}
CreateCharacterVehicle(playeridmodelidFloat:vposXFloat:vposYFloat:vposZFloat:vposAcol1col2){
    new 
vidquery[1024];
    
vid CreateVehicle(modelidvposXvposYvposZvposAcol1col2, -1);
    
CharacterVehicle[vid][cvID] = vid;
    
format(CharacterVehicle[vid][cvOwnerName], 24"%s"GetPlayerNameEx(playerid));
    
format(CharacterVehicle[vid][cvPlate], 8"Non-R");
    
GetVehiclePos(vidCharacterVehicle[vid][cvPosX], CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ]);
    
GetVehicleZAngle(vidCharacterVehicle[vid][cvPosA]);
    
CharacterVehicle[vid][cvModel] = modelid;
    
CharacterVehicle[vid][cvColour1] = col1;
    
CharacterVehicle[vid][cvColour2] = col2;
    
CharacterVehicle[vid][cvHealth] = 1000.0;
    
CharacterVehicle[vid][cvFuel] = 100.0;
    
CharacterVehicle[vid][cvVW] = GetPlayerVirtualWorld(playerid);
    
CharacterVehicle[vid][cvInt] = GetPlayerInterior(playerid);
    
SetVehicleVirtualWorld(vidCharacterVehicle[vid][cvVW]);
    
LinkVehicleToInterior(vidCharacterVehicle[vid][cvInt]);
    
mysql_format(MHandlequerysizeof(query), "INSERT INTO `vehicle` (`ID`, `OwnerName`, `Model`, `Plate`, `Colour1`, `Colour2`, `VW`, `Int`, `Health`, `Fuel`, `posX`, `posY`, `posZ`, `posA`)");
    
mysql_format(MHandlequerysizeof(query), "%s VALUES (%d, '%e', %d, '%s', %d, %d, %d, %d, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f)",
    
queryCharacterVehicle[vid][cvID], CharacterVehicle[vid][cvOwnerName], CharacterVehicle[vid][cvModel], CharacterVehicle[vid][cvPlate], CharacterVehicle[vid][cvColour1], CharacterVehicle[vid][cvColour2], CharacterVehicle[vid][cvVW], CharacterVehicle[vid][cvInt],
    
CharacterVehicle[vid][cvHealth], CharacterVehicle[vid][cvFuel], CharacterVehicle[vid][cvPosX], CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ], CharacterVehicle[vid][cvPosA]);
    
mysql_query(MHandlequery);
    
printf(query);
    return 
1;
}
SQL_SaveCharacterVehicle(vid){
    new 
query[1024];
    if(
CharacterVehicle[vid][cvID] == 0) return 1;
    
GetVehiclePos(vidCharacterVehicle[vid][cvPosX], CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ]);
    
GetVehicleZAngle(vidCharacterVehicle[vid][cvPosA]);
    
CharacterVehicle[vid][cvVW] = GetVehicleVirtualWorld(vid);
    
mysql_format(MHandlequerysizeof(query), "UPDATE `vehicle` SET `ID` = %d, `Plate` = '%s', `Lock` = %d, `Colour1` = %d, `Colour2` = %d, `VW` = %d, `Int` = %d, `Health` = %0.2f, `Fuel` = %0.2f, `posX` = %0.2f, `posY` = %0.2f, `posZ` = %0.2f, `posA` = %0.2f WHERE `OwnerName` = '%e' AND `ID` = %d",
    
CharacterVehicle[vid][cvID], CharacterVehicle[vid][cvPlate], CharacterVehicle[vid][cvLock], CharacterVehicle[vid][cvColour1], CharacterVehicle[vid][cvColour2], CharacterVehicle[vid][cvVW], CharacterVehicle[vid][cvInt], CharacterVehicle[vid][cvHealth], CharacterVehicle[vid][cvFuel], CharacterVehicle[vid][cvPosX],
    
CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ], CharacterVehicle[vid][cvPosA], CharacterVehicle[vid][cvOwnerName], CharacterVehicle[vid][cvID]);
    
mysql_query(MHandlequery);
    
printf(query);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason){
    
SQL_SaveCharacterInfo(playerid);
    
SQL_SaveCharacterWeapons(playerid);
    for(new 
0MAX_VEHICLESi++){
        if(!
strcmp(CharacterVehicle[i][cvOwnerName], GetPlayerNameEx(playerid))){
            
SQL_SaveCharacterVehicle(i);
            
DestroyVehicle(CharacterVehicle[i][cvID]);
        }
    }
    
ResetCharacterInfo(playerid);
    
gCharacterLogged{playerid} = false;
    
Delete3DTextLabel(pLabel[playerid]);
    return 
1;

I really need a help.
Reply


Messages In This Thread
MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 09:17
Re: MySQL won't save player vehicles? - by Unte99 - 11.03.2017, 09:28
Re: MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 09:32
Re: MySQL won't save player vehicles? - by Unte99 - 11.03.2017, 09:51
Re: MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 10:09
Re: MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 10:11
Re: MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 13:02
Re: MySQL won't save player vehicles? - by DuyDang2412 - 11.03.2017, 13:09
Re: MySQL won't save player vehicles? - by DuyDang2412 - 12.03.2017, 01:42

Forum Jump:


Users browsing this thread: 7 Guest(s)