Saving vehicle damages
#1

Hi, I just made it like that vehicle damages will save. Everything works except Car_Load. Like everything except visual damage works in Car_Load. Here are Car_Load, Car_Spawn and Car_Save.

Код:
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)
	{
		cache_get_field_content(i, "carPlate", CarData[i][carPlate], g_iHandle, 16);
		
	    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][carFuel] = cache_get_field_int(i, "carFuel");
		CarData[i][carHealth] = cache_get_field_float(i, "carHealth");
	    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][carLock] = cache_get_field_int(i, "carLock");
		CarData[i][carAlarm] = cache_get_field_int(i, "carAlarm");
	    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");

		cache_get_field_content(0, "carDamage", str, g_iHandle);
		sscanf(str, "p<|>dddd", CarDamage[i][0], CarDamage[i][1], CarDamage[i][2], CarDamage[i][3]);
		
		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_Save(carid)
{
	static
	    query[1000];

	if (CarData[carid][carVehicle] != INVALID_VEHICLE_ID)
	{
	    for (new i = 0; i < 14; i ++) {
			CarData[carid][carMods][i] = GetVehicleComponentInSlot(CarData[carid][carVehicle], i);
	    }
		GetVehicleDamageStatus(CarData[carid][carVehicle], CarDamage[carid][0], CarDamage[carid][1], CarDamage[carid][2], CarDamage[carid][3]);
		GetVehicleHealth(CarData[carid][carVehicle], CarData[carid][carHealth]);
		CarData[carid][carFuel] = CoreVehicles[CarData[carid][carVehicle]][vehFuel];
	}
	format(query, sizeof(query), "UPDATE `cars` SET `carModel` = '%d', `carOwner` = '%d', `carFuel` = '%d', `carHealth` = '%.1f', `carPlate` = '%s', `carPosX` = '%.4f', `carPosY` = '%.4f', `carPosZ` = '%.4f', `carPosR` = '%.4f', `carColor1` = '%d', `carColor2` = '%d', `carPaintjob` = '%d', `carLocked` = '%d', `carLock` = '%d', `carAlarm` = '%d'",
        CarData[carid][carModel],
        CarData[carid][carOwner],
		CarData[carid][carFuel],
		CarData[carid][carHealth],
		CarData[carid][carPlate],
        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][carLocked],
		CarData[carid][carLock],
		CarData[carid][carAlarm]
	);
	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'",
		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]
	);
	format(query, sizeof(query), "%s, `carDamage` = '%d|%d|%d|%d' WHERE `carID` = '%d'",
		query,
		CarDamage[carid][0],
		CarDamage[carid][1],
		CarDamage[carid][2],
		CarDamage[carid][3],
		CarData[carid][carID]
	);
	return mysql_tquery(g_iHandle, query);
}

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][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]);
			}
			SetVehicleNumberPlate(CarData[carid][carVehicle], CarData[carid][carPlate]);
			
			SetVehicleHealth(CarData[carid][carVehicle], CarData[carid][carHealth]);
			UpdateVehicleDamageStatus(CarData[carid][carVehicle], CarDamage[carid][0], CarDamage[carid][1], CarDamage[carid][2], CarDamage[carid][3]);
			
			CoreVehicles[CarData[carid][carVehicle]][vehFuel] = CarData[carid][carFuel];
   			ResetVehicle(CarData[carid][carVehicle]);
			return 1;
		}
	}
	return 0;
}
The problem should be in this line in Car_Load:
Код:
cache_get_field_content(0, "carDamage", str, g_iHandle);
sscanf(str, "p<|>dddd", CarDamage[i][0], CarDamage[i][1], CarDamage[i][2], CarDamage[i][3]);
What's wrong with it?
Reply
#2

Oh, I see the problem is not in that. There's a problem in saving I guess as this is what my car's health is in MySQL: 35651584|131586|0|0
Reply
#3

Anyone?
Reply
#4

welp
PHP код:
            UpdateVehicleDamageStatus(CarData[carid][carVehicle], CarDamage[carid][0], CarDamage[carid][1], CarDamage[carid][2], CarDamage[carid][3]);
            
            
CoreVehicles[CarData[carid][carVehicle]][vehFuel] = CarData[carid][carFuel];
               
ResetVehicle(CarData[carid][carVehicle]); 
Updating the damage and then resetting the vehicle?

xD
Reply
#5

Yeah, resetting vehicle closes the windows, etc and resets fuel if vehicle is not owned. It doesn't repair the vehicle.
By the way, I don't see anything wrong in my code, what would be wrong with it?
Reply
#6

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
Yeah, resetting vehicle closes the windows, etc and resets fuel if vehicle is not owned. It doesn't repair the vehicle.
By the way, I don't see anything wrong in my code, what would be wrong with it?
What happends when you change this:
PHP код:
            UpdateVehicleDamageStatus(CarData[carid][carVehicle], CarDamage[carid][0], CarDamage[carid][1], CarDamage[carid][2], CarDamage[carid][3]);
            
            
CoreVehicles[CarData[carid][carVehicle]][vehFuel] = CarData[carid][carFuel];
               
ResetVehicle(CarData[carid][carVehicle]); 
To this:

PHP код:
            CoreVehicles[CarData[carid][carVehicle]][vehFuel] = CarData[carid][carFuel];
               
ResetVehicle(CarData[carid][carVehicle]);  
UpdateVehicleDamageStatus(CarData[carid][carVehicle], CarDamage[carid][0], CarDamage[carid][1], CarDamage[carid][2], CarDamage[carid][3]); 
Reply
#7

I told you, there's nothing to do with ResetVehicle. /park is done with Car_Spawn as well and it works properly. There's a problem in either Car_Load or Car_Save.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)