Taknig a number away (minus)
So i been looking all over for a way to minus a number in a users file like

Ignore indenting, it looked all messed up with it when posting.
pawn Код:
`if(PlayerInfo[playerid][pCash] < 500){SendClientMessage(playerid, COLOR_GREY, "You don't have enough money");RemovePlayerFromVehicle(playerid);}GivePlayerMoney(playerid, -500);PlayerInfo[playerid][pRenting] = 1;SendClientMessage(playerid, COLOR_GREEN, "Enjoy your ride!");PlayerInfo[playerid][pCash] = 1;`
I want PlayerInfo[playerid][pCash] = 1; to minus 500 from their current amount, how do we do this?
Код:
```Operator	 Meaning						 Usage
==	 	 Left is equal to Right				 if (Left == Right)
!=		 Left is not equal to Right			 if (Left != Right)
>		 Left is greater than Right			 if (Left > Right)
>=		 Left is greater than or equal to Right	 	 if (Left >= Right)
<		 Left is less than Right			 if (Left < Right)
<=		 Left is less than or equal to Right		 if (Left <= Right)

-=		 Minus		 		 		 Variable -= 10
+=		 Plus		 		 		 Variable += 10
=		 Assign a value to variable	 		 Variable = 10```
The method of doing this is really simple.

You might want to make this on your OnPlayerUpdate: Easy way of stopping money hacks

pawn Код:
`if(GetPlayerMoney(playerid) != Player[playerid][Money])        {            ResetPlayerMoney(playerid);            GivePlayerMoney(playerid, Player[playerid][Money]);        }        if(GetPlayerScore(playerid) != Player[playerid][Level])        {            SetPlayerScore(playerid, 0);            SetPlayerScore(playerid, Player[playerid][Level]);        }]`
Change the variables, obviously.

Then, rather than your method you can do this:

pawn Код:
`if(PlayerInfo[playerid][pCash] < 500) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money");PlayerInfo[playerid][pRenting] = 1;SendClientMessage(playerid, COLOR_GREEN, "Enjoy your ride!");PlayerInfo[playerid][pCash] -= 500;`
Using the -= operator we can take a value away from a variable.

Don't do this, an exception will occur:

pawn Код:
`PlayerInfo[playerid][pCash] - 500;`
Quote:
So i just do

PlayerInfo[playerid][pCash] = -1; ?? But if i do that it just sets their money to -1 instead of minus 1.
No.

To take a number away from a variable, use the "-=" operator.

pawn Код:
`main(){      new var = 84:      var -= 3;      printf("%d", var);}`
Output : 81.
Quote:
 Originally Posted by Cole_William So i just do PlayerInfo[playerid][pCash] = -1; ?? But if i do that it just sets their money to -1 instead of minus 1.
look at my comment
Edited my part, look again @ second post
Quote:
 Originally Posted by sammp The method of doing this is really simple. You might want to make this on your OnPlayerUpdate: Easy way of stopping money hacks pawn Код: `if(GetPlayerMoney(playerid) != Player[playerid][Money])        {            ResetPlayerMoney(playerid);            GivePlayerMoney(playerid, Player[playerid][Money]);        }        if(GetPlayerScore(playerid) != Player[playerid][Level])        {            SetPlayerScore(playerid, 0);            SetPlayerScore(playerid, Player[playerid][Level]);        }]` Change the variables, obviously. Then, rather than your method you can do this: pawn Код: `if(PlayerInfo[playerid][pCash] < 500) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money");PlayerInfo[playerid][pRenting] = 1;SendClientMessage(playerid, COLOR_GREEN, "Enjoy your ride!");PlayerInfo[playerid][pCash] -= 500;` Using the -= operator we can take a value away from a variable. Don't do this, an exception will occur: pawn Код: `PlayerInfo[playerid][pCash] - 500;`
Thanks for the help!
Quote:
 Originally Posted by Hanger Edited my part, look again @ second post
Just saying += doesn't just mean "add"