11.03.2017, 09:17
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:
I really need a help.
Here is my code:
PHP код:
CMD:savevehs(playerid, params[]){
new string[128];
if(Character[playerid][Admin] < 4) return System_Scm(playerid, PERMISSIONONLY, TYPE_ERROR);
format(string, sizeof(string), "%s has just saved all of the vehicles.", GetPlayerNameEx(playerid));
ScmToAll(COLOR_GREEN, string);
for(new i = 0; i < MAX_VEHICLES; i++){
SQL_SaveCharacterVehicle(i);
}
return 1;
}
CreateCharacterVehicle(playerid, modelid, Float:vposX, Float:vposY, Float:vposZ, Float:vposA, col1, col2){
new vid, query[1024];
vid = CreateVehicle(modelid, vposX, vposY, vposZ, vposA, col1, col2, -1);
CharacterVehicle[vid][cvID] = vid;
format(CharacterVehicle[vid][cvOwnerName], 24, "%s", GetPlayerNameEx(playerid));
format(CharacterVehicle[vid][cvPlate], 8, "Non-R");
GetVehiclePos(vid, CharacterVehicle[vid][cvPosX], CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ]);
GetVehicleZAngle(vid, CharacterVehicle[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(vid, CharacterVehicle[vid][cvVW]);
LinkVehicleToInterior(vid, CharacterVehicle[vid][cvInt]);
mysql_format(MHandle, query, sizeof(query), "INSERT INTO `vehicle` (`ID`, `OwnerName`, `Model`, `Plate`, `Colour1`, `Colour2`, `VW`, `Int`, `Health`, `Fuel`, `posX`, `posY`, `posZ`, `posA`)");
mysql_format(MHandle, query, sizeof(query), "%s VALUES (%d, '%e', %d, '%s', %d, %d, %d, %d, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f)",
query, CharacterVehicle[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(MHandle, query);
printf(query);
return 1;
}
SQL_SaveCharacterVehicle(vid){
new query[1024];
if(CharacterVehicle[vid][cvID] == 0) return 1;
GetVehiclePos(vid, CharacterVehicle[vid][cvPosX], CharacterVehicle[vid][cvPosY], CharacterVehicle[vid][cvPosZ]);
GetVehicleZAngle(vid, CharacterVehicle[vid][cvPosA]);
CharacterVehicle[vid][cvVW] = GetVehicleVirtualWorld(vid);
mysql_format(MHandle, query, sizeof(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(MHandle, query);
printf(query);
return 1;
}
public OnPlayerDisconnect(playerid, reason){
SQL_SaveCharacterInfo(playerid);
SQL_SaveCharacterWeapons(playerid);
for(new i = 0; i < MAX_VEHICLES; i++){
if(!strcmp(CharacterVehicle[i][cvOwnerName], GetPlayerNameEx(playerid))){
SQL_SaveCharacterVehicle(i);
DestroyVehicle(CharacterVehicle[i][cvID]);
}
}
ResetCharacterInfo(playerid);
gCharacterLogged{playerid} = false;
Delete3DTextLabel(pLabel[playerid]);
return 1;
}