PHP код:
LoadDealerships()
{
new File:handle, count; // creating variable file and count for later use
new filename[64], line[256], s, key[64]; // creating strings filename, line, variable s, and key for later use
for(new i=1; i < MAX_DEALERSHIPS; i++) // looping through MAX_DEALERSHIPS. MAX_DEALERSHIPS would be defined at the top of the script. And will be in numbers.
{
format(filename, sizeof(filename), DEALERSHIP_FILE_PATH "d%d.ini", i); // Formating the filename with the current value of i of the loop. DEALERSHIP_FILE_PATH is the path defined on top of your script.
if(!fexist(filename)) continue; // If file doesnt exists go to end of the loop.
handle = fopen(filename, io_read); // Opens the file if exists and reads the info from it.
while(fread(handle, line)) // Loops through the file.
{
StripNL(line);
s = strfind(line, "="); // Checking if there's '=' sign in the line.
if(!line[0] || s < 1) continue; // If there isnt any line go to end of the loop.
strmid(key, line, 0, s++); //Extracting the first character of the line.
if(strcmp(key, "Created") == 0) DealershipCreated[i] = strval(line[s]); // If string key has value "Created" then it starts this function.
else if(strcmp(key, "Pos") == 0) sscanf(line[s], "p,fff", DealershipPos[i][0], // Else if it has value "Pos" then it does that sscanf function.
DealershipPos[i][1], DealershipPos[i][2]);
}
fclose(handle); // Closing the file.
if(DealershipCreated[i]) count++; // If the dealership is successfully created, then increase the value of count.
}
printf(" Loaded %d dealerships", count); // prints the number of loaded dealerships using the count variable.
}
SaveDealership(dealerid)
{
new filename[64], line[256]; // creating strings for later use.
format(filename, sizeof(filename), DEALERSHIP_FILE_PATH "d%d.ini", dealerid); // formatting the filename string with the path and the id.
new File:handle = fopen(filename, io_write); // Opening the file using the string filename which was formatted.
format(line, sizeof(line), "Created=%d\r\n", DealershipCreated[dealerid]); fwrite(handle, line); // Formatting the line string with the value that if the dealership is created or not. /r = start from beginning of the line. \n = new line.
format(line, sizeof(line), "Pos=%.3f,%.3f,%.3f\r\n", DealershipPos[dealerid][0], // Formatting the line with Position of the dealership.
DealershipPos[dealerid][1], DealershipPos[dealerid][2]);
fwrite(handle, line); // Writing the file.
fclose(handle); // Closing the file.
}