SA-MP Forums Archive
Vehicle Plate Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicle Plate Problem (/showthread.php?tid=606498)



Vehicle Plate Problem - ProPoint - 05.05.2016

Hi, i got some problem over here with SQL and Plate. I have the plate database on table `cars` , column `carPlate`. The Problem is, everytime i respawn a car with this command, the car plate is not changing into the number on the Database, but went on 1 or 0, i'm guessing that was the carID instead of carPlate.

Now, the other problem is that, it works fine on loading the vehicle on player connect, when the player is connected and when the car shows up, it shows with the right plate, but when the vehicle being respawned, it changed like i explained above. No idea why.

Here is the /respawncar command.
Код:
CMD:respawncar(playerid, params[])
{
	new vehicleid;

    if (PlayerData[playerid][pAdmin] < 2)
	    return SendErrorMessage(playerid, "You don't have permission to use this command.");

	if (sscanf(params, "d", vehicleid))
	    return SendSyntaxMessage(playerid, "/respawncar [veh]");

	if (vehicleid < 1 || vehicleid > MAX_VEHICLES || !IsValidVehicle(vehicleid))
		return SendErrorMessage(playerid, "You have specified an invalid vehicle ID.");

	Car_Save(vehicleid);
	RespawnVehicle(vehicleid);
	SendServerMessage(playerid, "You have respawned vehicle ID: %d.", vehicleid);

	return 1;
}
RespawnVehicle code:
Код:
	
stock RespawnVehicle(vehicleid)
{
	new id = Car_GetID(vehicleid);

	if (id != -1)
	{
		Car_Spawn(id);
        }
	ResetVehicle(vehicleid);
	return 1;
}
Car_Spawn code:
Код:
stock Car_Spawn(carid)
{
	if (carid != -1 && CarData[carid][carExists])
	{
		if (IsValidVehicle(CarData[carid][carVehicle]))
		    DestroyVehicle(CarData[carid][carVehicle]);

		if (CarData[carid][carColor1] == -1)
		    CarData[carid][carColor1] = random(127);
		    
		if (CarData[carid][carColor2] == -1)
		    CarData[carid][carColor2] = random(127);

        CarData[carid][carVehicle] = CreateVehicle(CarData[carid][carModel], CarData[carid][carPos][0], CarData[carid][carPos][1], CarData[carid][carPos][2], CarData[carid][carPos][3], CarData[carid][carColor1], CarData[carid][carColor2], (CarData[carid][carOwner] != 0) ? (-1) : (1200000));

		if (CarData[carid][carPlate] != -1)
		{
			new string[128],
				platen;

			CarData[carid][carPlate] = cache_get_field_int(carid, "carPlate");
			platen = CarData[carid][carPlate];

			format(string, sizeof(string),"LS-%d", platen);
	                SetVehicleNumberPlate(CarData[carid][carVehicle], string);
			SetVehicleToRespawn(CarData[carid][carVehicle]);
		}
		
		if (CarData[carid][carVehicle] != INVALID_VEHICLE_ID)
        {
            if (CarData[carid][carPaintjob] != -1)
            {
                ChangeVehiclePaintjob(CarData[carid][carVehicle], CarData[carid][carPaintjob]);
			}
			if (CarData[carid][carLocked])
			{
			    new
					engine, lights, alarm, doors, bonnet, boot, objective;

			    GetVehicleParamsEx(CarData[carid][carVehicle], engine, lights, alarm, doors, bonnet, boot, objective);
			    SetVehicleParamsEx(CarData[carid][carVehicle], engine, lights, alarm, 1, bonnet, boot, objective);
			}
			for (new i = 0; i < 14; i ++)
			{
			    if (CarData[carid][carMods][i]) AddVehicleComponent(CarData[carid][carVehicle], CarData[carid][carMods][i]);
			}
   			ResetVehicle(CarData[carid][carVehicle]);
			return 1;
		}
	}
	return 0;
}
I'm asking for help over here, those who might judging my scripting skill instead of helping will be reported right away.


Re: Vehicle Plate Problem - Sew_Sumi - 05.05.2016

PHP код:
 cache_get_field_int(carid"carPlate"); 
It's a string, not an integer.


Re: Vehicle Plate Problem - ProPoint - 05.05.2016

I saw that on another script code, no idea actually why ended up there. Any idea what should i do?


Re: Vehicle Plate Problem - biker122 - 05.05.2016

A number plate always contains a combination of letters and numbers. I don't know how you're assigning the number plate. In case, if you allow the players to use either words or numbers, then you have to fetch the data as a string.
To fetch a string, you have to use cache_get_field_content (..)


Re: Vehicle Plate Problem - Sew_Sumi - 05.05.2016

It's because the plate function is expecting a string to be passed to it, not an integer. You just gotta change the way the value is stored in the SQL, and the script to a string setup.