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;
}
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");
}
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;
}
Once this has finished querying, I then send a new query to the database, getting the data from it and then spawning the vehicle.
|
That's normal. Auto-generated ID's do not get reset or reused. And with reason. For example, this very topic has id 634613 in the database. If it gets deleted then that ID does not get re-used. If it did get reused then all existing links to it would suddenly point to another topic. If you want to start from scratch you should use TRUNCATE TABLE. This deletes all the data and it also resets the auto-increment id. However I don't believe truncate will work if there are foreign keys.
Why? That's extremely counter intuitive. You already have the data so why (again) do you need to query for it? Also what's the deal with prefixing variables with "i"? When I see "i" in front of a variable I think "integer". This makes your code a bitch to read because none of those variables are integers. |
ALTER TABLE DROP `somecolumname`
ALTER TABLE `sometable` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);