GivePlayerMoney with float
#1

hello,
i want that e.g. a trucker can sell his fuel for e.g 0.2$/litre.
The Problem is that the player gets way to much money, instead 200$ at e.g 1001litres.

Код:
public OnPlayerCommandText(playerid, cmdtext[]) 
{ 
if (strcmp("/test", cmdtext, true, 10) == 0) 
{ 
new litre=10000; 
new Float:price=0.2; 
GivePlayerMoney(playerid, litre*price); //player gets unlimited money -.-
 return 1; 
} 
return 0;}
I tested a bit and i think the problem is that the money which the player should get is saved as float and not as int.
At
Код:
new litre=1001; 
new Float:price=0.2; 
new c=litre*price; 
printf("litre*price int: %i, float: %.2f c int: %i, float: %.2f", litre*price, litre*price, c, c);
I geht this result:
Код:
litre*price int:1128805171, float: 200.19 c int: 1128805171, float: 200.19
event the variable c isnt a float, the result of litre*price is saved as float?
is there any possibility for type conversion in pawn, e.g c = (int)(a*b); or c = (new) (a*b);


i hope sbd can help me,
Toastbrot
Reply
#2

GivePlayerMoney(playerid,floatround(float(litre)*p rice));
Reply
#3

thank you for the fast answer
tested it and works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)