Data won't save.
#1

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
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)