Jump to content

PlaySound3D


Rotti

Recommended Posts

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

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

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

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

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

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

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