Stock creates the file but can't read it
#4

Thanks for your reply, I've used the function you just told me on both loading and saving the server crashed for me when I tried to save and when it didn't even load dealerships at all, these are the updated lines.

Код:
stock LoadDealershipCars()
{	        

	new dcar[7][32];
	new string[256], vehicle;
	new File:file = fopen("dealershipcars.cfg", io_read);
	if(file)
	{
	    new i = 1;
    	while(fread(file, string) && i < MAX_DVEHICLES)
		{
		    split(string, dcar, '|');
			VehicleStatistics[i][vehicle_model] = strval(dcar[0]);
			VehicleStatistics[i][vehicle_price] = strval(dcar[1]);
   			VehicleStatistics[i][vehicle_position][1] = floatstr(dcar[2]);
		    VehicleStatistics[i][vehicle_position][2] = floatstr(dcar[3]);
		    VehicleStatistics[i][vehicle_position][3] = floatstr(dcar[4]);
			VehicleStatistics[i][vehicle_position][4] = floatstr(dcar[5]);
      		VehicleStatistics[i][vehicle_onsale] = strval(dcar[6]);
			vehicle = CreateVehicle(VehicleStatistics[i][vehicle_model], VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], VehicleStatistics[i][vehicle_position][4], 0, 0, -1);
			format(string, sizeof(string), "{91D593}This Vehicle is for sale\nModel:%s\nPrice:$%d\n{FFBE63}Enter the vehicle to buy it", GetVehicleName(vehicle), VehicleStatistics[i][vehicle_price]);
			VehicleStatistics[i][vehicle_label] = Create3DTextLabel(string, COLOR_BDO, VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], 10.0, 0);
			i++;
	    }
     	fclose(file);
	}
	print("Dealership Cars loaded successfully.");
	return 1;
}
Код:
stock SaveDealershipCars()
{
	new i = 0, File:file;
	new string[256];
   	while(fread(file, string) && i < MAX_DVEHICLES)
	{
	    format(string, sizeof(string), "%d|%d|%f|%f|%f|%f|%d\r\n",
        VehicleStatistics[i][vehicle_model],
		VehicleStatistics[i][vehicle_price],
		VehicleStatistics[i][vehicle_position][1],
		VehicleStatistics[i][vehicle_position][2],
		VehicleStatistics[i][vehicle_position][3],
		VehicleStatistics[i][vehicle_position][4],
	    VehicleStatistics[i][vehicle_onsale]);
	    if(i == 0)
	    {
	        file = fopen("dealershipcars.cfg", io_write);
	    }
	    else
	    {
	    	file = fopen("dealershipcars.cfg", io_append);
	    }
		fwrite(file, string);
		i++;
	}
	fclose(file);
	print("Dealership Cars saved successfully.");
}
If you could please elaborate the functions you used in my code because when I tried them it just seemed like I had the same result
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)