Percentage Problem
#1

I use /rob command to rob 10% of the other player's money
pawn Код:
new mrand =random((GetPlayerMoney(ID)/100)*10);
GivePlayerMoney(playerid,mrand);
but when the other player got 700K it robbed about 600K
Reply
#2

The formula to get any percentage is, generally speaking,

A % - B
C % - D

Whereas D is the incognita:

(C * B) / A = D (always divide by the number that's opposite to the incognita)

100 % - GetPlayerMoney(ID)
10% - X

(10 * GetPlayerMoney(ID)) / 100 = X

That's what you should use.
Reply
#3

10 percent is 1/10th, so you can use this:
pawn Код:
new mrand = random(GetPlayerMoney(ID)/10);
GivePlayerMoney(playerid,mrand);
Reply
#4

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
10 percent is 1/10th, so you can use this:
pawn Код:
new mrand = random(GetPlayerMoney(ID)/10);
GivePlayerMoney(playerid,mrand);
Of course he can also multiply the number by 0.1 to get the 10% of said number, but your formula would fail if he needed the 11%, since he can't divide by 11 to get 11%.

By using a three rule function you will get the exact plus you learn to do something new and might use it in the future. Alternatively you can always multiply (less than 1 to get the percentage, more than 1 to sum X percentage to the original number).

0.1 = 10%
0.11 = 11%
0.5 = 50%
0.9 = 90%
0.05 = 5%

1 = 100%
1.1 = 110%
1.5 = 150%
2 = 200%

and so on..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)