Jump to content
  • 0

Save Score


repLay

Question

Am facut un sistem de save pe langa cel de salvare a conturilor:

enum dmmInfo
{
	dmLevel,
	dmKills,
	dmDeaths,
	dmLastPlayed,
	dmTotalPlayed,
	dmParticipari,

};
new DmInfo[MAX_PLAYERS][dmmInfo];
la onplayerdeath
		DmInfo[killerid][dmKills]++;
		OnPlayerDMUpdate(killerid);
		DmInfo[playerid][dmDeaths]++;
		OnPlayerDMUpdate(playerid);
cand foloseste comanda /dm on
							DmInfo[playerid][dmParticipari]++;
							OnPlayerDMUpdate(playerid);
cand foloseste comanda /dm off
						OnPlayerDMUpdate(playerid);
forward OnPlayerDMRegister(playerid);
public OnPlayerDMRegister(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		    new string3[64];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "dm/%s.ini", playername3);
			new File: hFile = fopen(string3, io_write);
			if (hFile)
			{
			    new var[32];
				format(var, 32, "Level=%d\n",DmInfo[playerid][dmLevel]);fwrite(hFile, var);
				format(var, 32, "Kills=%d\n",DmInfo[playerid][dmKills]);fwrite(hFile, var);
				format(var, 32, "Deaths=%d\n",DmInfo[playerid][dmDeaths]);fwrite(hFile, var);
				format(var, 32, "LastPlayed=%d\n",DmInfo[playerid][dmLastPlayed]);fwrite(hFile, var);
				format(var, 32, "TotalPlayed=%d\n",DmInfo[playerid][dmTotalPlayed]);fwrite(hFile, var);
				format(var, 32, "NRParticipari=%d\n",DmInfo[playerid][dmParticipari]);fwrite(hFile, var);
				fclose(hFile);
			}
	}
	return 1;
}

forward OnPlayerDMUpdate(playerid);
public OnPlayerDMUpdate(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		if(gPlayerLogged[playerid])
		{
			new string3[32];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "dm/%s.ini", playername3);
			new File: hFile = fopen(string3, io_write);
			if (hFile)
			{
				new var[32];
				format(var, 32, "Level=%d\n",DmInfo[playerid][dmLevel]);fwrite(hFile, var);
				format(var, 32, "Kills=%d\n",DmInfo[playerid][dmKills]);fwrite(hFile, var);
				format(var, 32, "Deaths=%d\n",DmInfo[playerid][dmDeaths]);fwrite(hFile, var);
				format(var, 32, "LastPlayed=%d\n",DmInfo[playerid][dmLastPlayed]);fwrite(hFile, var);
				format(var, 32, "TotalPlayed=%d\n",DmInfo[playerid][dmTotalPlayed]);fwrite(hFile, var);
				format(var, 32, "NRParticipari=%d\n",DmInfo[playerid][dmParticipari]);fwrite(hFile, var);
				fclose(hFile);
			}
		}
	}
	return 1;
}
forward OnPlayerDMLogin(playerid);
public OnPlayerDMLogin(playerid)
{

    new string2[64];
	new playername2[MAX_PLAYER_NAME];
	new playernamesplit[3][MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
	split(playername2, playernamesplit, '_');
	format(string2, sizeof(string2), "dm/%s.ini", playername2);
	new File: UserFile = fopen(string2, io_read);
	if ( UserFile )
	{
		new key[ 256 ] , val[ 256 ];
		new Data[ 256 ];
		while ( fread( UserFile , Data , sizeof( Data ) ) )
		{
			key = ini_GetKey( Data );
			if( strcmp( key , "Level" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmLevel] = strval( val ); }
			if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmKills] = strval( val ); }
  			if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmDeaths] = strval( val ); }
    		if( strcmp( key , "LastPlayed" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmLastPlayed] = strval( val ); }
      		if( strcmp( key , "TotalPlayed" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmTotalPlayed] = strval( val ); }
      		if( strcmp( key , "NRParticipari" , true ) == 0 ) { val = ini_GetValue( Data ); DmInfo[playerid][dmParticipari] = strval( val ); }
        	fclose(UserFile);//close the file after everything has been read in the while
		}
	}
	return 1;
}
forward OnPlayerDMDisconnect(playerid);
public OnPlayerDMDisconnect(playerid)
{
	OnPlayerDMUpdate(playerid);
    return 1;
}

forward DMTime();
public DMTime()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
		    if(PlayerDM[i] == 1)
		    {
				DmInfo[i][dmTotalPlayed]++;
				OnPlayerDMUpdate(i);
			}
		}
	}
	return 1;
}

am o problema de fiecare data cand cineva da /dm on , kills/deaths raman , dar daca a facut un kill sau un death incepe iar de la 0 , cum pot face cand intra playerul pe server sa ii "ia setarile" din fisierul care are numele lui?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.