Taknig a number away (minus) -
Cole_William - 19.07.2014
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?
Re: Taknig a number away (minus) -
Hanger - 19.07.2014
Код:
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
Re: Taknig a number away (minus) -
sammp - 19.07.2014
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;
Re: Taknig a number away (minus) -
Cole_William - 19.07.2014
Quote:
Originally Posted by Hanger
|
So i just do
PlayerInfo[playerid][pCash] = -1; ?? But if i do that it just sets their money to -1 instead of minus 1.
Re : Taknig a number away (minus) -
S4t3K - 19.07.2014
No.
To take a number away from a variable, use the "-=" operator.
pawn Код:
main()
{
new var = 84:
var -= 3;
printf("%d", var);
}
Output : 81.
Re: Taknig a number away (minus) -
sammp - 19.07.2014
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
Re: Taknig a number away (minus) -
Hanger - 19.07.2014
Edited my part, look again @ second post
Re: Taknig a number away (minus) -
Cole_William - 19.07.2014
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!
Re: Taknig a number away (minus) -
sammp - 19.07.2014
Quote:
Originally Posted by Hanger
Edited my part, look again @ second post
|
Just saying += doesn't just mean "add"
It means addition assignment.
Things like +=, -=, *= etc are all called
Compound assignment operators.
Things like +, -, * etc are all called
Arithmetic operators.