Jump to content

How can I sync attached play3DSound?


Recommended Posts

Code:

CLIENT:

triggerServerEvent("musics", root)

SERVER:

addEvent("musics", true)
addEventHandler("musics", root, function()
    triggerClientEvent("music", root)
end)

CLIENT:

(...)
addEvent("music", true)
addEventHandler("music", root, function()
local url = guiGetText(edit)
sound = playSound3D(tostring(url), x, y, z, true)
setSoundMaxDistance(sound, 100)
exports.bone_attach:attachElementToBone(sound, player, 11, 0, 0, 0.4, 180)
(...)

after calling this code, play3DSound can be heard only by the person who called it. Please help to me.

Link to comment
  • Moderators
55 minutes ago, NoviceWithManyProblems said:

after calling this code, play3DSound can be heard only by the person who called it.

 

local url = guiGetText(edit)
triggerServerEvent("musics", resourceRoot, localPlayer, url )

 

addEvent("musics", true)
addEventHandler("musics", resourceRoot, function(player, ...)
	if isElement(player) then
		triggerClientEvent("music", resourceRoot, player, ...) -- send to all players
	end
end, false)

 

addEvent("music", true)
addEventHandler("music", resourceRoot, function(player, url)
	if isElement(player) then
		local x,y,z = getElementPosition(player)
		local sound = playSound3D(tostring(url), x, y, z, true)
		setSoundMaxDistance(sound, 100)
		exports.bone_attach:attachElementToBone(sound, player, 11, 0, 0, 0.4, 180)

      --[[ ... ]]

 

 

 

Link to comment
  • Scripting Moderators
58 minutes ago, NoviceWithManyProblems said:

Code:

CLIENT:


triggerServerEvent("musics", root)

SERVER:


addEvent("musics", true)
addEventHandler("musics", root, function()
    triggerClientEvent("music", root)
end)

CLIENT:


(...)
addEvent("music", true)
addEventHandler("music", root, function()
local url = guiGetText(edit)
sound = playSound3D(tostring(url), x, y, z, true)
setSoundMaxDistance(sound, 100)
exports.bone_attach:attachElementToBone(sound, player, 11, 0, 0, 0.4, 180)
(...)

after calling this code, play3DSound can be heard only by the person who called it. Please help to me.

By the way there's no need to attach sound by using bone attach.

You can use attachElements instead - https://wiki.multitheftauto.com/wiki/AttachElements

Link to comment
2 hours ago, IIYAMA said:

 


local url = guiGetText(edit)
triggerServerEvent("musics", resourceRoot, localPlayer, url )

 


addEvent("musics", true)
addEventHandler("musics", resourceRoot, function(player, ...)
	if isElement(player) then
		triggerClientEvent("music", resourceRoot, player, ...) -- send to all players
	end
end, false)

 


addEvent("music", true)
addEventHandler("music", resourceRoot, function(player, url)
	if isElement(player) then
		local x,y,z = getElementPosition(player)
		local sound = playSound3D(tostring(url), x, y, z, true)
		setSoundMaxDistance(sound, 100)
		exports.bone_attach:attachElementToBone(sound, player, 11, 0, 0, 0.4, 180)

      --[[ ... ]]

 

 

 

I did it 1: 1 as you specified, checked from another computer, the same does not work, someone play something - I can't hear, I play something - he can't hear

Link to comment
  • Moderators
56 minutes ago, NoviceWithManyProblems said:

@IIYAMA do you need more informations? please help to me.

Add some more debug lines to the code.

1. So that it is clear which code is running and which code doesn't.

2. Also inspect some of the variable so that we don't have to gamble what values are used.

If you give me enough of that, then yes I will be able to help you better.

Link to comment
17 hours ago, stPatrick said:

guiGetText(edit)

returns valid data?

yes, music start play correctly but only person who start this can hear music.

 

16 hours ago, IIYAMA said:

Add some more debug lines to the code.

1. So that it is clear which code is running and which code doesn't.

2. Also inspect some of the variable so that we don't have to gamble what values are used.

If you give me enough of that, then yes I will be able to help you better.

All works good, no problems in DB3 - music play correctly but I one person who can hear this music  I want everyone to hear her

Link to comment
  • Moderators
18 minutes ago, NoviceWithManyProblems said:

All works good, no problems in DB3 - music play correctly but I one person who can hear this music  I want everyone to hear her

That is already added.

If that is not happening, then you will have to follow my instructions in my previous reply.

Which should contain a copy of the new code with debug lines + results.

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