function updateEngineSound()
local allVehicles = getElementsByType("vehicle")
for index, veh in ipairs (allVehicles) do
local model = getElementModel(veh)
if model == 580 then
if getVehicleEngineState(veh) then
local x, y, z = getElementPosition(veh)
local sound = getElementData(veh, "engineSound")
sound = playSound3D("sounds/song.mp3", x, y, z, true)
setElementData(veh, "engineSound", sound)
end
if isSoundPaused(sound) then
setSoundPaused(sound, false)
end
local velocityX, velocityY, velocityZ = getElementVelocity(veh)
local actualspeed = (velocityX^2 + velocityY^2 + velocityZ^2)^(0.5)
local mph = actualspeed * 50 * 111.847
local minSoundSpeed = 0.25
local soundSpeed = mph/(80+80/minSoundSpeed) + minSoundSpeed
setSoundSpeed (sound, soundSpeed)
setElementPosition(sound, x, y, z)
else -- otherwise (so if the engine is off)
setSoundPaused(sound, true)
end
end
end
end
setTimer(updateEngineSound, 50, 0)