Someone please explain me this?
#2

PHP код:
LoadDealerships() 
{
    new 
File:handlecount// creating variable file and count for later use
    
new filename[64], line[256], skey[64]; // creating strings filename, line, variable s, and key for later use
    
for(new i=1MAX_DEALERSHIPSi++) // looping through MAX_DEALERSHIPS. MAX_DEALERSHIPS would be defined at the top of the script. And will be in numbers.
    
{
        
format(filenamesizeof(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(filenameio_read); // Opens the file if exists and reads the info from it.
        
while(fread(handleline)) // Loops through the file.
        
{
            
StripNL(line);
            
strfind(line"="); // Checking if there's '=' sign in the line.
            
if(!line[0] || 1) continue; // If there isnt any line go to end of the loop.
            
strmid(keyline0s++); //Extracting the first character of the line.
            
if(strcmp(key"Created") == 0DealershipCreated[i] = strval(line[s]); // If string key has value "Created" then it starts this function.
            
else if(strcmp(key"Pos") == 0sscanf(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(filenamesizeof(filename), DEALERSHIP_FILE_PATH "d%d.ini"dealerid); // formatting the filename string with the path and the id.
    
new File:handle fopen(filenameio_write); // Opening the file using the string filename which was formatted.
    
format(linesizeof(line), "Created=%d\r\n"DealershipCreated[dealerid]); fwrite(handleline); // 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(linesizeof(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(handleline); // Writing the file.
    
fclose(handle); // Closing the file.

Reply


Messages In This Thread
Someone please explain me this? - by akib - 12.05.2017, 12:54
Re: Someone please explain me this? - by StrikerZ - 12.05.2017, 13:25
Re: Someone please explain me this? - by Hansrutger - 12.05.2017, 13:58
Re: Someone please explain me this? - by akib - 12.05.2017, 17:57

Forum Jump:


Users browsing this thread: 1 Guest(s)