16.12.2009, 16:50
Okay,so i want to make a /v buy command,if a player is at the dealership
he will be able to /v buy a car,i know how to do this but the problem is that
i want to know how to save the new car in cars.cfg,because it is a loop and
i don't know how to count the last car,i mean when i add like 20 cars after i define max_cars "30"
It adds automaticly more 10 cars,i hope you guys get me.
[I want it just to CreateVehicle and add the line to the .cfg file]
#define MOD_VEHICLES 127 // It won't count these cars as buyable cars.
he will be able to /v buy a car,i know how to do this but the problem is that
i want to know how to save the new car in cars.cfg,because it is a loop and
i don't know how to count the last car,i mean when i add like 20 cars after i define max_cars "30"
It adds automaticly more 10 cars,i hope you guys get me.
[I want it just to CreateVehicle and add the line to the .cfg file]
#define MOD_VEHICLES 127 // It won't count these cars as buyable cars.
pawn Код:
public LoadCar()
{
new arrCoords[13][64];
new strFromFile2[256];
new File: file = fopen("cars.cfg", io_read);
if (file)
{
new idx = MOD_VEHICLES;
while (idx < sizeof(CarInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
CarInfo[idx][cModel] = strval(arrCoords[0]);
CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
CarInfo[idx][cColorOne] = strval(arrCoords[5]);
CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
CarInfo[idx][cValue] = strval(arrCoords[9]);
CarInfo[idx][cLicense] = strval(arrCoords[10]);
CarInfo[idx][cOwned] = strval(arrCoords[11]);
CarInfo[idx][cLock] = strval(arrCoords[12]);
printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][cOwner],CarInfo[idx][cLicense]);
idx++;
}
}
return 1;
}
pawn Код:
public SaveCarCoords()
{
new idx;
new File: file2;
while (idx < sizeof(CarInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d\n",
CarInfo[idx][cModel],
CarInfo[idx][cLocationx],
CarInfo[idx][cLocationy],
CarInfo[idx][cLocationz],
CarInfo[idx][cAngle],
CarInfo[idx][cColorOne],
CarInfo[idx][cColorTwo]);
if(idx == 0)
{
file2 = fopen("cars.cfg", io_write);
}
else
{
file2 = fopen("cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}