Data won't save. - 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: Data won't save. (
/showthread.php?tid=235335)
Data won't save. -
Biesmen - 05.03.2011
I'm having a problem with the script below.
It doesn't seem to work properly. If you store some stuff in the safe, it will work. Until you reboot the server. If you reboot the server, the whole 'file' will be reset.
This is the code I am using:
pawn Код:
forward LoadSafe();
public LoadSafe()
{
new arrCoords[10][64];
new strFromFile2[256];
new File: file = fopen("safes.cfg", io_read);
if (file)
{
new idx = 0;
while (idx < sizeof(SafeInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
SafeInfo[idx][sDrugs] = strval(arrCoords[0]);
SafeInfo[idx][sMats] = strval(arrCoords[1]);
SafeInfo[idx][sGun][0] = strval(arrCoords[2]);
SafeInfo[idx][sGun][1] = strval(arrCoords[3]);
SafeInfo[idx][sGun][2] = strval(arrCoords[4]);
SafeInfo[idx][sGun][3] = strval(arrCoords[5]);
SafeInfo[idx][sAmmo][0] = strval(arrCoords[6]);
SafeInfo[idx][sAmmo][1] = strval(arrCoords[7]);
SafeInfo[idx][sAmmo][2] = strval(arrCoords[8]);
SafeInfo[idx][sAmmo][3] = strval(arrCoords[9]);
idx++;
}
}
return 1;
}
forward SaveSafe();
public SaveSafe()
{
new idx;
new File: file2;
idx = 0;
while (idx < sizeof(SafeInfo))
{
new coordsstring[255];
format(coordsstring, sizeof(coordsstring), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
SafeInfo[idx][sDrugs],
SafeInfo[idx][sMats],
SafeInfo[idx][sGun][0],
SafeInfo[idx][sGun][1],
SafeInfo[idx][sGun][2],
SafeInfo[idx][sGun][3],
SafeInfo[idx][sAmmo][0],
SafeInfo[idx][sAmmo][1],
SafeInfo[idx][sAmmo][2],
SafeInfo[idx][sAmmo][3]);
if(idx == 1)
{
file2 = fopen("safes.cfg", io_write);
}
else
{
file2 = fopen("safes.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
}
I hope you can help me. Thank you
Re: Data won't save. - rjjj - 05.03.2011
So, get this file that i made for you, and put in your scriptfiles folder:
http://solidfiles.com/d/7ccb/
After some time, the code in the safes.cfg will be overwritten
Finally, use this code:
pawn Код:
forward SaveSafe();
public SaveSafe()
{
new idx = 0;
while (idx < sizeof(SafeInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%i|%i|%i|%i|%i|%i|%i|%i|%i|%i\n",
SafeInfo[idx][sDrugs],
SafeInfo[idx][sMats],
SafeInfo[idx][sGun][0],
SafeInfo[idx][sGun][1],
SafeInfo[idx][sGun][2],
SafeInfo[idx][sGun][3],
SafeInfo[idx][sAmmo][0],
SafeInfo[idx][sAmmo][1],
SafeInfo[idx][sAmmo][2],
SafeInfo[idx][sAmmo][3]);
new File: file2 = fopen("safes.cfg", io_write);
fwrite(file2, coordsstring);
fclose(file2);
idx++;
}
return 1;
}
forward LoadSafe();
public LoadSafe()
{
new arrCoords[10][64];
new strFromFile2[256];
new File: file = fopen("safes.cfg", io_read);
if (file)
{
new idx = 0;
while (idx < sizeof(SafeInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
SafeInfo[idx][sDrugs] = strval(arrCoords[0]);
SafeInfo[idx][sMats] = strval(arrCoords[1]);
SafeInfo[idx][sGun][0] = strval(arrCoords[2]);
SafeInfo[idx][sGun][1] = strval(arrCoords[3]);
SafeInfo[idx][sGun][2] = strval(arrCoords[4]);
SafeInfo[idx][sGun][3] = strval(arrCoords[5]);
SafeInfo[idx][sAmmo][0] = strval(arrCoords[6]);
SafeInfo[idx][sAmmo][1] = strval(arrCoords[7]);
SafeInfo[idx][sAmmo][2] = strval(arrCoords[8]);
SafeInfo[idx][sAmmo][3] = strval(arrCoords[9]);
idx++;
}
fclose(file);
}
return 1;
}
I hope that i have helped