Help With Getting Percentage -
AroseKhanNiazi - 23.05.2014
How do i get percentage of something in samp
like like over deaths
and other ... getting his total money and taking away any percentage of money form him
Re : Help With Getting Percentage -
S4t3K - 23.05.2014
PHP код:
#include <a_samp>
#include <YSI\y_va>
new money = GetPlayerMoney(playerid);
new Float:percent = GetPercentageOfMoney(playerid, 1, 20);
// Will take %20 of the player's money and store it to "percent"
GivePlayerMoney(playerid, -floatround(percent));
SCMEx(playerid, -1, "You've death ! You've lost %%%f of your money ($%d)", percent, floatround(percent));
Float:GetPercentageOfMoney(playerid, Float:percents)
{
return floatdiv(floatmul(GetPlayerMoney(playerid), percents), 100);
}
SCMEx(playerid, colour, const message[], va_args<>)
{
new out[145];
va_format(out, sizeof(out), message, va_start<3>);
return SendClientMessage(playerid, colour, out);
}
Re: Help With Getting Percentage -
AroseKhanNiazi - 23.05.2014
and what if i want to give that percent to another player ??
Re : Help With Getting Percentage -
S4t3K - 23.05.2014
Use the function to get the player money, then use GivePlayerMoney combined to floatround(percent) (returns an integer from a float parameter) to give the percentage to the other player.
Re: Help With Getting Percentage -
AroseKhanNiazi - 23.05.2014
thanks bro +rep
Re: Re : Help With Getting Percentage -
RajatPawar - 23.05.2014
Quote:
Originally Posted by S4t3K
....
Float:GetPercentageOfMoney(playerid, Float  ercents)
{
return floatdiv(floatmul(GetPlayerMoney(playerid), percents), 100);
}
|
As a side note, this is really slow as compared to this -
pawn Код:
new money = 5000,
Float: percentMoney = (money * 0.65); // 65 percent of money
float*** functions are quite slow, I see no need to use them..
EDIT: In response to your below post -
pawn Код:
main() {
new money = 5000;
new Float: percentMoney = (money * 0.50);
printf("%0.2f", percentMoney);
}
works quite perfectly.
Re : Help With Getting Percentage -
S4t3K - 23.05.2014
Multiplying an integer by a float usually doesn't work with the usual *.
Re: Help With Getting Percentage -
AroseKhanNiazi - 23.05.2014
so which is better ??
Re : Help With Getting Percentage -
S4t3K - 23.05.2014
Use the one you want then.
Both are working.
Re : Help With Getting Percentage -
S4t3K - 23.05.2014
But the percentages are calculated if you divide per 100 then you multiply by a number, aren't ?
I've always used the floatxxx operations because when I've began, I tried with the basic operations then it didn't work. So if I've told something wrong, please excuse me.