Quote:
Originally Posted by Schneider
Alright, this is how I update my vehicles fuel: (It's inside a timer).
Obviously it's just a little piece, but you'll know how to implement it in your code.
pawn Код:
new Float:consumption, Float:distance; if((X != lastX) || (Y != lastY)|| (Z != lastZ)) //Check if player has moved { distance = floatround(floatsqroot(floatpower(floatabs(floatsub(X,lastX)),2)+floatpower(floatabs(floatsub(Y,lastY)),2)+floatpower(floatabs(floatsub(Z,lastZ)),2))); distance = distance / 50; consumption = floatdiv(distance, VehicleInfo[vehicleID][FuelConsumption]); //devide the distance with its distance/liter VehicleInfo[vehicleID][Fuel] = floatsub(VehicleInfo[vehicleID][Fuel], consumption); LastX = X; LastY = Y; LastZ = Z; }
Edit: My fuelsystem is based on the Metric System (kilometers/liters). I don't know if it works right for Miles/gallon
|
Just a question, how are the x,y,z & lastx, lasty, lastz stored?