SA-MP Forums Archive
Vehicle stats wont load - 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 stats wont load (/showthread.php?tid=632475)



Vehicle stats wont load - penaut - 14.04.2017

To be 100% correct the HP, Panels, Doors, Tires does load up, but the script is not changing the car IG.

Код:
LoadVehicles()
{
	new string[64];
	new File:handle, count;
	new filename[64], line[256], s, key[64];
	for(new i=1; i < MAX_DVEHICLES; i++)
	{
		format(filename, sizeof(filename), VEHICLE_FILE_PATH "v%d.ini", i);
		if(!fexist(filename)) continue;
		handle = fopen(filename, io_read);
		while(fread(handle, line))
		{
			StripNL(line);
			s = strfind(line, "=");
			if(!line[0] || s < 1) continue;
			strmid(key, line, 0, s++);
			if(strcmp(key, "Created") == 0) VehicleCreated[i] = strval(line[s]);
			else if(strcmp(key, "Model") == 0) VehicleModel[i] = strval(line[s]);
			else if(strcmp(key, "Pos") == 0) sscanf(line[s], "p<,>ffff", VehiclePos[i][0], VehiclePos[i][1], VehiclePos[i][2], VehiclePos[i][3]);
			else if(strcmp(key, "Colors") == 0) sscanf(line[s], "p<,>dd", VehicleColor[i][0], VehicleColor[i][1]);
			else if(strcmp(key, "Interior") == 0) VehicleInterior[i] = strval(line[s]);
			else if(strcmp(key, "VirtualWorld") == 0) VehicleWorld[i] = strval(line[s]);
			else if(strcmp(key, "Owner") == 0) strmid(VehicleOwner[i], line, s, sizeof(line));
			else if(strcmp(key, "NumberPlate") == 0) strmid(VehicleNumberPlate[i], line, s, sizeof(line));
			else if(strcmp(key, "Value") == 0) VehicleValue[i] = strval(line[s]);
			else if(strcmp(key, "Lock") == 0) VehicleLock[i] = strval(line[s]);
			else if(strcmp(key, "Alarm") == 0) VehicleAlarm[i] = strval(line[s]);
			else if(strcmp(key, "Paintjob") == 0) VehiclePaintjob[i] = strval(line[s]);
			else if(strcmp(key, "Uzemanyag") == 0) VehicleUzemanyag[i] = strval(line[s]);
			else if(strcmp(key, "UzemanyagMax") == 0) VehicleUzemanyagMax[i] = strval(line[s]);
			else if(strcmp(key, "HP") == 0) carHP[i] = strval(line[s]);
			else if(strcmp(key, "Panels") == 0) carPanels[i] = strval(line[s]);
			else if(strcmp(key, "Doors") == 0) carDoors[i] = strval(line[s]);
			else if(strcmp(key, "Lights") == 0) carLights[i] = strval(line[s]);
			else if(strcmp(key, "Tires") == 0) carTires[i] = strval(line[s]);
			else
			{
				for(new t=0; t < sizeof(VehicleTrunk[]); t++)
				{
					format(string, sizeof(string), "Trunk%d", t+1);
					if(strcmp(key, string) == 0) sscanf(line[s], "p<,>dd", VehicleTrunk[i][t][0], VehicleTrunk[i][t][1]);
				}
				for(new m=0; m < sizeof(VehicleMods[]); m++)
				{
					format(string, sizeof(string), "Mod%d", m);
					if(strcmp(key, string) == 0) VehicleMods[i][m] = strval(line[s]);
				}
			}
	}
		new kocsiid = VehicleID[i];
		CreateVehicle(VehicleModel[i],VehiclePos[i][0],VehiclePos[i][1],VehiclePos[i][2],VehiclePos[i][3],VehicleColor[i][0],VehicleColor[i][1],-1,0);
		SetVehicleVirtualWorld(VehicleID[i], 0);
		VehicleWorld[i] = 0;
		SetVehiclePos(VehicleID[i], VehiclePos[i][0], VehiclePos[i][1], VehiclePos[i][2]);
		SetVehicleZAngle(VehicleID[i], VehiclePos[i][3]);
		UpdateVehicleDamageStatus(VehicleID[i], carPanels[i], carDoors[i], carLights[i], carTires[i]);
		SetVehicleHealth(VehicleID[i], carHP[i]);
			
		SetVehicleParamsEx(VehicleID[i], 0, 0, 0, 0, 0, 0, 0);
		
		fclose(handle);
		if(VehicleCreated[i]) count++;
	}
	printf("%d veh loaded", count);
	printf("[Panels] : %d - [Doors] : %d - [Lights] : %d - [Tires] : %d",carPanels[1], carDoors[1], carLights[1], carTires[1]); //id 1 car datas
}



Re: Vehicle stats wont load - GangstaSunny. - 14.04.2017

Do you save the stuff as bitmask?


Re: Vehicle stats wont load - penaut - 15.04.2017

It saves correctly, this is the important part of the ID 1 car.ini:
Код:
HP=826.000000
Panels=18874401
Doors=33554944
Lights=5
Tires=0
The only problem is applying the health and damage status to the vehicles.

I made this line to know if the datas load correctly for ID 1 vehicle (and they do):
Код:
printf("[Panels] : %d - [Doors] : %d - [Lights] : %d - [Tires] : %d",carPanels[1], carDoors[1], carLights[1], carTires[1]); //id 1 car datas
So it loads correctly, saves correctly, the only problem is that it does not lower the vehicles HP or change the damage status of the vehicle.