I have a vehicle creation system. Some vehicles have been removed. The database shows that the vehicle Elegy has ID: 2 and the vehicle Sultan has ID: 3. On the server in vehicles shows me that Elegy has ID 1 and Sultan ID: 2. How to fix it?
Are you talking about the ID from /dl ? That cannot be changed by any way. It's auto-incremented every time you spawn a vehicle. If you don't have a vehicle ID 1, the next spawned vehicle will be ID1 even if you have ID5+
Loop through the existing vehicle's to get the ID. Hard to understand what you mean though. Show us your dialog code
If the vehicle is created, it's ID can't be changed anymore.
It gives the code related to the VID.
Code:
SetupVehicleTable()
{
new query[200];
strcat(query, "CREATE TABLE IF NOT EXISTS `vehicles` ( \
`vehicle_id` int(11) NOT NULL AUTO_INCREMENT, \
`vehicle_model` int(11) default '0', \
PRIMARY KEY (`vehicle_id`))");
mysql_tquery(g_SQL, query);
return 1;
}
enum vInfo
{
vID,
vModel,
Text3D:vLabel,
};
new VehicleInfo[MAX_VEHICLES][vInfo];
new Veh[MAX_VEHICLES];
CreateVehicleCV(model, price, Float:posx, Float:posy, Float:posz, Float:posa, color1, color2)
{
new id, query[300], str[150];
VehicleInfo[id][vID] = CreateVehicle(model, posx, posy, posz, posa, color1, color2, -1);
Veh[VehicleInfo[id][vID]] = id;
VehicleInfo[id][vModel] = model;
SetVehicleToRespawn(VehicleInfo[id][vID]);
format(query, sizeof(query), "INSERT INTO `vehicles` (`vehicle_id`, `vehicle_model`) VALUES ('%d', '%d')", id, model);
mysql_tquery(g_SQL, query);
format(str, sizeof(str), "%s (UID: %d)", GetVehicleNameFromModel(VehicleInfo[id][vModel]), VehicleInfo[id][vID]);
VehicleInfo[id][vLabel] = Create3DTextLabel(str, -1, 0.0, 0.0, 0.0, 50.0, 0);
Attach3DTextLabelToVehicle(VehicleInfo[id][vLabel], VehicleInfo[id][vID], 0.0, 0.0, 1.0);
return VehicleInfo[id][vID];
}
SaveVehicle(xvehid)
{
new query[200];
mysql_format(g_SQL, query, sizeof query, "UPDATE `vehicles` SET `vehicle_model` = %d WHERE `vehicle_id` = %d LIMIT 1", VehicleInfo[xvehid][vModel], xvehid);
mysql_tquery(g_SQL, query);
return 1;
}
forward LoadVehicle();
public LoadVehicle()
{
new rows = cache_num_rows();
new id, loaded;
new str[150];
if(rows)
{
while(loaded < rows)
{
cache_get_value_name_int(loaded, "vehicle_id", id);
cache_get_value_name_int(loaded, "vehicle_model", VehicleInfo[id][vModel]);
VehicleInfo[id][vID] = CreateVehicle(VehicleInfo[id][vModel], 0.0, 0.0, 0.0, 0.0, -1, -1, -1);
Veh[VehicleInfo[id][vID]] = id;
SetVehicleToRespawn(VehicleInfo[id][vID]);
loaded++;
format(str, sizeof(str), "%s (UID: %d)", GetVehicleNameFromModel(VehicleInfo[id][vModel]), VehicleInfo[id][vID]);
VehicleInfo[id][vLabel] = Create3DTextLabel(str, -1, 0.0, 0.0, 0.0, 50.0, 0);
Attach3DTextLabelToVehicle(VehicleInfo[id][vLabel], VehicleInfo[id][vID], 0.0, 0.0, 1.0);
}
}
printf("%d loaded vehicles.", loaded);
return 1;
}
case 777:
{
if(response)
{
new veh, xid;
veh = CreateVehicleCV(VehicleInfo[xid][vModel], strval(inputtext), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
xid = Veh[veh];
PutPlayerInVehicle(playerid, veh, 0);
new str[50];
format(str, sizeof(str), "UID: %d", VehicleInfo[xid][vID]);
SendClientMessage(playerid, -1, str);
}
}
}
I do not describe it correctly. I would like the vehicle_id to be updated in the database. On the screen you can see the vehicle_id 2, 3 and 4 and I would like it to be updated in the order of 1,2 and 3. Or somehow reset the vehicle_id so that it will be in order. I do not know how best.