Help With Getting Percentage
#1

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
Reply
#2

PHP код:
#include <a_samp>
#include <YSI\y_va>
new money GetPlayerMoney(playerid);
new 
Float:percent GetPercentageOfMoney(playerid120); 
// 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)"percentfloatround(percent));
Float:GetPercentageOfMoney(playeridFloat:percents)
{
    return 
floatdiv(floatmul(GetPlayerMoney(playerid), percents), 100);
}
SCMEx(playeridcolour, const message[], va_args<>)
{
    new 
out[145];
    
va_format(outsizeof(out), messageva_start<3>);
    return 
SendClientMessage(playeridcolourout);

Reply
#3

and what if i want to give that percent to another player ??
Reply
#4

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.
Reply
#5

thanks bro +rep
Reply
#6

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
....
Float:GetPercentageOfMoney(playerid, Floatercents)
{
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.
Reply
#7

Multiplying an integer by a float usually doesn't work with the usual *.
Reply
#8

so which is better ??
Reply
#9

Use the one you want then.
Both are working.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)