Ryosuke Posted January 17, 2017 Share Posted January 17, 2017 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
</Mr.Tn6eL> Posted January 17, 2017 Share Posted January 17, 2017 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
Ryosuke Posted January 17, 2017 Author Share Posted January 17, 2017 Really, that did not help much. The problem is the issue of changing the speed of sound when the gears pass :\ Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now