Karuzo Posted August 6, 2014 Share Posted August 6, 2014 Hey guys, I use a useful function to get the actual rpm of a car and it always returns me -1.#ND if I pressed S one time (it's in the reverse gear). Idk why and i don't really know how to fix this. If anybody could help me , that would be great. here's my code: function getVehicleRPM(vehicle) if not vehicle then return "0" end if getVehicleEngineState(vehicle) == false then return "0" end local speedx, speedy, speedz = getElementVelocity(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local gear = getVehicleCurrentGear(vehicle) local handling = getVehicleHandling(vehicle) local acceleration = handling["engineAcceleration"] local maxSpeed = handling["maxVelocity"] local gears = handling["numberOfGears"] local gearSpeed = maxSpeed/gears local currentGearSpeed = kmh/gear local gearDiff = gearSpeed - currentGearSpeed if currentGearSpeed > gearSpeed then gearDiff = 1 end local RPM = math.ceil( (maxSpeed/gearDiff)*100)*3 return RPM end Link to comment
Gallardo9944 Posted August 6, 2014 Share Posted August 6, 2014 division by zero? Nice, man Link to comment
Karuzo Posted August 6, 2014 Author Share Posted August 6, 2014 oops. didn't noticed that For all who need it: function getVehicleRPM(vehicle) if not vehicle then return "0" end local currentGearSpeed if getVehicleEngineState(vehicle) == false then return "0" end local speedx, speedy, speedz = getElementVelocity(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local gear = getVehicleCurrentGear(vehicle) local handling = getVehicleHandling(vehicle) local acceleration = handling["engineAcceleration"] local maxSpeed = handling["maxVelocity"] local gears = handling["numberOfGears"] local gearSpeed = maxSpeed/gears local currentGearSpeed = 0 if not (gear == 0) then currentGearSpeed = kmh/gear end local gearDiff = gearSpeed - currentGearSpeed if currentGearSpeed > gearSpeed then gearDiff = 1 end local RPM = math.ceil( (maxSpeed/gearDiff)*100)*3 return RPM end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now