SA-MP Forums Archive
Organize scriptfiles - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Organize scriptfiles (/showthread.php?tid=126429)



Organize scriptfiles - falor - 08.02.2010

Hey guys.
I'm actually making my gamemod, but i have a problem.
I put the player's info in a scriptfile, but all informations are separated by a coma ( e.g : Peter_Smith,0,0,150536864,9000,0,0,0,0,1,2895 )
How can i change my script to make a better scriptfile like :
Quote:

Surname_Name = Peter_Smith
PhoneNr = 2895
etc...

It would be easier to change values, because i plan to add too much things more.
Thanks


Re: Organize scriptfiles - Peep - 08.02.2010

Quote:
Originally Posted by falor
Hey guys.
I'm actually making my gamemod, but i have a problem.
I put the player's info in a scriptfile, but all informations are separated by a coma ( e.g : Peter_Smith,0,0,150536864,9000,0,0,0,0,1,2895 )
How can i change my script to make a better scriptfile like :
Quote:

Surname_Name = Peter_Smith
PhoneNr = 2895
etc...

It would be easier to change values, because i plan to add too much things more.
Thanks
Give the code how it save it .


Re: Organize scriptfiles - falor - 08.02.2010

The line is like that
Quote:

format(filestring,sizeof(filestring),"%s,%d,%d,%d, %d,%d,%d,%d,%d,%d,%d",playername,PlayerInfo[playerid][vowned],PlayerInfo[playerid][vowner],PlayerInfo[playerid][pass],PlayerInfo[playerid][pcash],PlayerInfo[playerid][bank],PlayerInfo[playerid][admin],PlayerInfo[playerid][bowner],PlayerInfo[playerid][bowned],PlayerInfo[playerid][phone],PlayerInfo[playerid][phonenr]);

Quote:

stock SavePlayer(playerid)
{
new fname[256],playername[256],filestring[256];
new File: file;
GetPlayerName(playerid, playername, sizeof(playername));
format(fname,sizeof(fname),P_FILE,udb_encode(playe rname));
if(!fexist(fname)) {}
else {
file = fopen(fname, io_write);
if(file) {
PlayerInfo[playerid][pcash] = GetPlayerMoney(playerid);
format(filestring,sizeof(filestring),"%s,%d,%d,%d, %d,%d,%d,%d,%d,%d,%d",playername,PlayerInfo[playerid][vowned],PlayerInfo[playerid][vowner],PlayerInfo[playerid][pass],PlayerInfo[playerid][pcash],PlayerInfo[playerid][bank],PlayerInfo[playerid][admin],PlayerInfo[playerid][bowner],PlayerInfo[playerid][bowned],PlayerInfo[playerid][phone],PlayerInfo[playerid][phonenr]);
fwrite(file,filestring);
fclose(file);
}
}
}




Re: Organize scriptfiles - woot - 08.02.2010

Use user file management systems, such as Dini or dudb.


Re: Organize scriptfiles - falor - 08.02.2010

I don't know how to do that trick!


Re: Organize scriptfiles - Joe Staff - 08.02.2010

DINI and DUDB are inefficient, they are good, however, for lazy scripters.
If you want to change how it is saved then you're also going to have to change how it is loaded

Anyway, to change how it's saved just change
pawn Код:
"%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
into
pawn Код:
"PlayerName=%s\nVehicleOwned=%d\nVehicleOwner=%d\nPassword=%d\nCash=%d\nBank=%d\nAdmin Level=%d\nBusinesOwner=%d\nBusinessOwned=%d\nPhone=%d\nPhone Number=%d"
But remember, if you change how it's saved then loading won't work, you'll have to change that too.


Re: Organize scriptfiles - falor - 08.02.2010

I'll do it! Thank you


Re: Organize scriptfiles - falor - 08.02.2010

When i change

Код:
PAWN Code:
"%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
into

Код:
"PlayerName=%s\nVehicleOwned=%d\nVehicleOwner=%d\nPassword=%d\nCash=%d\nBank=%d\nAdmin Level=%d\nBusinesOwner=%d\nBusinessOwned=%d\nPhone=%d\nPhone Number=%d"
Errors :
Код:
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2718) : error 075: input line too long (after substitutions)
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2719) : error 017: undefined symbol "pla"
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2720) : error 017: undefined symbol "yerid"
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2720) : error 029: invalid expression, assumed zero
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2720) : error 029: invalid expression, assumed zero
F:\SANAND~1\Server\GAMEMO~1\BUILDI~2.PWN(2720) : fatal error 107: too many error messages on one line
Here is my script
Код:
stock SavePlayer(playerid)
{
  new fname[256],playername[256],filestring[256];
	new File: file;
	GetPlayerName(playerid, playername, sizeof(playername));
 	format(fname,sizeof(fname),P_FILE,udb_encode(playername));
 	if(!fexist(fname)) {}
 	else {
	  file = fopen(fname, io_write);
	  if(file) {
	    PlayerInfo[playerid][pcash] = GetPlayerMoney(playerid);
 			format(filestring,sizeof(filestring),"PlayerName=%s\nVehicleOwned=%d\nVehicleOwner=%d\nPassword=%d\nCash=%d\nBank=%d\nAdmin Level=%d\nBusinesOwner=%d\nBusinessOwned=%d\nPhone=%d\nPhone Number=%d",playername,PlayerInfo[playerid][vowned],PlayerInfo[playerid][vowner],PlayerInfo[playerid][pass],PlayerInfo[playerid][pcash],PlayerInfo[playerid][bank],PlayerInfo[playerid][admin],PlayerInfo[playerid][bowner],PlayerInfo[playerid][bowned],PlayerInfo[playerid][phone],PlayerInfo[playerid][phonenr],PlayerInfo[playerid][niveau]);
  			fwrite(file,filestring);
	  		fclose(file);
		}
	}
Thanks for your help guys



Re: Organize scriptfiles - MadeMan - 08.02.2010

You can do it like this

pawn Код:
format(filestring,sizeof(filestring),"PlayerName=%s\n", playername); fwrite(file,filestring);
format(filestring,sizeof(filestring),"VehicleOwned=%d\n", PlayerInfo[playerid][vowned]); fwrite(file,filestring);
format(filestring,sizeof(filestring),"VehicleOwner=%d\n", PlayerInfo[playerid][vowner]); fwrite(file,filestring);
and so on


Re: Organize scriptfiles - falor - 08.02.2010

Thank you very muck
It works

Now with this :
Код:
stock CreatePlayer(playerid)
{
	new fname[256],playername[256],filestring[256];
 	new SplitDiv[99][V_LIMIT];
	new File: file;
	GetPlayerName(playerid, playername, sizeof(playername));
 	format(fname,sizeof(fname),P_FILE,udb_encode(playername));
	  file = fopen(fname, io_write);
	  if(file) {
 			format(filestring,sizeof(filestring),"%s,0,0,%d,1",playername,PlayerInfo[playerid][pass],PlayerInfo[playerid][pcash],PlayerInfo[playerid][phone],PlayerInfo[playerid][niveau]);
  			fwrite(file,filestring);
	  		fclose(file);
		}
  		file = fopen(fname, io_read);
		if (file) {
			fread(file, filestring);
			split(filestring, SplitDiv, ',');
			strmid(PlayerInfo[playerid][name], SplitDiv[0], 0, strlen(SplitDiv[0]), 255);
			PlayerInfo[playerid][vowned] = strval(SplitDiv[1]);
			PlayerInfo[playerid][vowner] = strval(SplitDiv[2]);
			PlayerInfo[playerid][pass] = strval(SplitDiv[3]);
			PlayerInfo[playerid][pcash] = strval(SplitDiv[4]);
			PlayerInfo[playerid][bank] = strval(SplitDiv[5]);
			PlayerInfo[playerid][admin] = strval(SplitDiv[6]);
			PlayerInfo[playerid][bowner] = strval(SplitDiv[7]);
			PlayerInfo[playerid][bowned] = strval(SplitDiv[8]);
			PlayerInfo[playerid][phone] = strval(SplitDiv[9]);
			PlayerInfo[playerid][phonenr] = strval(SplitDiv[10]);
			PlayerInfo[playerid][niveau] = strval(SplitDiv[11]);
			fclose(file);
		}
}
It's harder because of the split with ','
I should apply the precedent method? Or not?