[HELP] Saving Cars - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Saving Cars (
/showthread.php?tid=196980)
[HELP] Saving Cars -
EthanR - 07.12.2010
I'm trying to script a static cars system which loads / saves cars over a .CFG file. One little problem, explanation below.
SaveCars();
Код:
public SaveCars()
{
new idx;
new File: file2;
while (idx < sizeof(CarInfo))
{
new coordsstring[512];
format(coordsstring, sizeof(coordsstring), "%s|%d|%d|%f|%f|%f\n",
CarInfo[idx][CarOwner],
CarInfo[idx][CarModel],
CarInfo[idx][CarID],
CarInfo[idx][CarPos][0],
CarInfo[idx][CarPos][1],
CarInfo[idx][CarPos][2]);
if(idx == 0)
{
file2 = fopen("cars.cfg", io_write);
}
else
{
file2 = fopen("cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
LoadCars();
Код:
public LoadCars()
{
new arrCoords[6][64];
new strFromFile2[512];
new File: file = fopen("cars.cfg", io_read);
if(file)
{
new idx;
while (idx < sizeof(CarInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
strmid(CarInfo[idx][CarOwner], arrCoords[0], 0, strlen(arrCoords[0]), 255);
CarInfo[idx][CarModel] = strvalEx(arrCoords[1]);
CarInfo[idx][CarID] = strvalEx(arrCoords[2]);
CarInfo[idx][CarPos][0] = floatstr(arrCoords[3]);
CarInfo[idx][CarPos][1] = floatstr(arrCoords[4]);
CarInfo[idx][CarPos][2] = floatstr(arrCoords[5]);
idx++;
}
fclose(file);
}
return 1;
}
It's all fine if a person buys a car, it will write perfectly into the .cfg file just like this example here.
Код:
Testname|560|1|2488.699951|317.899993|30.600484
Testname2|560|2|2597.541748|532.915832|155.538421
None|0|0|0.000000|0.000000|0.000000
The 2 lines are bought cars, the last line is an empty line which is not used yet (obviously).
Now to the problem, after a GameMode Restart, once a player buys a car it automaticly overwrites the FIRST USED line.
I need to know a way to check if the line is used, so it can overwrite the unused (third line) line.
Any ideas?
Re: [HELP] Saving Cars -
Berky - 19.12.2010
Eyo Big Baws Ethan Rodricaz good to see you back again!