Jump to content

playSound3D synced for every player


Mimimiguel

Recommended Posts

Posted

To be clear, you want to create a sound in GTA world or doesnt it matter were the sound's located? If you really want to use 3D ( compare: https://wiki.multitheftauto.com/wiki/PlaySound3D , https://wiki.multitheftauto.com/wiki/PlaySound ) then create it for every player, everything you create client-side is only for the client your executing it "at". So only he/she will notice something created. Creating for everyone: trigger a client event for all players. If you reply, i'll go more detailed.

Posted

Yes, please, i think i take the idea but im not sure of how can i create a sound for everyone in clientside starting of a gui event. The idea its to use the playSound3D function, so when another player gets nearly the sound he can hear it.

Posted

client:

addEvent ( "playSoundForAllPlayers" , true) 
addEventHandler("playSoundForAllPlayers", root, 
function() 
playSound3D(...) 
end) 

And in server, use this whenever you want to play the sound.

triggerClientEvent("playSoundForAllPlayers", root) 

Posted

Well, the sync worked fine but I had another bug that i still couldnt solve:

  
sound = {} 
addEvent( "playsound", true ) 
addEventHandler( "playsound", getRootElement(), function( veh, sound, player ) 
    if getElementData( player, "radio" ) == false then 
    x, y, z = getElementPosition( veh ) 
    sound[ player ] = playSound3D( sound, x, y, z, false ) 
    setTimer( actualizarPosicionSonido, 50, 0, sound, veh ) 
    setSoundMaxDistance( sound, maxdistance ) 
    setElementData( player, "radio", true ) 
    else 
    stopSound( sound[ player ] ) 
    sound[ player ] = nil 
    setElementData( player, "radio", false ) 
    end 
end 
) 
  
  

Returns: Attempt to index local 'sound' ( a string value )

Posted
playSound3D( sound, x, y, z, false ) 

sound should be a table, and your using it in playSound3D, and you defined it as string before.

Edit playSound3D and replace sound with the file path.

Posted
playSound3D( sound, x, y, z, false ) 

sound should be a table, and your using it in playSound3D, and you defined it as string before.

Edit playSound3D and replace sound with the file path.

So instead of playSound3D( sound, x, y, z, false ) it should be for example playSound3D( "sound.mp3", x, y, z, false) ?

Posted

Yes.

And if there is any local sound exept sound = {} remove it

also

setSoundMaxDistance( sound, maxdistance ) 

should be:

setSoundMaxDistance( sound [ player ], maxdistance ) 

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