SA-MP Forums Archive
Save player stats - 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)
+--- Thread: Save player stats (/showthread.php?tid=608392)



Save player stats - CSLangdale - 31.05.2016

Код:
forward Save_PlayerInfo();
public Save_PlayerInfo() //Saves all the garages, changed to a public because of the autosave timer
{
	new playerid;
    if(Logged[playerid] == true)
    {
			    new File, path[64];
			    format(path,sizeof(path),"/Players/%d.ini");
		     	new INI:file = INI_Open(path);
				INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
	  		  	INI_WriteInt(File, "Level", PlayerInfo[playerid][pLevel]);
	    		INI_WriteInt(File, "Skin", GetPlayerSkin(playerid));
				INI_WriteInt(File, "Registered", PlayerInfo[playerid][Registered]);
				INI_WriteInt(File, "HandMoney", GetPlayerMoney(playerid));
				INI_Close(file);
	 }
}
This is what i have but i keep getting errors of tag mismatch anyone see how i can fix this so i can test if it actually works?

It is my attempt at setting an autosave system to save players stats


Re: Save player stats - ilijap - 31.05.2016

Код:
forward Save_PlayerInfo();
public Save_PlayerInfo() //Saves all the garages, changed to a public because of the autosave timer
{
	new playerid;
    if(Logged[playerid] == true)
    {
			    new path[64];
			    format(path,sizeof(path),"/Players/%d.ini");
		     	new INI:File = INI_Open(path);
				INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
	  		  	INI_WriteInt(File, "Level", PlayerInfo[playerid][pLevel]);
	    		INI_WriteInt(File, "Skin", GetPlayerSkin(playerid));
				INI_WriteInt(File, "Registered", PlayerInfo[playerid][Registered]);
				INI_WriteInt(File, "HandMoney", GetPlayerMoney(playerid));
				INI_Close(File);
	 }
}



Re: Save player stats - Konstantinos - 31.05.2016

You don't provide the line of the error though so I will just assume that is:
pawn Код:
if(Logged[playerid] == true)
because "Logged" does not have "bool:" tag on its declaration. Change "true" to "1".

Another issue and probably the most important is that that piece of code will only try to save for the player with ID 0. You declare "playerid" which is by default 0 inside the public function when it should have been a parameter. Calling it with the parameter as well.


Re: Save player stats - CSLangdale - 31.05.2016

oh sorry its only tag mismatch errors on these lines

Код:
INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
	  		  	INI_WriteInt(File, "Level", PlayerInfo[playerid][pLevel]);
	    		INI_WriteInt(File, "Skin", GetPlayerSkin(playerid));
				INI_WriteInt(File, "Registered", PlayerInfo[playerid][Registered]);
				INI_WriteInt(File, "HandMoney", GetPlayerMoney(playerid));



Re: Save player stats - Konstantinos - 31.05.2016

You declare two variables: File and file. Since you opened the file with "file" variable which uses the INI tag, use that as the first parameter because "File" doesn't have any tag and also not assigned to any value.

This line is also wrong:
pawn Код:
format(path,sizeof(path),"/Players/%d.ini");
formatting nothing and %d is for integers when should have been a string for the player's name.


Re: Save player stats - Rubey - 31.05.2016

new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(path,sizeof(path),"/Players/%d.ini", pName);

You have an error. Correct with it.