PaiN^ Posted March 27, 2013 Share Posted March 27, 2013 This should work : -- Client : addEvent ( 'sound', true ) addEventHandler ( 'sound', root, function ( ) local song = playSound3D("Diskoparty.mp3", -2758, 968, 54, true) setSoundVolume ( song, 100 ) setSoundMinDistance ( song, 100 ) outputChatBox(":D") end ) -- Server : addEventHandler ( 'onResourceStart', resourceRoot, function ( player ) local x, y, z = getElementPosition ( player ) triggerClientEvent ( 'sound', player, x, y, z ) end ) Link to comment
Rotti Posted March 27, 2013 Author Share Posted March 27, 2013 Ok I just wanted to do it this way, because i'm using it with a vehicle: --Serverside function movesong() x,y,z = getElementPosition(Partybus) triggerClientEvent("song", getRootElement(),x,y,z) end setTimer(movesong, 50, 0) --Clientside function move(posX,posY,posZ) setElementPosition(song, posX,posY,posZ) end addEventHandler("song", root, move) addEvent("song",true) But that didn't work... Link to comment
PaiN^ Posted March 27, 2013 Share Posted March 27, 2013 Will if you want the sound to be in the vehicle, Use attachElements .. Link to comment
Rotti Posted March 27, 2013 Author Share Posted March 27, 2013 But how? the sound is clientside and the vehicle serverside Link to comment
ZL|LuCaS Posted March 27, 2013 Share Posted March 27, 2013 But how? the sound is clientside and the vehicle serverside please explain better what you want to do? Link to comment
Rotti Posted March 27, 2013 Author Share Posted March 27, 2013 I want to do the same as #Pai_[N] said: attach the sound to the vehicle with attechElements Link to comment
Sasu Posted March 27, 2013 Share Posted March 27, 2013 Try this: -- Client : addEvent ( 'sound', true ) addEventHandler ( 'sound', root, function ( ) if getPedOccupiedVehicle(localPlayer) then local x,y,z = getElementPosition(localPlayer) local song = playSound3D("Diskoparty.mp3", x, y, z, true) attachElements ( sound, localPlayer, 0, 0, 5 ) setSoundVolume ( song, 100 ) setSoundMinDistance ( song, 100 ) outputChatBox(":D") end end ) function stop() stopSound(song) end addEvent('stop', true) addEventHandler('stop', root, stop) -- Server : addEventHandler ( 'onVehicleEnter', resourceRoot, function ( ) triggerClientEvent ( 'sound', source ) end ) addEventHandler( 'onVehicleExit', resourceRoot, function () triggerClientEvent ( 'stop', source) end ) Link to comment
denny199 Posted March 28, 2013 Share Posted March 28, 2013 I recommend to search here: https://community.multitheftauto.com/in ... =resources Link to comment
Rotti Posted March 28, 2013 Author Share Posted March 28, 2013 But... thats not what i want sorry, I want the sound to be everytime attached on the vehicle which was created serverside. The vehicle is defined as "Partybus". As i said maybe it will work with setElementPosition and getElementPosition Ok i think you can help me better now Link to comment
denny199 Posted March 28, 2013 Share Posted March 28, 2013 Can you show me your part that creates the "partybus" because then We/I can edit it. Link to comment
Rotti Posted March 28, 2013 Author Share Posted March 28, 2013 ---------------- ----Partybus---- ---------------- Partybus = createVehicle ( 437, -2755, 958, 54.3, 0, 0, 0, "Party" ) Partylaser1 = createObject( 18102, -2755, 958, 56.3) Speaker1 = createObject( 1840, -2755, 958, 57.3) Speaker2 = createObject( 1840, -2755, 958, 57.3) Speaker3 = createObject( 1840, -2755, 958, 57.3) Speaker4 = createObject( 1840, -2755, 958, 57.3) attachElements(Speaker1, Partybus, -1, 4, 2) attachElements(Speaker2, Partybus, 1, 4, 2, 0, 0, 180) attachElements(Speaker3, Partybus, -1, -4, 2) attachElements(Speaker4, Partybus, 1, -4, 2, 0, 0, 180) attachElements(Partylaser1, Partybus, 1, 3.5, 0.7, 40, 0, 90) There is no function Link to comment
denny199 Posted March 28, 2013 Share Posted March 28, 2013 Client side: addEvent ( 'startsound', true ) addEventHandler ( 'startsound', root, function ( ) if not ( isElement ( sound ) ) then pl = getLocalPlayer() auto = getPedOccupiedVehicle(pl) sound = playSound3D("Diskoparty.mp3", 0, 0, 0, true) attachElements ( sound, auto, 0, 0, 1 ) setSoundVolume ( sound, 100 ) setSoundMinDistance ( sound, 100 ) end end ) addEvent ( 'stopsound', true ) addEventHandler ( 'stopsound', root, function ( ) if ( isElement ( sound ) ) then destroyElement ( sound ) end end) Server Side: Partybus = createVehicle ( 437, -2755, 958, 54.3, 0, 0, 0, "Party" ) Partylaser1 = createObject( 18102, -2755, 958, 56.3) Speaker1 = createObject( 1840, -2755, 958, 57.3) Speaker2 = createObject( 1840, -2755, 958, 57.3) Speaker3 = createObject( 1840, -2755, 958, 57.3) Speaker4 = createObject( 1840, -2755, 958, 57.3) attachElements(Speaker1, Partybus, -1, 4, 2) attachElements(Speaker2, Partybus, 1, 4, 2, 0, 0, 180) attachElements(Speaker3, Partybus, -1, -4, 2) attachElements(Speaker4, Partybus, 1, -4, 2, 0, 0, 180) attachElements(Partylaser1, Partybus, 1, 3.5, 0.7, 40, 0, 90) addEventHandler ( 'onVehicleEnter', Partybus, function (thePlayer) triggerClientEvent ( 'startsound', root ) end ) addEventHandler( 'onVehicleExit', Partybus, function (thePlayer) triggerClientEvent ( 'stopsound', root) end ) Link to comment
Rotti Posted March 28, 2013 Author Share Posted March 28, 2013 not everybody hears the sound #Edit ok we are very close to solve the problem. I have changed your code a bit: Partybus = createVehicle ( 437, -2755, 958, 54.3, 0, 0, 0, "Party" ) Partylaser1 = createObject( 18102, -2755, 958, 56.3) Speaker1 = createObject( 1840, -2755, 958, 57.3) Speaker2 = createObject( 1840, -2755, 958, 57.3) Speaker3 = createObject( 1840, -2755, 958, 57.3) Speaker4 = createObject( 1840, -2755, 958, 57.3) attachElements(Speaker1, Partybus, -1, 4, 2) attachElements(Speaker2, Partybus, 1, 4, 2, 0, 0, 180) attachElements(Speaker3, Partybus, -1, -4, 2) attachElements(Speaker4, Partybus, 1, -4, 2, 0, 0, 180) attachElements(Partylaser1, Partybus, 1, 3.5, 0.7, 40, 0, 90) addEventHandler ( 'onVehicleEnter', Partybus, function (thePlayer) triggerClientEvent ( 'startsound', root ) end ) addEventHandler( 'onClientResourceStart', resourceRoot, function() song = playSound3D("Diskoparty.mp3", -2758, 968, 54, true) setSoundVolume ( song, 100 ) setSoundMinDistance ( song, 100 ) outputChatBox(":D") end ) addEvent ( 'startsound', true ) addEventHandler ( 'startsound', root, function ( ) if not ( isElement ( sound ) ) then pl = getLocalPlayer() auto = getPedOccupiedVehicle(pl) attachElements(song, auto) end end ) But only the players who have entered the vehicle can hear the sound. Link to comment
ZL|LuCaS Posted April 3, 2013 Share Posted April 3, 2013 not everybody hears the sound#Edit ok we are very close to solve the problem. I have changed your code a bit: Partybus = createVehicle ( 437, -2755, 958, 54.3, 0, 0, 0, "Party" ) Partylaser1 = createObject( 18102, -2755, 958, 56.3) Speaker1 = createObject( 1840, -2755, 958, 57.3) Speaker2 = createObject( 1840, -2755, 958, 57.3) Speaker3 = createObject( 1840, -2755, 958, 57.3) Speaker4 = createObject( 1840, -2755, 958, 57.3) attachElements(Speaker1, Partybus, -1, 4, 2) attachElements(Speaker2, Partybus, 1, 4, 2, 0, 0, 180) attachElements(Speaker3, Partybus, -1, -4, 2) attachElements(Speaker4, Partybus, 1, -4, 2, 0, 0, 180) attachElements(Partylaser1, Partybus, 1, 3.5, 0.7, 40, 0, 90) addEventHandler ( 'onVehicleEnter', Partybus, function (thePlayer) triggerClientEvent ( 'startsound', root ) end ) addEventHandler( 'onClientResourceStart', resourceRoot, function() song = playSound3D("Diskoparty.mp3", -2758, 968, 54, true) setSoundVolume ( song, 100 ) setSoundMinDistance ( song, 100 ) outputChatBox(":D") end ) addEvent ( 'startsound', true ) addEventHandler ( 'startsound', root, function ( ) if not ( isElement ( sound ) ) then pl = getLocalPlayer() auto = getPedOccupiedVehicle(pl) attachElements(song, auto) end end ) But only the players who have entered the vehicle can hear the sound. the sound triggered when the player enters the vehicle. onVehicleEnter you need something like createMarker around the vehicle. 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