Simple Math Help
#1

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!
Reply
#2

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 : ))
Reply
#3

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);
Reply
#4

thanks guys but which method do i use? lol they both sound good...
Reply
#5

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
Reply
#6

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...
Reply
#7

well how do you plan on having the person sell their car? Checkpoint, text command?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)