Sergo86 Posted December 2, 2013 Share Posted December 2, 2013 This script replaces the sound of Infernus. The problem is that when I made one Infernus sound works when will create 1 more Infernus sound disappears, even the standard. Help fix client side local engine_sound = "files/engine.wav" local idle_soundfile = "files/engine_idle.wav" local sound = nil local idle_sound = nil function getVehicleRPM(vehicle) if (vehicle) then if (isVehicleOnGround(vehicle)) then if (getVehicleEngineState(vehicle) == true) then if(getVehicleCurrentGear(vehicle) > 0) then vehicleRPM = math.floor(((getElementSpeed(vehicle, "kmh")/getVehicleCurrentGear(vehicle))*220) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end else vehicleRPM = math.floor(((getElementSpeed(vehicle, "kmh")/1)*220) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end end else vehicleRPM = 0 end else if (getVehicleEngineState(vehicle) == true) then vehicleRPM = vehicleRPM - 150 if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end else vehicleRPM = 0 end end return tonumber(vehicleRPM) else return 0 end end function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end function engine_func() local veh = getPedOccupiedVehicle ( getLocalPlayer()) if veh then if getElementModel ( veh ) == 411 then if getVehicleEngineState ( veh ) == true then if getElementSpeed ( veh, "kmh" ) > 10 then if idle_sound then destroyElement ( idle_sound ) idle_sound = nil end if sound == nil then sound = playSound3D ( engine_sound, 0, 0, 0, true ) attachElements ( sound, veh ) end setSoundSpeed ( sound, getVehicleRPM(veh)/10000 ) elseif getElementSpeed ( veh, "kmh" ) < 10 then if idle_sound == nil then idle_sound = playSound3D ( idle_soundfile, 0, 0, 0, true ) setSoundVolume ( idle_sound, 0.2 ) attachElements ( idle_sound, veh ) end elseif getElementSpeed ( veh, "kmh" ) == 0 then if sound then destroyElement ( sound ) sound = nil end end else if sound then destroyElement ( sound ) sound = nil end if idle_sound then destroyElement ( idle_sound ) idle_sound = nil end end end end end addEventHandler ( "onClientVehicleEnter", getRootElement(), function() if getElementModel ( source ) == 411 then setWorldSoundEnabled( 40, false ) addEventHandler ( "onClientRender", getRootElement(), engine_func ) end end) addEventHandler ( "onClientVehicleExit", getRootElement(), function() setWorldSoundEnabled( 40, true ) removeEventHandler ( "onClientRender", getRootElement(), engine_func ) end) 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