How can I make a save cash timer? [MySql]
#1

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);
Reply
#2

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)
{

}
Reply
#3

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);
       }
Reply
#4

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.
Reply
#5

Still not working...
Reply
#6

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)