SetVehicleNumberPlate bug.
#1

I have made a simple system for vehicles, everything is working great, saving and loading, except one part lemme explain.
i've created 4 vehicles, they're spawned with vehicle id 1,2,3,4 like usually i made the system will create a random plate number for example: RL33NN
it will be created for vehicle id 1 and 2 and 3 except 4.. it has the regular one, i've tried to make a command for example setting vehicle plate number in game and respawning the vehicle.. when i choosed id 4 actually it doesn't set the vehicle id 4 it does for 3 instead, that's the only problem, thanks for reading.
Reply
#2

maybe there is problem with loops.
Remember that numerating starts from 0, not 1
Reply
#3

Post your code.

@czerwony03, vehicle IDs start at 1, not 0.
Reply
#4

I thought this was removed in 0.3z, lol. Anyways, can you show us the code?
Reply
#5

Actually yeah, the first vehicle spawned with car id 1

when the vehicle created.
Quote:

new
string[64],
id,
name[64];

id = random(33);
name = "SS";

format(string, sizeof(string), "LS:%d%s", id, name);
SetVehicleNumberPlate(i, string);
format(CarData[i][carNumberPlate], 32, string);

When the car spawned.
Quote:

SetVehicleNumberPlate(carid, CarData[carid][carNumberPlate]);

Vehicle load.
Quote:
Quote:

cache_get_field_content(i, "carNumberPlate", CarData[i][carNumberPlate], g_iHandle, 32);

i did printf and it works loading them all.

When it's saved.
Quote:

format(query, sizeof(query), "%s, `carNumberPlate` = '%s' WHERE `carID` = '%d'",
query,
CarData[carid][carNumberPlate],
CarData[carid][carID]
);

if you the whole codes. just say.
Reply
#6

Bump.
Reply
#7

Yeah whole code.
Reply
#8

here is it.
EDIT:
the car is saved in SQL
http://prntscr.com/amnyhj
and it's loading successfuly.
http://prntscr.com/amnykr

Vehicles IG
http://prntscr.com/amnz51
http://prntscr.com/amnz91

EDIT:
Everything is working for the vehicle paintjob and color, everything! except numberplate.
Код:
enum carData {
	carID,
	carExists,
	carModel,
	carOwner,
	carKeys,
	Float:carPos[4],
	carColor1,
	carColor2,
	carPaintjob,
	carLocked,
	carEngine,
	carLights,
 	carMods[14],
	carImpounded,
	carImpoundPrice,
	carFaction,
	carJob,
	carGang,
	carWeapons[5],
	carAmmo[5],
	carVehicle,
 	carNumberPlate[32 char]
};
Код:
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][carEngine] = 0;
		CarData[carid][carLights] = 0;
		
		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));

		SetVehicleNumberPlate(carid, CarData[carid][carNumberPlate]);

		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;
}

forward Car_Load();
public Car_Load()
{
	static
	    rows,
	    fields,
		str[128];

	cache_get_data(rows, fields, g_iHandle);

	for (new i = 0; i < rows; i ++) if (i < MAX_DYNAMIC_CARS)
	{
	    CarData[i][carExists] = true;
	    CarData[i][carID] = cache_get_field_int(i, "carID");
	    CarData[i][carModel] = cache_get_field_int(i, "carModel");
	    CarData[i][carOwner] = cache_get_field_int(i, "carOwner");
	    CarData[i][carKeys] = cache_get_field_int(i, "carKeys");
	    CarData[i][carPos][0] = cache_get_field_float(i, "carPosX");
	    CarData[i][carPos][1] = cache_get_field_float(i, "carPosY");
	    CarData[i][carPos][2] = cache_get_field_float(i, "carPosZ");
	    CarData[i][carPos][3] = cache_get_field_float(i, "carPosR");
	    CarData[i][carColor1] = cache_get_field_int(i, "carColor1");
	    CarData[i][carColor2] = cache_get_field_int(i, "carColor2");
	    CarData[i][carPaintjob] = cache_get_field_int(i, "carPaintjob");
	    CarData[i][carLocked] = cache_get_field_int(i, "carLocked");
	    CarData[i][carImpounded] = cache_get_field_int(i, "carImpounded");
	    CarData[i][carImpoundPrice] = cache_get_field_int(i, "carImpoundPrice");
        CarData[i][carFaction] = cache_get_field_int(i, "carFaction");
        CarData[i][carJob] = cache_get_field_int(i, "carJob");
        CarData[i][carGang] = cache_get_field_int(i, "carGang");
        
        cache_get_field_content(i, "carNumberPlate", CarData[i][carNumberPlate], g_iHandle, 32);
        
        printf("%s", CarData[i][carNumberPlate]);

		for (new j = 0; j < 14; j ++)
		{
		    if (j < 5)
		    {
		        format(str, sizeof(str), "carWeapon%d", j + 1);
		        CarData[i][carWeapons][j] = cache_get_field_int(i, str);

		        format(str, sizeof(str), "carAmmo%d", j + 1);
		        CarData[i][carAmmo][j] = cache_get_field_int(i, str);
	        }
	        format(str, sizeof(str), "carMod%d", j + 1);
	        CarData[i][carMods][j] = cache_get_field_int(i, str);
	    }
	    Car_Spawn(i);
	}
	for (new i = 0; i < MAX_DYNAMIC_CARS; i ++) if (CarData[i][carExists]) {
		format(str, sizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'", CarData[i][carID]);

		mysql_tquery(g_iHandle, str, "OnLoadCarStorage", "d", i);
	}
	return 1;
}
Код:
Car_Create(ownerid, modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, type = 0)
{
    for (new i = 0; i != MAX_DYNAMIC_CARS; i ++)
	{
		if (!CarData[i][carExists])
   		{
   		    if (color1 == -1)
   		        color1 = random(127);

			if (color2 == -1)
			    color2 = random(127);

   		    CarData[i][carExists] = true;
            CarData[i][carModel] = modelid;
            CarData[i][carOwner] = ownerid;
            CarData[i][carKeys] = 0;

            CarData[i][carPos][0] = x;
            CarData[i][carPos][1] = y;
            CarData[i][carPos][2] = z;
            CarData[i][carPos][3] = angle;

            CarData[i][carColor1] = color1;
            CarData[i][carColor2] = color2;
            CarData[i][carPaintjob] = -1;
            CarData[i][carLocked] = false;
            CarData[i][carEngine] = false;
            CarData[i][carLights] = false;
            CarData[i][carImpounded] = -1;
            CarData[i][carImpoundPrice] = 0;
            CarData[i][carGang] = -1;
            CarData[i][carJob] = -1;
            CarData[i][carFaction] = type;

			new
				string[64],
				id,
				name[64];

			id = random(33);
   			name = "SS";

			format(string, sizeof(string), "LS:%d%s", id, name);
			SetVehicleNumberPlate(i, string);
			format(CarData[i][carNumberPlate], 32, string);

            for (new j = 0; j < 14; j ++)
			{
                if (j < 5)
				{
                    CarData[i][carWeapons][j] = 0;
                    CarData[i][carAmmo][j] = 0;
                }
                CarData[i][carMods][j] = 0;
            }
            CarData[i][carVehicle] = CreateVehicle(modelid, x, y, z, angle, color1, color2, -1);

            if (CarData[i][carVehicle] != INVALID_VEHICLE_ID) {
                ResetVehicle(CarData[i][carVehicle]);
            }
            mysql_tquery(g_iHandle, "INSERT INTO `cars` (`carModel`) VALUES(0)", "OnCarCreated", "d", i);
            return i;
		}
	}
	return -1;
}
Код:
Car_Save(carid)
{
	static
	    query[900];

	if (CarData[carid][carVehicle] != INVALID_VEHICLE_ID)
	{
	    for (new i = 0; i < 14; i ++) {
			CarData[carid][carMods][i] = GetVehicleComponentInSlot(CarData[carid][carVehicle], i);
	    }
	}
	format(query, sizeof(query), "UPDATE `cars` SET `carModel` = '%d', `carOwner` = '%d', `carPosX` = '%.4f', `carPosY` = '%.4f', `carPosZ` = '%.4f', `carPosR` = '%.4f', `carColor1` = '%d', `carColor2` = '%d', `carPaintjob` = '%d',`carGang` = '%d',`carLocked` = '%d', `carEngine` = '%d', `carLights` = '%d'",
        CarData[carid][carModel],
        CarData[carid][carOwner],
        CarData[carid][carPos][0],
        CarData[carid][carPos][1],
        CarData[carid][carPos][2],
        CarData[carid][carPos][3],
        CarData[carid][carColor1],
        CarData[carid][carColor2],
        CarData[carid][carPaintjob],
        CarData[carid][carGang],
        CarData[carid][carLocked],
        CarData[carid][carEngine],
        CarData[carid][carLights]
	);
	format(query, sizeof(query), "%s, `carMod1` = '%d', `carMod2` = '%d', `carMod3` = '%d', `carMod4` = '%d', `carMod5` = '%d', `carMod6` = '%d', `carMod7` = '%d', `carMod8` = '%d', `carMod9` = '%d', `carMod10` = '%d', `carMod11` = '%d', `carMod12` = '%d', `carMod13` = '%d', `carMod14` = '%d'",
		query,
		CarData[carid][carMods][0],
		CarData[carid][carMods][1],
		CarData[carid][carMods][2],
		CarData[carid][carMods][3],
		CarData[carid][carMods][4],
		CarData[carid][carMods][5],
		CarData[carid][carMods][6],
		CarData[carid][carMods][7],
		CarData[carid][carMods][8],
		CarData[carid][carMods][9],
		CarData[carid][carMods][10],
		CarData[carid][carMods][11],
		CarData[carid][carMods][12],
		CarData[carid][carMods][13]
	);
	format(query, sizeof(query), "%s, `carImpounded` = '%d', `carImpoundPrice` = '%d', `carFaction` = '%d', `carWeapon1` = '%d', `carWeapon2` = '%d', `carWeapon3` = '%d', `carWeapon4` = '%d', `carWeapon5` = '%d', `carAmmo1` = '%d', `carAmmo2` = '%d', `carAmmo3` = '%d', `carAmmo4` = '%d', `carAmmo5` = '%d', `carJob` = '%d', `carKeys` = '%d'",
		query,
		CarData[carid][carImpounded],
		CarData[carid][carImpoundPrice],
		CarData[carid][carFaction],
		CarData[carid][carWeapons][0],
		CarData[carid][carWeapons][1],
		CarData[carid][carWeapons][2],
		CarData[carid][carWeapons][3],
		CarData[carid][carWeapons][4],
		CarData[carid][carAmmo][0],
		CarData[carid][carAmmo][1],
		CarData[carid][carAmmo][2],
		CarData[carid][carAmmo][3],
		CarData[carid][carAmmo][4],
		CarData[carid][carJob],
		CarData[carid][carKeys]
	);
	format(query, sizeof(query), "%s, `carNumberPlate` = '%s' WHERE `carID` = '%d'",
	    query,
	    CarData[carid][carNumberPlate],
	    CarData[carid][carID]
	);
	return mysql_tquery(g_iHandle, query);
}
Reply
#9

This bug from my script or samp??
Reply
#10

bump
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)