Jump to content

Vehicle RPM returns -1.#ND on reverse gear


Karuzo

Recommended Posts

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

oops.

didn't noticed that :D

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...