22.05.2017, 15:19
I'll try to explain this problem to best of my ability, basically I have a command '/acar create < model id / model name.'
This inserts a new row in to the MySQL table `VehicleInfo` (a new vehicle). Once this has finished querying, I then send a new query to the database, getting the data from it and then spawning the vehicle. Although, during testing I created 6 vehicles then empty'd the table but when I go in to the server and create another new vehicle it's registering the ID as 7 instead of 1 again (Note: 1 - 6 vehicle ID's nolonger exist within the table)
I also stopped the server then empty'd the table.
Here is some code:
Command:
CreateNewVehicle function
OnVehicleCreation
This inserts a new row in to the MySQL table `VehicleInfo` (a new vehicle). Once this has finished querying, I then send a new query to the database, getting the data from it and then spawning the vehicle. Although, during testing I created 6 vehicles then empty'd the table but when I go in to the server and create another new vehicle it's registering the ID as 7 instead of 1 again (Note: 1 - 6 vehicle ID's nolonger exist within the table)
I also stopped the server then empty'd the table.
Here is some code:
Command:
PHP код:
if(!strcmp(iParams, "create", true, 6)) {
if(PlayerInfo[playerid][aAdmin] < 4) return SendError(playerid, CANT_USE_CMD);
if(!strlen(iParamsEx)) return SCP(playerid, "/acar create", "< model / id >");
new slctedID;
if(!IsNumeric(iParamsEx)) slctedID = ModelFromName(iParamsEx);
else slctedID = strval(iParamsEx);
if(slctedID < 400 || slctedID > 611) return SCP(playerid, "/acar create", "< model / id >");
new Float:playerX, Float:playerY, Float:playerZ, Float:playerA;
GetPlayerPos(playerid, playerX, playerY, playerZ);
GetPlayerFacingAngle(playerid, playerA);
CreateNewVehicle(PlayerName(playerid), slctedID, playerX, playerY, playerZ, playerA);
new iFormat[159];
format(iFormat, sizeof(iFormat), "(( AdmCmd | {CCCCCC}You have successfully created a new vehicle: %s! {D13F3F}))", VehicleName[slctedID - 400]);
SendPlayerMessage(playerid, 0xD13F3FFF, iFormat, "(( AdmCmd | {CCCCCC}");
return 1;
}
PHP код:
stock CreateNewVehicle(vehOwner[], vehModel, Float:vehX, Float:vehY, Float:vehZ, Float:vehA, vVW = 0, rRes = VEHICLE_OWNED) {
new iQuery[450];
mysql_format(Pipeline, iQuery, sizeof(iQuery), "INSERT INTO `VehicleInfo` (`Owner`, `Model`, `X`, `Y`, `Z`, `A`, `VirtualWorld`, `Type`) VALUES ('%e', %d, %f, %f, %f, %f, %d, %d)", vehOwner, vehModel, vehX, vehY, vehZ, vehA, vVW, rRes);
mysql_tquery(Pipeline, iQuery, "OnVehicleCreation");
}
PHP код:
public OnVehicleCreation() {
new vehicleid = cache_insert_id();
printf("[ON VEHICLE CREATE] %d has been created successfully!", vehicleid);
new iQuery[159]; mysql_format(Pipeline, iQuery, sizeof(iQuery), "SELECT * FROM `VehicleInfo` WHERE `ID` = %d LIMIT 1", vehicleid);
mysql_tquery(Pipeline, iQuery, "OnLoadVehicles", "d", 0);
return 1;
}