[PROBLEM] Saving data - 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)
+--- Thread: [PROBLEM] Saving data (
/showthread.php?tid=519354)
[PROBLEM] Saving data -
Shura - 13.06.2014
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
Re: [PROBLEM] Saving data -
Laure - 14.06.2014
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.
Respuesta: [PROBLEM] Saving data -
Shura - 14.06.2014
Hi Imperior, is created in scriptfiles like the script. :/
Re: [PROBLEM] Saving data -
Laure - 14.06.2014
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.
Respuesta: [PROBLEM] Saving data -
Shura - 14.06.2014
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