SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/05/2017, 12:54 PM   #1
akib
Big Clucker
 
akib's Avatar
 
Join Date: Jun 2016
Location: Bangladesh
Posts: 158
Reputation: 1
Default Someone please explain me this?

Hi,
how this two codes work?
Code:
LoadDealerships()
{
	new File:handle, count;
	new filename[64], line[256], s, key[64];
	for(new i=1; i < MAX_DEALERSHIPS; i++)
	{
		format(filename, sizeof(filename), DEALERSHIP_FILE_PATH "d%d.ini", i);
		if(!fexist(filename)) continue;
		handle = fopen(filename, io_read);
		while(fread(handle, line))
		{
			StripNL(line);
			s = strfind(line, "=");
			if(!line[0] || s < 1) continue;
			strmid(key, line, 0, s++);
			if(strcmp(key, "Created") == 0) DealershipCreated[i] = strval(line[s]);
			else if(strcmp(key, "Pos") == 0) sscanf(line[s], "p,fff", DealershipPos[i][0],
				DealershipPos[i][1], DealershipPos[i][2]);
		}
		fclose(handle);
		if(DealershipCreated[i]) count++;
	}
	printf("  Loaded %d dealerships", count);
}
Code:
SaveDealership(dealerid)
{
	new filename[64], line[256];
	format(filename, sizeof(filename), DEALERSHIP_FILE_PATH "d%d.ini", dealerid);
	new File:handle = fopen(filename, io_write);
	format(line, sizeof(line), "Created=%d\r\n", DealershipCreated[dealerid]); fwrite(handle, line);
	format(line, sizeof(line), "Pos=%.3f,%.3f,%.3f\r\n", DealershipPos[dealerid][0],
		DealershipPos[dealerid][1], DealershipPos[dealerid][2]);
	fwrite(handle, line);
	fclose(handle);
}
akib is offline   Reply With Quote
Old 12/05/2017, 01:25 PM   #2
StrikerZ
High-roller
 
StrikerZ's Avatar
 
Join Date: Mar 2016
Location: India
Posts: 1,109
Reputation: 154
Default Re: Someone please explain me this?

PHP Code:
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.

__________________
StrikerZ is offline   Reply With Quote
Old 12/05/2017, 01:58 PM   #3
Hansrutger
Gangsta
 
Hansrutger's Avatar
 
Join Date: May 2011
Location: Sweden
Posts: 928
Reputation: 158
Default Re: Someone please explain me this?

Code is being read from up to down and left to right usually. Not sure if code by arabic standards exists.
__________________


Hansrutger is offline   Reply With Quote
Old 12/05/2017, 05:57 PM   #4
akib
Big Clucker
 
akib's Avatar
 
Join Date: Jun 2016
Location: Bangladesh
Posts: 158
Reputation: 1
Default Re: Someone please explain me this?

Quote:
Originally Posted by Sunehildeep View Post
PHP Code:
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.

Thanks dude!
akib is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can some explain me this please. DaDenz Server Support 0 01/02/2014 06:01 PM
Please explain. Don_Cage Scripting Help 2 30/01/2014 06:23 PM
Can someone explain me this efrim123 Scripting Help 6 15/10/2013 01:37 AM
Could someone explain this to me? Don_Cage Scripting Help 5 25/03/2013 10:10 AM
Can someone explain? lsrgta Help Archive 5 07/05/2011 09:41 PM


All times are GMT. The time now is 07:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.