05.03.2011, 13:42
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:
I hope you can help me. Thank you
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);
}
}