How can i change a part in a specific line in a file.
#1

Hello i was busy trying to make my own house system and thought it be fun
to make a 'sale' sign in the front yard of the house with a price on it using 3Dtext;

pawn Код:
AddSaleSign(signmodel,saleid, Float:entX, Float:entY, Float:entZ, Float:entA,Price )
{
    new File:pr_file,prstr[130];

   
    signs[saleid][sex] = entX;
    signs[saleid][sey] = entY;
    signs[saleid][sez] = entZ;
    signs[saleid][sea] = entA;
    signs[saleid][cost] = Price;

    pr_file = fopen( propFile[5], io_append );
   
    if(pr_file)SignObject[saleid] = saleid;
    {
    format( prstr, 130, "%d,%d,%f, %f, %f, %f, %d ;// %s\r\n",signmodel,saleid,entX,entY,entZ,entA,Price);
    fwrite( pr_file, prstr );
    fclose( pr_file );
    printf( "PropDB - %s", prstr );

    signs[saleid][sid]= CreateDynamicObject(19470,entX,entY,entZ,0.000000,0.000000,entA,0,-1,-1,50);
        Create3DTextLabel(Price,0xEEEE88FF,entX,entY,entZ+0.75,20.0,0,1);

    }
    return -1;
}

This part basicly returns the following into a file

Код:
19470,0,2268.674560, 35.834636, 26.484375, 178.891632, 50000 ;// 
19470,2,2245.197753, 34.113197, 26.484375, 180.142669, 50000 ;//
The second number is the ID that should be linked later on with the house that it is for
and the last number (50000) is the price

Now the question;

What if i want to change the price ingame ? How would i do that ? does the entire line in the file needs to be deleted ?
Or can i just change the last value somehow ?

If you do know how to then please give me an example.
iknow its kind of an old system but i realy hope it can be done in just one line using just these filefunctions


Thanks in advance
Reply
#2

No you dont have to change it all.

You just need to do a command.

/changeprice [houseid] [price]

Cant help you with the command coz im on mobile
Reply
#3

Ugh..soo...anyone who can actualy help out with a proper example ?
Reply
#4

somethin like this?

Код:
COMMAND:setprice(playerid, params[]) {
	new signID, price;
    if(sscanf(params, "ui", signID, price)) 
		return SendClientMessage(playerid, -1, "USAGE: /setprice [houseid] [price]");
    
	// Maybe do a check to see if sign exists
	if ( !SignExists(signID) ) 
		return SendClientMessage(playerid, -1, "ERROR: Sign doesn't exist.");
	
	signs[signID][cost] = price;

	
	return 1;
}
Reply
#5

No this is not what i am trying to ask. I dont need a command i need to know how i can reset
the last value in a specific line in a FILE that is created in the scriptfiles folder. I am asking because i am not sure if its possible with these filefunctions.
Reply
#6

Quote:
Originally Posted by AIped
Посмотреть сообщение
No this is not what i am trying to ask. I dont need a command i need to know how i can reset
the last value in a specific line in a FILE that is created in the scriptfiles folder. I am asking because i am not sure if its possible with these filefunctions.
made it in a couple minutes and got 2 functions from
https://sampwiki.blast.hk/wiki/
credits to Sacky for create and delete
i dont code in pawno so I cant assure you it will work, you're gonna have to change some stuff
Код:
public fcreate(filename[])
{
    if (fexist(filename)){return false;}
    new File:fhandle = fopen(filename,io_write);
    fclose(fhandle);
    return true;
}

fdeleteline(filename[], line[]){
	if(fexist(filename)){
		new temp[256];
		new File:fhandle = fopen(filename,io_read);
		fread(fhandle,temp,sizeof(temp),false);
		if(strfind(temp,line,true)==-1){return 0;}
		else{
			fclose(fhandle);
			fremove(filename);
			for(new i=0;i<strlen(temp);i++){
				new templine[256];
				strmid(templine,temp,i,i+strlen(line));
				if(equal(templine,line,true)){
					strdel(temp,i,i+strlen(line));
					fcreate(filename);
					fhandle = fopen(filename,io_write);
					fwrite(fhandle,temp);
					fclose(fhandle);
					return 1;
				}
			}
		}
	}
	return 0;
}


COMMAND:setprice(playerid, params[]) {
	new signID, price;
    if(sscanf(params, "ui", signID, price)) 
		return SendClientMessage(playerid, -1, "USAGE: /setprice [houseid] [price]");
    
	new File:pFile = fopen( propFile[5], io_append );
	if(!pFile) 
    {
        fcreate(propFile[5]);
    } 
 
	new string[128], strFile[128];
	// Your gonna have to change some shit here -
	format(string, sizeof(string), "%d,%d,%f, %f, %f, %f, %d", get all the stuff with signs[signID] <--- );
	
	while(fread(pFile, strFile)) { // Read the entire file
	   if ( !strcmp(string, strFile)) 
	   {
	      // Delete the line
		  fdeleteline(propFile[5], string);
		  format(string, sizeof(string), "%d,%d,%f, %f, %f, %f, %d", ...last Param will be -> Price );
		  fwrite(pFile, string);
	   }
	}
	fclose(pFile);
	return 1;
}
Reply
#7

Quote:
Originally Posted by Trucido
Посмотреть сообщение
made it in a couple minutes and got 2 functions from
https://sampwiki.blast.hk/wiki/
credits to Sacky for create and delete
i dont code in pawno so I cant assure you it will work, you're gonna have to change some stuff
Код:
public fcreate(filename[])
{
    if (fexist(filename)){return false;}
    new File:fhandle = fopen(filename,io_write);
    fclose(fhandle);
    return true;
}

fdeleteline(filename[], line[]){
	if(fexist(filename)){
		new temp[256];
		new File:fhandle = fopen(filename,io_read);
		fread(fhandle,temp,sizeof(temp),false);
		if(strfind(temp,line,true)==-1){return 0;}
		else{
			fclose(fhandle);
			fremove(filename);
			for(new i=0;i<strlen(temp);i++){
				new templine[256];
				strmid(templine,temp,i,i+strlen(line));
				if(equal(templine,line,true)){
					strdel(temp,i,i+strlen(line));
					fcreate(filename);
					fhandle = fopen(filename,io_write);
					fwrite(fhandle,temp);
					fclose(fhandle);
					return 1;
				}
			}
		}
	}
	return 0;
}


COMMAND:setprice(playerid, params[]) {
	new signID, price;
    if(sscanf(params, "ui", signID, price)) 
		return SendClientMessage(playerid, -1, "USAGE: /setprice [houseid] [price]");
    
	new File:pFile = fopen( propFile[5], io_append );
	if(!pFile) 
    {
        fcreate(propFile[5]);
    } 
 
	new string[128], strFile[128];
	// Your gonna have to change some shit here -
	format(string, sizeof(string), "%d,%d,%f, %f, %f, %f, %d", get all the stuff with signs[signID] <--- );
	
	while(fread(pFile, strFile)) { // Read the entire file
	   if ( !strcmp(string, strFile)) 
	   {
	      // Delete the line
		  fdeleteline(propFile[5], string);
		  format(string, sizeof(string), "%d,%d,%f, %f, %f, %f, %d", ...last Param will be -> Price );
		  fwrite(pFile, string);
	   }
	}
	fclose(pFile);
	return 1;
}
You got this from the wiki ?wtf XD

Alright so basicly what this does is just deleting one line and recreate the exact same except for the price ?
thats great but how does it know wich line must change ? i could have a dozen lines in that file.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)