#define MAX_VEH 100 #define VEHICLE_FILE_ "vehicles.txt" |
SaveVehicles()
{
new filestring[125];
new File: vfile = fopen("vehicles.txt", io_write);
for(new vehicleid = 1;vehicleid<MAX_VEH;vehicleid++)
{
if(cInfo[vehicleid][Car1Model] != 0)
{
format(filestring, sizeof(filestring), "%i,%f\n",cInfo[vehicleid][Car1Model],cInfo[vehicleid][CarX1]);
fwrite(vfile, filestring);
}
}
fclose(vfile);
return 1;
}
LoadVehicles()
{
if(fexist("vehicles.txt"))
{
new SplitDiv[40][32];
new filestring[275];
new File: file = fopen(VEHICLE_FILE_, io_read);
if (file)
{
for(new vehicleid = 1;vehicleid<MAX_VEH;vehicleid++)
{
fread(file, filestring);
cInfo[vehicleid][Car1Model] = strval(SplitDiv[0]);
cInfo[vehicleid][CarX1] = floatstr(SplitDiv[1]);
}
}
fclose(file);
}
return 1;
}
new cInfo[MAX_VEH][PlayercInfo]; public OnPlayerConnect(playerid) { LoadVehicles(); return 1; } public OnPlayerDisconnect(playerid, reason) { SaveVehicles(); return 1; } |