Money problem!
#1

Sometimes they disappear players money! (Using MYSQL R39).
Sometimes players with $45,000+ remain to $1,000.
Код HTML:
stock GiveMoney(playerid, money)
{
    pInfo[playerid][pMoney] += money;
    mysql_format(MySQLCon, QuerY, sizeof(QuerY), "UPDATE `players` SET `Money`=%d WHERE `ID`=%d AND `user`='%e'", pInfo[playerid][pMoney],pInfo[playerid][pID],GetName(playerid));
    mysql_pquery(MySQLCon, QuerY);
    ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
    UpdateMoneyBar(playerid,pInfo[playerid][pMoney]);//Sets the money in the moneybar to the serverside cash, Do not remove!
    return pInfo[playerid][pMoney];
}
Reply
#2

It's terrible to save player money whenever he earns or loses money.

This function doesn't explain why the gave money is wrong.
Reply
#3

Why would it be terrible to save the money whenever it changes?
It's the best way to keep your data up to date all the time.

If you only save when the player disconnects, your player may have played for hours and can lose all his progress when there's a sudden server-crash or a power-outage (which does happen sometimes).
Let this happen a few times to a player and you won't see him again on your server (I would never join again on a server that doesn't save my data regularly while playing).

I've seen scripts that save EVERYTHING during OnPlayerDisconnect, which is far more terrible.
A player may login for a few minutes and log out again after one mission.
Why would you save dozens of fields when only 1 value changes, or perhaps none at all?

In my own scripts, I save whenever data changes.
Player earns money -> save it.
Player earns scorepoints -> save it.
Player joins a company -> save it.
Player makes a kill -> save it.

Every save-function like the one posted above is small and perfectly manageable.

On topic:
You don't have to check for the player's ID and his name for updating his money.
Only his ID would be fine.
But it shows no reason to why your player may lose money.

EDIT:
After taking a closer look, don't use pqueries to update data like a player's money.
pqueries run in parallel with other pqueries, which may get ahead and you will never be sure it your last query is actually executed last.

You may send query1 to set his money to 1000, then he earns money (say $5000) and you send query2 to update his money to 6000.
But suppose for whatever reason query1 takes longer to execute than query2, you'll be setting his money to 6000 first and update it to 1000 later on.

NEVER use pqueries for this.
Only normal queries (which halt execution of your script and also may not be what you want) or tqueries (the best ones for this job).
Reply
#4

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Why would it be terrible to save the money whenever it changes?
It's the best way to keep your data up to date all the time.

If you only save when the player disconnects, your player may have played for hours and can lose all his progress when there's a sudden server-crash or a power-outage (which does happen sometimes).
Let this happen a few times to a player and you won't see him again on your server (I would never join again on a server that doesn't save my data regularly while playing).

I've seen scripts that save EVERYTHING during OnPlayerDisconnect, which is far more terrible.
A player may login for a few minutes and log out again after one mission.
Why would you save dozens of fields when only 1 value changes, or perhaps none at all?

In my own scripts, I save whenever data changes.
Player earns money -> save it.
Player earns scorepoints -> save it.
Player joins a company -> save it.
Player makes a kill -> save it.

Every save-function like the one posted above is small and perfectly manageable.

On topic:
You don't have to check for the player's ID and his name for updating his money.
Only his ID would be fine.
But it shows no reason to why your player may lose money.

EDIT:
After taking a closer look, don't use pqueries to update data like a player's money.
pqueries run in parallel with other pqueries, which may get ahead and you will never be sure it your last query is actually executed last.

You may send query1 to set his money to 1000, then he earns money (say $5000) and you send query2 to update his money to 6000.
But suppose for whatever reason query1 takes longer to execute than query2, you'll be setting his money to 6000 first and update it to 1000 later on.

NEVER use pqueries for this.
Only normal queries (which halt execution of your script and also may not be what you want) or tqueries (the best ones for this job).
Okay, I change pquery with tquery.
It's good?
Код HTML:
stock GiveMoney(playerid, money)
{
    pInfo[playerid][pMoney] += money;
    mysql_format(MySQLCon, QuerY, sizeof(QuerY), "UPDATE `players` SET `Money`=%d WHERE `ID`=%d AND `user`='%e'", pInfo[playerid][pMoney],pInfo[playerid][pID],GetName(playerid));
    mysql_tquery(MySQLCon, QuerY);
    ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
    UpdateMoneyBar(playerid,pInfo[playerid][pMoney]);//Sets the money in the moneybar to the serverside cash, Do not remove!
    return pInfo[playerid][pMoney];
}
Reply
#5

bump!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)