SA-MP Forums Archive
Error money per distance - 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: Error money per distance (/showthread.php?tid=616535)



Error money per distance - AlexuTzVs - 06.09.2016

As the title says i want to give a player an amount of money per distance. this is the code but is not working

pawn Код:
distance = floatround(GetDistanceBetweenPoints(Position[0],Position[1], Position[2], gRandomPizza[rand][0], gRandomPizza[rand][1], gRandomPizza[rand][2]), floatround_round);
                    if(PlayerInfo[playerid][pPizzaSkill] == 1) pizzaprize[playerid] = random(15) + distance*(8/1000);



Re: Error money per distance - Vince - 06.09.2016

Integer divided by integer will remain integer. As such 8/1000 will simply yield 0. And as we all know, anything multiplied by 0 yields 0. The result will not be automatically converted to a floating point number. Instead of rounding the distance, round the final result.


Re: Error money per distance - AlexuTzVs - 06.09.2016

And can you help me doing that, you explained something good but i still can't solve this


Re: Error money per distance - AlexuTzVs - 06.09.2016

Up ? please


Re: Error money per distance - SickAttack - 06.09.2016

An integer division rounds the result to floor.

8/1000 is 0.008, which turns into 0 (integer division > floor)

I don't know in what range you want the amount to be, but try something like: (random(15) + 1) + (distance / 2)


Re: Error money per distance - AlexuTzVs - 11.09.2016

I want the player to get something like 20$ - 2000 meters. how is this possible. cuz if distance = 2000 / 2 = 1000 + random 15+1 which gives me 1000+$


Re: Error money per distance - Shinja - 12.09.2016

Try this
PHP код:
pizzaprize[playerid] = floatround(floatadd(float(random(15)), floatmul(float(distance), 0.008)), floatround_round);