NickScripter Posted August 29, 2019 Share Posted August 29, 2019 I'm using a script that changes the original sound of GTA vehicles. However, I can't destroy the sound when the vehicle is destroyed. Can anybody help me? Client-side local sound = {} addEventHandler("onClientWorldSound", root, function() if getElementType(source) == "vehicle" then cancelEvent() end end) addEventHandler("onClientElementDestroy", getRootElement(), function () if getElementType(source) == "vehicle" and getPedOccupiedVehicle(getLocalPlayer()) == source then if isElement(sound[veh]) then destroyElement(sound[veh]) end end end) 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) setSoundVolume(sound[veh], 0.2) 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
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