SA-MP Forums Archive
[UNSOLVED] Big problem, cannot solve it. - 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: [UNSOLVED] Big problem, cannot solve it. (/showthread.php?tid=113209)



[UNSOLVED] Big problem, cannot solve it. - FreddeN - 12.12.2009

Well, I've been trying to fix this problem for a long time now and I just cant find a way to solve it.

This problem shows up on other functions like Admin Level and Ranks etc... is dosent even save money I earned, but now we will discuss about my Bank System.

When I'm logged in and earn some money I walk to the Bank and type /bank <amount>, I've double checked my %s.ini, it saves the amount.
But when I disconnect and checks the %s.ini the amount is gone, I had like $100 when I left and now it just dissapeard to $0.

When I connect again the money is still gone...

Basicly, my Register System seems to have a saving error when disconnecting...

If you want to take a look at my full script, here you go:

http://pastebin.com/f1f28ded1

Please, I hope you can solve this for me, thanks!



Re: [HELP] Big problem, cannot solve it. - Backwardsman97 - 12.12.2009

You do know that OnPlayerUpdate gets called very very fast? You are doing your saving very wrong. Opening and writing into files under OnPlayerUpdate is bad. You should just read when the player logs in and save when the player leaves.


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

Quote:
Originally Posted by Backwardsman97
You do know that OnPlayerUpdate gets called very very fast? You are doing your saving very wrong. Opening and writing into files under OnPlayerUpdate is bad. You should just read when the player logs in and save when the player leaves.
No, I didnt know that, hmm, you got a tips how I could make a better saving system?


Re: [HELP] Big problem, cannot solve it. - Backwardsman97 - 12.12.2009

Pretty much I would just say to put the stuff under OnPlayerUpdate under OnPlayerDisconnect. And the reason I think this isn't working is because under OnPlayerUpdate you set the variable to store money to whatever the player has right then. Well if the player is leaving, it takes away their money and then saves it.


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

Quote:
Originally Posted by Backwardsman97
Pretty much I would just say to put the stuff under OnPlayerUpdate under OnPlayerDisconnect. And the reason I think this isn't working is because under OnPlayerUpdate you set the variable to store money to whatever the player has right then. Well if the player is leaving, it takes away their money and then saves it.
Alright, I will do some experiments with it, I will make a update soon


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

By putting it under OnPlayerDisconnect it dident save when I got the money ingame or at Disconnect...

Код:
public OnPlayerDisconnect(playerid, reason)
{
	gPlayerLogged[playerid] = 0;
  
  if(IsPlayerConnected(playerid))
	{
		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);
				fclose(hFile);
			}
		}
	}
	return 1;
}



Re: [HELP] Big problem, cannot solve it. - Joe Staff - 12.12.2009

pawn Код:
gPlayerLogged[playerid] = 0;
 
  if(IsPlayerConnected(playerid))
    {
        if(gPlayerLogged[playerid])
What looks wrong there?


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

Quote:
Originally Posted by Joe Staff
pawn Код:
gPlayerLogged[playerid] = 0;
 
  if(IsPlayerConnected(playerid))
    {
        if(gPlayerLogged[playerid])
What looks wrong there?
I will try this.


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

Well, by deleting that line(s) it just shows the amount in the %s.ini, but when I get ingame the money is still gone...

And there is no such command like /update that updates the information from the %s.ini file?


Re: [HELP] Big problem, cannot solve it. - FreddeN - 12.12.2009

Sorry for double posting, but I cant continue on a script that got such an error.