floatround? - 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)
+--- Thread: floatround? (
/showthread.php?tid=586168)
floatround? -
SumX - 19.08.2015
What is wrong at this command?
PHP код:
CMD:fill(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new fillstring[128];
format( fillstring, sizeof(fillstring), "You payed {FFFFFF}%d"ORANGESV"$ to refill your car's fuel.", floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100)*BusinessInfo[18][bFee]));
BusinessInfo[18][bMoney] += floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100 )*BusinessInfo[18][bFee]);
GivePlayerTheMoney(playerid, - floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100)*BusinessInfo[18][bFee]));
SCM(playerid, ORANGES, fillstring);
foreach(Player, i)
{
if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
{
KillTimer(CarTimer[playerid]);
TogglePlayerControllable(i, 0);
FillTimer[playerid] = SetTimerEx("Fill", 250, false, "i", i);
}
}
}
else SCM(playerid, COLOR_DGREY, "You are not driving a car.");
return 1;
}
It fills my vehicle but it won't take my money.
It says "You payed 0$ ro refill your car's fuel."
Is there a problem because of floatround?
BusinessFee = 5000, so:
Example: if I have 20/100 fuel I want to take my money 80% from BusinessFee, so 80/100*5000
Another example: if I have 70/100 fuel I want to take my money 30% from BusinessFee, so 30/100*5000
Can anyone help me? thanks!
AW: floatround? -
Nero_3D - 20.08.2015
Well you used integer instead of floats therefor it would always return 0
Add .0 after each 100, also use a variable, just looks silly to do the calculation three times
Re: floatround? -
ikkentim - 20.08.2015
Great read:
http://stackoverflow.com/a/3602857