Jump to content

Engine Sound System - HELP


Ryosuke

Recommended Posts

 

Help me. I got the snore script on the vehicles. But he has a continuous snoring. How can I synchronize with the gears? . Give me some examples please

 

 

 

 

 

 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 velocityX, velocityY, velocityZ = getElementVelocity(veh) 
                    local actualspeed = (velocityX^2 + velocityY^2 + velocityZ^2)^(0.5) 
                    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
  • Moderators

getVehicleCurrentGear

local gear = getVehicleCurrentGear ( veh ) or 1
local actualspeed = ((velocityX^2 + velocityY^2 + velocityZ^2)^(0.5)) * ((11 - gear) /10)

You could try something like this. Although I have no idea how to do it perfectly.

Another solution would be playing another sound.

 

Also I added the gear data to the actually speed. Which isn't really semantic solution. But you will figure it out! :)

 

 

Edited by IIYAMA
Link to comment

In fact, you do not have to use the gears specifically. But rather with each speed obtaining a different speed in the sound. Like that, every km / h it changes the local SoundSpeed kmh = actualspeed * 180 SoundSpeed = 0.15 .I tried to write a code for this but gave some errors

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