Jump to content

[HELP] Count vehicle acceleration from 0 to 100km/h


JAY.ANN

Recommended Posts

With enough testing and tweaking I'm sure it is possible, however you can cheat. You can create every vehicle with a ped in it, give them a forwards control state and measure the time it takes them to accelerate to 100 km/h. This is a way easier solution. Do it with 20 peds in 20 vehicles in the same time and it should be quick enough to do it every now and then.

  • Confused 1
Link to comment
local screenWidth, screenHeight = guiGetScreenSize ( ) 

function getAccelerationTime(vehicle)
	local acc = 0
	local maxVelocity = getVehicleHandling(vehicle).maxVelocity
	local gearRatio = getVehicleHandling(vehicle).driveType == 'f' and getVehicleHandling(vehicle).engineAcceleration or getVehicleHandling(vehicle).engineAcceleration*getVehicleHandling(vehicle).numberOfGears
	acc = 100/maxVelocity*gearRatio
	return acc
end

function showAccelerationTime()
	if not isPedInVehicle(localPlayer) then return false end
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if not vehicle or getVehicleEngineState(vehicle) == false then return false end
	local acc = getAccelerationTime(vehicle)
	dxDrawText(string.format("%0.2f", acc).." sec", 0, 0, screenWidth, screenHeight, tocolor(255, 255, 255), 1, "pricedown", "center", "center")
end
addEventHandler("onClientRender", root, showAccelerationTime)

 

Link to comment
7 hours ago, WorthlessCynomys said:

With enough testing and tweaking I'm sure it is possible, however you can cheat. You can create every vehicle with a ped in it, give them a forwards control state and measure the time it takes them to accelerate to 100 km/h. This is a way easier solution. Do it with 20 peds in 20 vehicles in the same time and it should be quick enough to do it every now and then.

I thought about this way, but it seems too complicated

4 hours ago, Smokahontas said:
local screenWidth, screenHeight = guiGetScreenSize ( ) 

function getAccelerationTime(vehicle)
	local acc = 0
	local maxVelocity = getVehicleHandling(vehicle).maxVelocity
	local gearRatio = getVehicleHandling(vehicle).driveType == 'f' and getVehicleHandling(vehicle).engineAcceleration or getVehicleHandling(vehicle).engineAcceleration*getVehicleHandling(vehicle).numberOfGears
	acc = 100/maxVelocity*gearRatio
	return acc
end

function showAccelerationTime()
	if not isPedInVehicle(localPlayer) then return false end
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if not vehicle or getVehicleEngineState(vehicle) == false then return false end
	local acc = getAccelerationTime(vehicle)
	dxDrawText(string.format("%0.2f", acc).." sec", 0, 0, screenWidth, screenHeight, tocolor(255, 255, 255), 1, "pricedown", "center", "center")
end
addEventHandler("onClientRender", root, showAccelerationTime)

 

Thank you, I gonna test it and answer about the results!

Link to comment
4 hours ago, Smokahontas said:
local screenWidth, screenHeight = guiGetScreenSize ( ) 

function getAccelerationTime(vehicle)
	local acc = 0
	local maxVelocity = getVehicleHandling(vehicle).maxVelocity
	local gearRatio = getVehicleHandling(vehicle).driveType == 'f' and getVehicleHandling(vehicle).engineAcceleration or getVehicleHandling(vehicle).engineAcceleration*getVehicleHandling(vehicle).numberOfGears
	acc = 100/maxVelocity*gearRatio
	return acc
end

function showAccelerationTime()
	if not isPedInVehicle(localPlayer) then return false end
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if not vehicle or getVehicleEngineState(vehicle) == false then return false end
	local acc = getAccelerationTime(vehicle)
	dxDrawText(string.format("%0.2f", acc).." sec", 0, 0, screenWidth, screenHeight, tocolor(255, 255, 255), 1, "pricedown", "center", "center")
end
addEventHandler("onClientRender", root, showAccelerationTime)

 

It doesn't work correctly. It outputs 26.67 sec at the Admiral but my stopwatch says that it's 6.35 sec. I guess it may be because of Drag Multiplier and Interia values

Edited by JAY.ANN
Link to comment

Just type /check

function checkVehicleSpeed()
    local vehicle = getPedOccupiedVehicle(getLocalPlayer())
    local accel = getVehicleHandling(vehicle).engineAcceleration
    local seconds = 100/accel
    outputChatBox("Your vehicle takes " .. seconds .. " seconds to get from 0 to 100km/h")
end
addCommandHandler("check", checkVehicleSpeed)

 

  • Thanks 1
Link to comment
12 hours ago, Smokahontas said:

Just type /check

function checkVehicleSpeed()
    local vehicle = getPedOccupiedVehicle(getLocalPlayer())
    local accel = getVehicleHandling(vehicle).engineAcceleration
    local seconds = 100/accel
    outputChatBox("Your vehicle takes " .. seconds .. " seconds to get from 0 to 100km/h")
end
addCommandHandler("check", checkVehicleSpeed)

 

This one works fine, thank you so much!

Solved

  • Like 1
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...