Crook4Money Posted January 27, 2018 Share Posted January 27, 2018 (edited) I made a script that I had to restart from scratch due to not backing it up and completely breaking it. When the script was in a better state I could get the sound to follow the vehicle I was driving, but I can't seem to get that to happen again. function startMySound(thePlayer) if ( isPedInVehicle ( thePlayer ) ) then local vehicle = getPedOccupiedVehicle(thePlayer) local x,y,z = getElementPosition( vehicle ) playSound3D( "sound1.mp3", x, y, z, true ) end end addEventHandler( "onClientVehicleEnter", root, startMySound ) From what I tried to remember from the last script setting the x,y,z to the vehicle was allowing the sound to follow the vehicle using the local coordinates, but the sound now just starts at the car and stays where the sound started playing. How do I get it to track your position? Edit: Come to think of it I couldn't get PlaySound3D to work at all with the original script for whatever reason and instead used PlaySound which would follow the player by default. So I guess I never had this working to begin with. Edited January 27, 2018 by Crook4Money Link to comment
rE5vK8bu Posted January 27, 2018 Share Posted January 27, 2018 (edited) Try use attachElements function startMySound(player) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) local x,y,z = getElementPosition(player) local sound = playSound3D("sound1.mp3",x,y,z,true) attachElements(sound,vehicle) -- It attach the sound to the vehicle end end addEventHandler("onClientVehicleEnter",getRootElement(),startMySound) Edited January 27, 2018 by lebrnno 1 Link to comment
ÆBKV Posted January 27, 2018 Share Posted January 27, 2018 (edited) addEventHandler("onClientPlayerVehicleEnter",root, function() local vehicle = getPedOccupiedVehicle(source) local x,y,z = getElementPosition(vehicle) sound = playSound3D("sound1.mp3",x,y,z,true) attachElements(sound,vehicle) end ) try this Edited January 27, 2018 by ÆBKV 1 Link to comment
Crook4Money Posted February 9, 2018 Author Share Posted February 9, 2018 Interesting formatting. It worked. tyty. 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