Needing help with save/load system
#1

Hello,
Last few weeks i did edit Carlito's Roleplay, i am new to pawn btw. I did editted allot, yesterday i started with the car ownership system.
The car ownership system i made now is really basic(/vsell /vbuy /vpark etc) and i got some troubles with the saving of the cars. I use this load/save scripts
Код:
public LoadDynamicCars()
{
	new arrCoords[11][128];
	new strFromFile2[512];
	new File: file = fopen("CRP_Scriptfiles/Cars/carspawns.cfg", io_read);
	if (file)
	{
		new idx;
		while (idx <= sizeof(DynamicCars))
		{
			fread(file, strFromFile2);
			split(strFromFile2, arrCoords, '|');
			DynamicCars[idx][CarModel] = strval(arrCoords[0]);
			DynamicCars[idx][CarX] = floatstr(arrCoords[1]);
			DynamicCars[idx][CarY] = floatstr(arrCoords[2]);
			DynamicCars[idx][CarZ] = floatstr(arrCoords[3]);
			DynamicCars[idx][CarAngle] = floatstr(arrCoords[4]);
			DynamicCars[idx][CarColor1] = strval(arrCoords[5]);
			DynamicCars[idx][CarColor2] = strval(arrCoords[6]);
			DynamicCars[idx][FactionCar] = strval(arrCoords[7]);
			DynamicCars[idx][CarType] = strval(arrCoords[8]);
            DynamicCars[idx][Price] = strval(arrCoords[9]);
      strmid(DynamicCars[idx][Owner], arrCoords[10], 0, strlen(arrCoords[10]), 128);
			new vehicleid = CreateVehicle(DynamicCars[idx][CarModel],DynamicCars[idx][CarX],DynamicCars[idx][CarY],DynamicCars[idx][CarZ],DynamicCars[idx][CarAngle],DynamicCars[idx][CarColor1],DynamicCars[idx][CarColor2], -1);

			if(DynamicCars[idx][FactionCar] != 255)
			{
				SetVehicleNumberPlate(vehicleid, DynamicFactions[DynamicCars[idx][FactionCar]][fName]);
				SetVehicleToRespawn(vehicleid);
			}
			idx++;
		}
		fclose(file);
	}
	return 1;
}
public SaveDynamicCars()
{

	new idx;
	new File: file2;
	file2 = fopen("CRP_Scriptfiles/Cars/carspawns.cfg", io_write);
	while (idx < sizeof(DynamicCars))
	{

		new coordsstring[512];
		format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%s\n",
		DynamicCars[idx][CarModel],
		DynamicCars[idx][CarX],
		DynamicCars[idx][CarY],
		DynamicCars[idx][CarZ],
		DynamicCars[idx][CarAngle],
		DynamicCars[idx][CarColor1],
		DynamicCars[idx][CarColor2],
		DynamicCars[idx][FactionCar],
		DynamicCars[idx][CarType],
		DynamicCars[idx][Price],
		DynamicCars[idx][Owner]);
		fwrite(file2, coordsstring);
		idx++;
		
	}
	fclose(file2);
	return 1;
}
It did looked well at the first time, but after some gmxes its all fucked up. After 3 GMX's most of the cars are gone :\ and it doesn't save the owner.
Oh, btw i did declared DynamicCars as
Код:
enum Cars
{
	CarModel,
	Float:CarX,
	Float:CarY,
	Float:CarZ,
	Float:CarAngle,
	CarColor1,
	CarColor2,
	FactionCar,
	CarType,
	Price,
	Owner[128],

};
new DynamicCars[140][Cars];
Thanks
Reply
#2

Nobody? Please, i could use some help i am busy with it for more then 2 hours allready, I only make it worse.
Reply
#3

bump
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)