05.02.2017, 13:15
Code:
Right now it sets the money of the player to the value that is set.
Like if a player will pay someone 12 dollars the money of that person will be set to 12 dollars.
How can I set that if he receives 12 dollars then it will be added to his value and if I use in script -value example -12 it will take 12 from him?
I tried
PlayerInfo[playerid][pCash] += value;
but it keep adding, like if the player connect and his money load it will be like this, money that loaded from database + money that loaded from the database..
So the question is.. how to detect if the value is - or +
PHP код:
GivePlayerMoneyEx(playerid, value)
{
new string[20], DB_Query[256];
if(PlayerInfo[playerid][pCash] < 10)
{
format(string, sizeof(string), "C000000%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 9 && PlayerInfo[playerid][pCash] < 100)
{
format(string, sizeof(string), "C00000%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 99 && PlayerInfo[playerid][pCash] < 1000)
{
format(string, sizeof(string), "C0000%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 999 && PlayerInfo[playerid][pCash] < 10000)
{
format(string, sizeof(string), "COINS 000%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 9999 && PlayerInfo[playerid][pCash] < 100000)
{
format(string, sizeof(string), "C00%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 99999 && PlayerInfo[playerid][pCash] < 1000000)
{
format(string, sizeof(string), "C0%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
else if(PlayerInfo[playerid][pCash] > 999999 && PlayerInfo[playerid][pCash] < 10000000)
{
format(string, sizeof(string), "C%i", PlayerInfo[playerid][pCash]);
PlayerTextDrawSetString(playerid, MoneyText[0][playerid], string);
PlayerInfo[playerid][pCash] = value;
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `CASH` = %d WHERE `ID` = %d"
, PlayerInfo[playerid][pCash], PlayerInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
}
return 1;
}
Like if a player will pay someone 12 dollars the money of that person will be set to 12 dollars.
How can I set that if he receives 12 dollars then it will be added to his value and if I use in script -value example -12 it will take 12 from him?
I tried
PlayerInfo[playerid][pCash] += value;
but it keep adding, like if the player connect and his money load it will be like this, money that loaded from database + money that loaded from the database..
So the question is.. how to detect if the value is - or +