Organize scriptfiles
#1

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
Reply
#2

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 .
Reply
#3

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);
}
}
}

Reply
#4

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

I don't know how to do that trick!
Reply
#6

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.
Reply
#7

I'll do it! Thank you
Reply
#8

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
Reply
#9

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
Reply
#10

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?
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)