Simple Math Help - 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: Simple Math Help (
/showthread.php?tid=70709)
Simple Math Help -
StrickenKid - 27.03.2009
Im making a "crane" where you can sell certain cars fro cash, and i wanted to make it so the worse damage for the car the less you get paid.
I wanted to do something like: for every damage of 10, you lose 1K or something like that but im not sure how i do that math code.
Thanks for Any Help!
Re: Simple Math Help -
Nubotron - 27.03.2009
You can do it like this:
final_price = ( undamaged_car_price * ( car_health / max_car_health ) )
if undamaged_car_price is 100000$, and if car is damaged 40% (car_health=600) then it is
final_price = ( 100000 * ( 600 / 1000 ) ) = ( 100000 * 0.6 ) = 60000$
It is not realistic because more the car is damaged, and less it will cost money, not proportionally, i think, if car is damaged only 20% then price should be ~60% of undamaged car price, and if damage is 50% then price should be ~25% of undamaged car price.. Need think about this but it is too late in now : ))
Re: Simple Math Help -
Salmon - 27.03.2009
Couldn't you just check the health of the car,
Didn't test it but something like
Код:
new intial;
new payout;
intial = '50000';
new Float:health;
new veh;
new string[32];
veh = GetPlayerVehicleID(playerid);
GetVehicleHealth(veh, health);
payout = 'health / 100';
payout = 'payout * intial';
GivePlayerMoney(playerid, payout);
format(string, sizeof(string), "You have gained %d for your car.", payout);
SendClientMessage(playerid, 0xFFFFFFAA, string);
Re: Simple Math Help -
StrickenKid - 27.03.2009
thanks guys but which method do i use? lol they both sound good...
Re: Simple Math Help -
yezizhu - 27.03.2009
new
const perGain = 10000,//10k
const modDamage = 100,//default vehicle health is 1000.0
const defaultPrice = 0
Float:Vechp;
GetVehicleHealth(GetPlayerVehicleID(playerid),Vech p);
new
const earnCash = perGain*(Vechp/modDamage)+defaultPrice;
GivePlayerMoney(playerid,earnCash);
printf("earn %d",earnCash);
Converse thought.
Edited some type error
Re: Simple Math Help -
StrickenKid - 27.03.2009
so if that gives error.... which one is best? i got 3 suggestions for 3 diff ways.... anyone think 1 will work better than the other? or should i just pick a random suggestion...
Re: Simple Math Help -
Salmon - 27.03.2009
well how do you plan on having the person sell their car? Checkpoint, text command?