Jump to content

Engine Sound Synchronization Help


Ryosuke

Recommended Posts

  Well the script is almost perfect! . Just missing the part of synchrony in the gearshift, someone to help me?

 

 

 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 
                    local x, y, z = getElementPosition(veh) 
                    local sound = getElementData(veh, "engineSound") 
                    if not sound then 
                        sound = playSound3D("sounds/engine.wav", x, y, z, true) 
                        setElementData(veh, "engineSound", sound,false) 
                    end 
                    if isSoundPaused(veh) then 
                        setSoundPaused(sound, false) 
                    end 
                    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 mph = actualspeed * 70 * 111.847 
                    local minSoundSpeed = 0.15 
                    local soundSpeed = mph/(1000+1000/minSoundSpeed) + minSoundSpeed  
                    setSoundSpeed (sound, soundSpeed) 
                    setElementPosition(sound, x, y, z) 
                else 
                    setSoundPaused(sound, true) 
                end 
            end 
        end 
    end 
    addEventHandler ("onClientPreRender", root, updateEngineSound) 

Link to comment
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 mph = actualspeed * 70 * 111.847 
                    local minSoundSpeed = 0.15 
                    local soundSpeed = mph/(1000+1000/minSoundSpeed) + minSoundSpeed  
                    setSoundSpeed (sound[veh], soundSpeed) 
                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 
addEventHandler("onClientPreRender", root, updateEngineSound) 

 

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...