Jump to content

Attach music to vehicle


Volltron

Recommended Posts

Hello there again, I have a problem with my script. I want to make so when someone plays music in their car it will make others near hear it too but it doesn't start and I don't know what the problem is 
Client : 

local music = "blah.wav"
function playTheSound(x, y, z, vehicle)
	sound = playSound3D(music, x, y, z)
	attachElements(sound, vehicle)
	setSoundMaxDistance(sound,50)
	setSoundVolume(sound,1)
end
addEvent("playTheSound", true)
addEventHandler("playTheSound", root, playTheSound)

function stopTheSound(x, y, z)
	stopSound(sound)
end
addEvent("stopTheSound", true)
addEventHandler("stopTheSound", root, stopTheSound)

Server : 

function playMusic(thePlayer)
	if (isPedInVehicle(thePlayer)) then
		local x, y, z = getElementPosition(thePlayer)
		local vehicle = getPedOccupiedVehicle(thePlayer)
		triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle)
	else
		outputChatBox("You must be in a vehicle!", thePlayer, 0, 0, 255)
	end
end
addCommandHandler("start", playMusic)

function stopMusic(thePlayer)
	triggerClientEvent("stopTheSound", root)
end
addCommandHandler("stop", stopMusic)

 

Edited by Volltron
Link to comment

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