# Final Adjustments Sound system in vehicles

## Recommended Posts

I finished some adjustments, but to be perfect I need to create some kind of delay in the gearshift so it would be more realistic. some help ?

local sound = {}

function updateEngineSound()
local allVehicles = getElementsByType("vehicle")
for index, veh in ipairs (allVehicles) do
local model = getElementModel(veh)
if model == 411 then
if getVehicleEngineState(veh) then
if isElement(sound[veh]) then
local gear = getVehicleCurrentGear ( veh ) or 1
local velocityX, velocityY, velocityZ = getElementVelocity(veh)
--local actualspeed = ((velocityX^2 + velocityY^2 + velocityZ^2)^(0.5)) * ((11 - gear) /10)
local rpm =((velocityX^2 + velocityY^2 + velocityZ^2)^(0.5)) * 161
local mph = rpm * 80 * 111.847 / gear
local minSoundSpeed = 0.15
local soundSpeed
if (gear == 0) then
mph = rpm * 50 * 111.840
end
--soundSpeed = mph/(2000+2000/minSoundSpeed) + 0.20
soundSpeed = mph/(100000/minSoundSpeed) + minSoundSpeed
setSoundSpeed (sound[veh], soundSpeed)
outputChatBox(gear)
else
local x, y, z = getElementPosition(veh)
sound[veh] = playSound3D("sounds/engine.wav", x, y, z, true)
attachElements(sound[veh], veh)
end
else
if isElement(sound[veh]) then
destroyElement(sound[veh])
end
end
end
end
end

im not good on scripting but i thing this is usefully for your script.

Edited by Kutlu35
1 hour ago, Kutlu35 said:

im not good on scripting but i thing this is usefully for your script.

I just created this script for a reason! Improve the sound quality and create a more realistic system!, What I mean is to adjust the gearshift without the use of handling, but in the last case I can use it, since this resouce that you passed me is much worse than the my

Can't you just use a simple bool? For example isShiftingUp.

If it's true, start reducing soundSpeed to simulate the RPM dropping. If applicable you can also play some gear shifting sound here.

Then once the shifting is done, set the bool back to false to resume the sound simulation?

On 22.01.2017 at 03:53, Elvis Willian said:

I just created this script for a reason! Improve the sound quality and create a more realistic system!, What I mean is to adjust the gearshift without the use of handling, but in the last case I can use it, since this resouce that you passed me is much worse than the my

i send you link cuz this have gearshift system. You can read the lua file and see gear(rpm) system how does work. Good luck

Edited by Kutlu35
10 hours ago, Kutlu35 said:

i send you link cuz this have gearshift system. You can read the lua file and see gear(rpm) system how does work. Good luck

This would help me a lot if you can send me. I'm very grateful.

## Create an account

Register a new account