SA-MP Forums Archive
How can I make a save cash timer? [MySql] - 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: How can I make a save cash timer? [MySql] (/showthread.php?tid=584835)



How can I make a save cash timer? [MySql] - andreistalker - 08.08.2015

How can i Make a save cash timer?
I tried this:
Код HTML:
forward updatemoney();
public updatemoney()
{
       new query[256];
		foreach(Player, i)
		mysql_format(handle, query, sizeof(query), "UPDATE 'conturi' SET 'Cash' = '%d' WHERE 'Name' = '%s'",P_Data[i][pCash],GetName(i));
		mysql_query(handle, query);
	return 1;
}
And the timer:
Код HTML:
MoneyTimer = SetTimer("updatemoney", 1000, true);



Re: How can I make a save cash timer? [MySql] - liquor - 08.08.2015

And the problem? Btw once every second is a little unnecessary, if you don't expect the gamemode to crash very very often.

I can see one problem, you are not opening the foreach loop, like this;
pawn Код:
foreach(Player,i)
{

}



Re: How can I make a save cash timer? [MySql] - X337 - 08.08.2015

You forgot to add brackets on "foreach" loop.
So, it's just executed the last player.
Код:
	foreach(Player, i)
       {
		mysql_format(handle, query, sizeof(query), "UPDATE 'conturi' SET 'Cash' = '%d' WHERE 'Name' = '%s'",P_Data[i][pCash],GetName(i));
		mysql_query(handle, query);
       }



Re: How can I make a save cash timer? [MySql] - Vince - 08.08.2015

You don't. Clearly "P_Data[i][pCash]" gets updated somehwere. It is at that point that the query must be sent, not in some arbitrary intervals. If you only have lines like:
pawn Код:
P_Data[playeird][pCash] += 1000;
Then you should write a function which does that job AND which updates the database.


Re: How can I make a save cash timer? [MySql] - andreistalker - 08.08.2015

Still not working...


Re: How can I make a save cash timer? [MySql] - andreistalker - 08.08.2015

The problem is with sending to the database, when i write stats i get the money


Re: How can I make a save cash timer? [MySql] - andreistalker - 08.08.2015

Now it's working, but when i loggin is not giving my money, until now worked....


Re: How can I make a save cash timer? [MySql] - andreistalker - 08.08.2015

Close thread, i resolved it
Код HTML:
public updatemoney()
{
		foreach(Player, i)
		{
  		if(gLogged[i] == 1){
		P_Data[i][pCash] = GetPlayerMoney(i);
		new query[256];
	mysql_format(handle, query, sizeof(query), "UPDATE `conturi` SET `Cash`='%d' WHERE `Nume`='%s'", P_Data[i][pCash], GetName(i));// facem update-ul la baza de date
 	mysql_query(handle, query);
		}
		}
	return 1;
}
I added if(gLogged[i] == 1) and now works