[URGENT] Can you see if there is something wrong?
#1

I'll try to explain in detail what the problem is.

This problem is the same on pAdmin, pLeader, pRank and also on pMoney and pBank.
We're talking about pMoney and pBank because it is easiest to understand what I mean.

When I log in and make some money, we say $10 and maybe add $5 in my bank account.
Then I log out and close down the game and takes a look at my %s.ini and I can see that everything is true.

When I try to log in again the money is gone.
If I check the %s.ini there is still correct but I can not get the money in the game.

If you are wondering, I earned money through stunting with a bike, perhaps it is the error?

Here is my Register System:

Код:
forward OnPlayerLogin(playerid,const string[]);
Код:
enum Info
{
  pPassword[128],
	pMoney,
	pBank,
	pAdmin,
	pLeader,
	pRank,
};
new PlayerInfo[MAX_PLAYERS][Info];
new gPlayerLogged[MAX_PLAYERS];
new gPlayerAccount[MAX_PLAYERS];
Код:
public OnPlayerDisconnect(playerid, reason)
{
  if(gPlayerLogged[playerid])
  {
		new string3[32];
		new pname3[MAX_PLAYER_NAME];
		GetPlayerName(playerid, pname3, sizeof(pname3));
		format(string3, sizeof(string3), "%s.ini", pname3);
		new File: pFile = fopen(string3, io_write);
		if (pFile)
		{
			new var[32];
			format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
			fclose(pFile);
			new File: hFile = fopen(string3, io_append);
			PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
			format(var, 32, "Money:%d\n",PlayerInfo[playerid][pMoney]);fwrite(hFile, var);
			format(var, 32, "Bank:%d\n",PlayerInfo[playerid][pBank]);fwrite(hFile, var);
      format(var, 32, "Admin:%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
			format(var, 32, "Leader:%d\n",PlayerInfo[playerid][pLeader]);fwrite(hFile, var);
			format(var, 32, "Rank:%d\n",PlayerInfo[playerid][pRank]);fwrite(hFile, var);
			fclose(hFile);
		}
		gPlayerLogged[playerid] = 0;
	}
	return 1;
}
Код:
if (strcmp(cmd, "/login", true) ==0 )
	{
	  if(IsPlayerConnected(playerid))
	  {
	    new tmppass[64];
			if(gPlayerLogged[playerid] == 1)
			{
				SendClientMessage(playerid, COLOR_GREY, "	You are already logged in.");
				return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /login <password>");
				return 1;
			}
			strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
			String(tmppass);
			OnPlayerLogin(playerid,tmppass);
		}
		return 1;
	}
Код:
if (strcmp(cmd, "/register", true)==0)
	{
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOR_GREY, "	USAGE: /register <password>");
			return 1;
		}
		if (gPlayerAccount[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_GREY, "	That nickname is already registered.");
			return 1;
		}

		strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
		String(PlayerInfo[playerid][pPassword]);
		GetPlayerName(playerid, playername, sizeof(playername));
		format(string, sizeof(string), "%s.ini", playername);
		new File: file = fopen(string, io_read);
		if (file)
		{
			SendClientMessage(playerid, COLOR_GREY, "	That name is already registered.");
			fclose(file);
			return 1;
		}
		new File:hFile;
		hFile = fopen(string, io_append);
		new var[32];//
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
		PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
    format(var, 32, "Money:%d\n",PlayerInfo[playerid][pMoney]);fwrite(hFile, var);
    format(var, 32, "Bank:%d\n",PlayerInfo[playerid][pBank]);fwrite(hFile, var);
    format(var, 32, "Admin:%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
		format(var, 32, "Leader:%d\n",PlayerInfo[playerid][pLeader]);fwrite(hFile, var);
		format(var, 32, "Rank:%d\n",PlayerInfo[playerid][pRank]);fwrite(hFile, var);
		fclose(hFile);
		SendClientMessage(playerid, COLOR_WHITE, "Succesfully Registered.");
		SendClientMessage(playerid, COLOR_WHITE, "Next time when you come , use /login <password>");
		OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
		return 1;
	}
Код:
public OnPlayerLogin(playerid,const string[])
{
  new pname2[MAX_PLAYER_NAME];
	new pname3[MAX_PLAYER_NAME];
	new string2[64];
	new string3[128];
	GetPlayerName(playerid, pname2, sizeof(pname2));
	format(string2, sizeof(string2), "%s.ini", pname2);
	new File: UserFile = fopen(string2, io_read);

	if (UserFile)
	{
		new valtmp[128];
		fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);

		if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
		{
			new key[128],val[128];
 			new Data[128];
 			while(fread(UserFile,Data,sizeof(Data)))
			{
				key = ini_GetKey(Data);
				if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pMoney] = strval( val ); }
				if( strcmp( key , "Bank" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pBank] = strval( val ); }
        if( strcmp( key , "Admin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
				if( strcmp( key , "Leader" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pLeader] = strval( val ); }
				if( strcmp( key , "Rank" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pRank] = strval( val ); }
        GivePlayerMoney(playerid,PlayerInfo[playerid][pMoney]);
			}
			fclose(UserFile);
			gPlayerLogged[playerid] = 1;
			gPlayerAccount[playerid] = 1;
		  GetPlayerName(playerid, pname3, sizeof(pname3));
			format(string3, sizeof(string3), "Succesfully logged in.");
			SendClientMessage(playerid, COLOR_WHITE, string3);
		}
		else
		{
			SendClientMessage(playerid, COLOR_GREY, "Invalid Password.");
			fclose(UserFile);
		}
	}
	return 1;
}
Код:
stock ini_GetKey( line[] )
{
	new keyRes[128];
	keyRes[0] = 0;
  if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  return keyRes;
}
Код:
stock ini_GetValue( line[] )
{
	new valRes[128];
	valRes[0]=0;
	if ( strfind( line , "=" , true ) == -1 ) return valRes;
	strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
	return valRes;
}
Thank you so much for taking your time to fix this for me!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)