[PROBLEM] Saving data
#1

Hello, I have a problem with the saved data of garages.

No error in the code, but to close the server and open the (garage.cfg) is again at 0 and garages are removed.

Please, help :/


CODE LOAD:

Code:
stock LoadGarages()
{
        new binfo[21][32];
        new string[256];
        new File:file = fopen("garages.cfg", io_read);
        if(file)
        {
            new idx = 1;
                while(idx < MAX_GARAGES)
                {
                    fread(file, string);
                    split(string, binfo, '|');
                    format(GarageInfo[idx][gOwner], 32, "%s", binfo[3]);
                    GarageInfo[idx][gX] = floatstr(binfo[4]);
                    GarageInfo[idx][gY] = floatstr(binfo[5]);
                    GarageInfo[idx][gZ] = floatstr(binfo[6]);
                        if(GarageInfo[idx][gLevel])
                        {
                            GarageInfo[idx][gPickup] = CreateDynamicPickup(1318, 1, GarageInfo[idx][gX], GarageInfo[idx][gY], GarageInfo[idx][gZ], 0);
            				if(!strcmp("Gobierno", GarageInfo[idx][gOwner])) format(string, sizeof(string), ""COL_WHITE"["COL_WHITE"%d, Garage (Lvl: %d)\n"COL_WHITE"\n"COL_WHITE"Dueсo"COL_WHITE" %s\n"COL_WHITE"$%d", idx, GarageInfo[idx][gLevel], GarageInfo[idx][gOwner], GarageInfo[idx][gPrice]);
                			else format(string, sizeof(string), ""COL_WHITE"["COL_WHITE"%d, Garage (Nivel: %d)"COL_WHITE"]\n"COL_WHITE"Dueсo"COL_WHITE" %s", idx, GarageInfo[idx][gLevel], GarageInfo[idx][gOwner]);
                   			GarageInfo[idx][gText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, GarageInfo[idx][gX], GarageInfo[idx][gY], GarageInfo[idx][gZ]+0.3, 15);

                        }
                        idx++;
            }
        }
        print("Garages Cargados Correctamente.");
        return 1;
}
CODE SAVE:
Code:
stock SaveGarages()
{
        new idx = 1, File:file;
        new string[256];
        while(idx < MAX_GARAGES)
        {
            format(string, sizeof(string), "%d|%d|%s|%f|%f|%f\r\n",
            GarageInfo[idx][gLevel],
            GarageInfo[idx][gPrice],
            GarageInfo[idx][gOwner],
            GarageInfo[idx][gX],
            GarageInfo[idx][gY],
            GarageInfo[idx][gZ]
                );
            if(idx == 1)
            {
                file = fopen("garages.cfg", io_write);
            }
            else
            {
                file = fopen("garages.cfg", io_append);
            }
                fwrite(file, string);
                fclose(file);
                idx++;
        }
        print("Garages Guardados Correctamente.");
}

In OnGameModeInit I placed the following conditions:

Code:
SaveGarages();//Garages
LoadGarages();//Garages
Reply
#2

Dude i think you're missing something your garage.cfg is not matching the cfg file which garages save to it should be garages.cfg in your scriptfiles.
Reply
#3

Hi Imperior, is created in scriptfiles like the script. :/
Reply
#4

You surely should have the checkfiles stock, delete your current garages.cfg and include
pawn Code:
if(!dini_Exists("garages.cfg")) dini_Create("garages.cfg");
in your CheckFiles stock.
Reply
#5

I already have the checkfiles, what should I include in OnGameModeInit too?

Code:
stock CheckFiles()
{
if(!dini_Exists("garages.cfg")) dini_Create("garages.cfg");
        return 1;
}
Oh and sorry, I should delete? I please help me, I'll give reputation
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)