Jump to content

[Question] How do you get PlaySound3D to follow


Crook4Money

Recommended Posts

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 by Crook4Money
Link to comment

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 by lebrnno
  • Thanks 1
Link to comment
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 by ÆBKV
  • Thanks 1
Link to comment
  • 2 weeks later...

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