Jump to content

setSoundMaxDistance Problem


Tony Brand

Recommended Posts

Posted

Hi, i made a function called syncSong

it works like this:

 

addEvent("syncSong", true)
addEventHandler("syncSong", root,
	function( )
		local song = playSound("data/sound.mp3", false)
		setSoundVolume(song, 0.9)
		setSoundMaxDistance(song, 2)
	end)

as you see i setSoundMaxDistance(song, 2) so now sound must be played in a short range!but problem is when players use that command thats trigger this event,sound plays for whole server in every place!
also here is the CommandHandler
 

addCommandHandler( "alarm",
	triggerClientEvent("syncSong", getRootElement())
	etc(another codes under this line...)


 

Posted
46 minutes ago, Tony Brand said:

so it must change to
 


local song = playSound3D("data/sound.mp3", false)

 

Check the arguments on the wiki... you have to specify the X, Y and Z co-ordinates.

Posted
1 minute ago, MIKI785 said:

Check the arguments on the wiki... you have to specify the X, Y and Z co-ordinates.

yes i saw it, i need to get player x y z ! can you help me?

Posted
addEvent("syncSong", true)
addEventHandler("syncSong", root,
	function( )
		local x,y,z = getElementPosition(  )
		local song = playSound3D("data/sound.mp3", x, y, z, false)
		setSoundVolume(song, 0.9)
		setSoundMaxDistance( song, 100 )
	end)

where i did wrong?

Posted
addEvent("syncSong", true)
addEventHandler("syncSong", root,
	function( )
		local x,y,z = getElementPosition(localPlayer)
		local song = playSound3D("data/sound.mp3", x, y, z, false)
		setSoundVolume(song, 0.9)
		setSoundMaxDistance( song, 100 )
	end)

 

Posted
5 minutes ago, Dimos7 said:

addEvent("syncSong", true)
addEventHandler("syncSong", root,
	function( )
		local x,y,z = getElementPosition(localPlayer)
		local song = playSound3D("data/sound.mp3", x, y, z, false)
		setSoundVolume(song, 0.9)
		setSoundMaxDistance( song, 100 )
	end)

 

it has no error but again whole the server can hear the sound :(

Posted (edited)
local x,y,z = getElementPosition(source)

And make sure when you trigger that event on the server, that the source of the event is the player who played the song. I.e.

triggerClientEvent(root, "syncSong",         thePlayerWhoPlayedTheSong)
--                 ^ who will hear the song  ^ event source

 

Edited by MrTasty
  • Like 1
Posted
5 minutes ago, MrTasty said:

local x,y,z = getElementPosition(source)

And make sure when you trigger that event on the server, that the source of the event is the player who played the song. I.e.


triggerClientEvent(root, "syncSong", thePlayerWhoPlayedTheSong)

 

tnx ❤️ fixed

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