GivePlayerMoney with float - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GivePlayerMoney with float (
/showthread.php?tid=123812)
GivePlayerMoney with float -
tostbrot - 27.01.2010
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
Re: GivePlayerMoney with float - Double-O-Seven - 27.01.2010
GivePlayerMoney(playerid,floatround(float(litre)*p rice));
Re: GivePlayerMoney with float -
tostbrot - 27.01.2010
thank you for the fast answer

tested it and works