Dialog ID vehicle
#1

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?
Reply
#2

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+
Reply
#3

Loop through the existing vehicle's to get the ID. Hard to understand what you mean though. Show us your dialog code
Reply
#4

If the vehicle is created, it's ID can't be changed anymore.
To create vehicles within the avaliable IDs, use a loop like this:
pawn Code:
new ArrayThatStoresTheCreatedVehicles[] = {INVALID_VEHICLE_ID, ...};

getFreeVehicleSlot() {
  for(new i = 0, j = sizeof ArrayThatStoresTheCreatedVehicles; i < j; i++) {
    if(ArrayThatStoresTheCreatedVehicles[i] != INVALID_VEHICLE_ID) return i;
  }
  return -1;
}

// usage

static vehid = getFreeVehicleSlot();
if(vehid != -1) {
  // Create the vehicle with vehid;
} else return print("Max vehicles limit reached.");
Reply
#5

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);
		}
	}
}
Reply
#6

Use a for loop instead of while..do

If you insist, start counting from 1: new id, loaded = 1;
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)