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;
}
So neither CreateCharacterVehicle nor SQL_SaveCharacterVehicle doesn't work? mysql_log.txt doesn't show anything at all? If so, debug the code by putting print lines in your code and see how far it goes.
|
INSERT INTO `vehicle` (`ID`, `OwnerName`, `Model`, `Plate`, `Colour1`, `Colour2`, `VW`, `Int`, `Health`, `Fuel`, `posX`, `posY`, `posZ`, `posA`) VALUES (1, 'Daniel_Joyce', 521, 'Non-R', 1, 1, 0, 0, 1000.00, 100.00, 0.00, 0.00, 0.00, 0.00) |
INSERT INTO `vehicle` (`ID`, `OwnerName`, `Model`, `Plate`, `Colour1`, `Colour2`, `VW`, `Int`, `Health`, `Fuel`, `posX`, `posY`, `posZ`, `posA`) VALUES (2, 'Daniel_Joyce', 521, 'Non-R', 1, 2, 0, 0, 1000.00, 100.00, 1390.91, -2379.21, 20.01, 69.96) |
UPDATE `vehicle` SET `ID` = 1, `Plate` = 'Non-R', `Lock` = 0, `Colour1` = 1, `Colour2` = 1, `VW` = 0, `Int` = 0, `Health` = 1000.00, `Fuel` = 100.00, `posX` = 0.00, `posY` = 0.00, `posZ` = 0.00, `posA` = 0.00 WHERE `OwnerName` = 'Daniel_Joyce' AND `ID` = 1 |
UPDATE `vehicle` SET `ID` = 2, `Plate` = 'Non-R', `Lock` = 0, `Colour1` = 1, `Colour2` = 2, `VW` = 0, `Int` = 0, `Health` = 1000.00, `Fuel` = 100.00, `posX` = 1391.02, `posY` = -2378.81, `posZ` = 19.60, `posA` = 70.32 WHERE `OwnerName` = 'Daniel_Joyce' AND `ID` = 2 |
public OnPlayerDisconnect(playerid, reason){
for(new i = 0; i < MAX_VEHICLES; i++){
printf("I : %d | ID : %d | Model : %d", i, CharacterVehicle[i][cvID], CharacterVehicle[i][cvModel]);
if(CharacterVehicle[i][cvModel] == 0) continue;
if(strcmp(GetPlayerNameEx(playerid), CharacterVehicle[i][cvOwnerName])) continue;
SQL_SaveCharacterVehicle(CharacterVehicle[i][cvID]);
DestroyVehicle(CharacterVehicle[i][cvID]);
ResetCharacterVehicle(CharacterVehicle[i][cvID]);
}
SQL_SaveCharacterInfo(playerid);
SQL_SaveCharacterWeapons(playerid);
ResetCharacterInfo(playerid);
gCharacterLogged{playerid} = false;
Delete3DTextLabel(pLabel[playerid]);
return 1;
}
SQL_SaveCharacterVehicle(vid){
new query[1024];
if(CharacterVehicle[vid][cvModel] == 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;
}
CreateCharacterVehicle(playerid, modelid, Float:vposX, Float:vposY, Float:vposZ, Float:vposA, col1, col2){
new query[1024];
for(new i = 0; i < MAX_VEHICLES; i++){
if(CharacterVehicle[i][cvModel] != 0 || GetVehicleModel(i) != 0) continue;
CharacterVehicle[i][cvID] = CreateVehicle(modelid, vposX, vposY, vposZ, vposA, col1, col2, -1);
format(CharacterVehicle[i][cvOwnerName], 24, "%s", GetPlayerNameEx(playerid));
format(CharacterVehicle[i][cvPlate], 8, "Non-R");
CharacterVehicle[i][cvPosX] = vposX;
CharacterVehicle[i][cvPosY] = vposY;
CharacterVehicle[i][cvPosZ] = vposZ;
CharacterVehicle[i][cvPosA] = vposA;
CharacterVehicle[i][cvModel] = modelid;
CharacterVehicle[i][cvColour1] = col1;
CharacterVehicle[i][cvColour2] = col2;
CharacterVehicle[i][cvHealth] = 1000.0;
CharacterVehicle[i][cvFuel] = 100.0;
CharacterVehicle[i][cvVW] = GetPlayerVirtualWorld(playerid);
CharacterVehicle[i][cvInt] = GetPlayerInterior(playerid);
SetVehicleVirtualWorld(i, CharacterVehicle[i][cvVW]);
LinkVehicleToInterior(i, CharacterVehicle[i][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[i][cvID], CharacterVehicle[i][cvOwnerName], CharacterVehicle[i][cvModel], CharacterVehicle[i][cvPlate], CharacterVehicle[i][cvColour1], CharacterVehicle[i][cvColour2], CharacterVehicle[i][cvVW], CharacterVehicle[i][cvInt],
CharacterVehicle[i][cvHealth], CharacterVehicle[i][cvFuel], CharacterVehicle[i][cvPosX], CharacterVehicle[i][cvPosY], CharacterVehicle[CharacterVehicle[i][cvID]][cvPosZ], CharacterVehicle[i][cvPosA]);
mysql_query(MHandle, query);
printf(query);
return 1;
}
return 1;
}