[HELP] Saving data into a file -
Pooh7 - 09.12.2010
Hi
File functions, savings, readings, etc are my nightmear

I'm total noob for file functions
Ok, I have this func for saving vehicles (ownership):
pawn Code:
public SacuvajVozila()
{
new idx;
new File: file2;
while (idx < sizeof(Vozilo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%d\n",
Vozilo[idx][hModel],
Vozilo[idx][hPozX],
Vozilo[idx][hPozY],
Vozilo[idx][hPozZ],
Vozilo[idx][hPozA],
Vozilo[idx][hBoja1],
Vozilo[idx][hBoja2],
Vozilo[idx][hVlasnik],
Vozilo[idx][hOpis],
Vozilo[idx][hCena],
Vozilo[idx][hImaVlasnika]);
/*if(idx == 0)
{
file2 = fopen("VozilaOwnership.cfg", io_write);
}
else
{
file2 = fopen("VozilaOwnership.cfg", io_append);
}*/
file2 = fopen("VozilaOwnership.cfg", io_write);
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
This function is called in GameModeExitFunc (godfather mode)
My problem is that when i restart my server (gmx), new vehicles data is just add into a file.
For example, this is one line from VozilaOwnership.cfg:
Code:
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Autosalon,Infernus,1000000,0
When someone buy this car, script will create new line:
Code:
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Firstname_Lastname,Infernus,1000000,1
The problem is that what new line just add on end of file.
I want to replace the existing line with that new line.
How to do that?
Sorry for my bad English.
Re: [HELP] Saving data into a file -
kiss - 10.12.2010
WTF is this?
Explane please
Re: [HELP] Saving data into a file -
Pooh7 - 10.12.2010
It's a vehicle ownership.
And update for some car is just add on end of file.
I want to replace existing line with new vehicle data.
This updates on end of file are not loading, because in it's over a limit. Limit is 64 vehicles, and I have 64 lines in my cfg file. So, updates can't be load.
If i increase a limit, vehicles will be double (only updated vehicles).
How to set replacing, not adding?
Respuesta: [HELP] Saving data into a file -
kirk - 10.12.2010
He means that instead of creating any new line, just want it replaced with the new information of the new car the player bought.
Re: [HELP] Saving data into a file -
smeti - 10.12.2010
Try.:
pawn Code:
public
SacuvajVozila()
{
new
idx = 0,
File:file2 = fopen("VozilaOwnership.cfg", io_write); // io_write
if(file2)
{
new
coordsstring[256];
while(idx < sizeof(Vozilo)) // Loop 64 0. - 63.
{
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%d\r\n", // \r\n new line
Vozilo[idx][hModel],
Vozilo[idx][hPozX],
Vozilo[idx][hPozY],
Vozilo[idx][hPozZ],
Vozilo[idx][hPozA],
Vozilo[idx][hBoja1],
Vozilo[idx][hBoja2],
Vozilo[idx][hVlasnik],
Vozilo[idx][hOpis],
Vozilo[idx][hCena],
Vozilo[idx][hImaVlasnika]);
fwrite(file2, coordsstring);
idx++;
}
fclose(file2); // Close the opened file
}
return 1;
}