Jump to content

[help] playSound3D problem


skaruharu

Recommended Posts

Hello!

My problem is when i klick on the hardstyle button then i can hear the music but my friend cant hear it when im going close to him..

So any idea? :/

Client:

	addEventHandler("onClientResourceStart", root,
function ()
mywindow = guiCreateWindow(681, 407, 378, 372, "Radio", false)
guiWindowSetSizable(mywindow, false)
	hardstyleB = guiCreateButton(16, 31, 103, 43, "Hardstyle", false, mywindow )
closeB = guiCreateButton(144, 330, 94, 32, "Close", false, mywindow )
	addEventHandler("onClientGUIClick", closeB, closewindow, false)
addEventHandler("onClientGUIClick", hardstyleB, theradio, false)  
	guiSetVisible(mywindow,false)
	end)
	 
	function theradio ()
    local x, y, z = getElementPosition(getLocalPlayer())
    local int = getElementInterior(getLocalPlayer())
    local dim = getElementDimension(getLocalPlayer())
    local px, py, pz = getElementPosition(getLocalPlayer()) 
    if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
    local hardstylee = playSound3D("http://listen.hardstyle.nu/listen.pls", x, y, z) 
    setSoundMaxDistance(hardstylee, 40) 
    setElementDimension(hardstylee, dim) 
    setElementInterior(hardstylee, int) 
    attachElements ( hardstylee, localPlayer)                    
      end        
end    
	
Edited by skaruharu
Link to comment
	addEventHandler("onClientResourceStart", root,
function ()
mywindow = guiCreateWindow(681, 407, 378, 372, "Radio", false)
guiWindowSetSizable(mywindow, false)
	hardstyleB = guiCreateButton(16, 31, 103, 43, "Hardstyle", false, mywindow )
closeB = guiCreateButton(144, 330, 94, 32, "Close", false, mywindow )
	addEventHandler("onClientGUIClick", closeB, closewindow, false)
addEventHandler("onClientGUIClick", hardstyleB, theradio, false)  
	guiSetVisible(mywindow,false)
	end)
	 
	function theradio ()
    local x, y, z = getElementPosition(getLocalPlayer())
    local int = getElementInterior(getLocalPlayer())
    local dim = getElementDimension(getLocalPlayer())
    for i, player in ipairs(getElementsByType("player")) do
    local px, py, pz = getElementPosition(player)
    if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
    local hardstylee = playSound3D("http://listen.hardstyle.nu/listen.pls", x, y, z) 
    setSoundMaxDistance(hardstylee, 40) 
    setElementDimension(hardstylee, dim) 
    setElementInterior(hardstylee, int) 
    attachElements ( hardstylee, localPlayer)                    
      end
    end
end    
	

 

Link to comment
	addEventHandler("onClientResourceStart", root,
function ()
mywindow = guiCreateWindow(681, 407, 378, 372, "Radio", false)
guiWindowSetSizable(mywindow, false)
	hardstyleB = guiCreateButton(16, 31, 103, 43, "Hardstyle", false, mywindow )
closeB = guiCreateButton(144, 330, 94, 32, "Close", false, mywindow )
	addEventHandler("onClientGUIClick", closeB, closewindow, false)
addEventHandler("onClientGUIClick", hardstyleB, theradio, false)  
	guiSetVisible(mywindow,false)
	end)
function theradio ()
  if source == hardstuleB then
    
    local x, y, z = getElementPosition(localPlayer)
    for _, v in ipairs(getElementsByType("player")) do
    local px, py, pz = getElementPosition(v)
    if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
    local hardstylee = playSound3D("http://listen.hardstyle.nu/listen.pls", x, y, z) 
    setSoundMaxDistance(hardstylee, 40)                     
      end
      end
    end
end    
	

 

Link to comment

if you are casting the sound then use root, you don't need to loop the sound to every player. Simply replace the entire loop with local hardstylee = playSound("link")

It will cast to everyone so long as you don't run it in an event where the player is defined, or run it in a command.

Also using it in a gui will cast it to only the player opening the gui.

Link to comment

Thx Dimos but the code is not working..

If i do it with command in server side and trigger it then it works. But if i do it in client side with button then it doesnt work. It works when i use addEventHandler inside the gui but only me can hear.. So i have no idea how i can get it root because when i add the addEventHandler outside the gui i only get errors..

Link to comment

Denny if i understood you right i made this..

But still not working

 

client:

[lua]

function theradio () 
    local x, y, z = getElementPosition(getLocalPlayer())
    local int = getElementInterior(getLocalPlayer())
    local dim = getElementDimension(getLocalPlayer())
    local px, py, pz = getElementPosition(getLocalPlayer())    
    if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then
    triggerServerEvent("onRadio", root, localPlayer)    
    local hardstylee = playSound3D("http://listen.hardstyle.nu/listen.pls", x, y, z) 
    setSoundMaxDistance(hardstylee, 40) 
    setElementDimension(hardstylee, dim) 
    setElementInterior(hardstylee, int) 
    attachElements ( hardstylee, localPlayer)    
    end
end

[/lua]

 

server:

	function myradio (player)
   outputChatBox("Radio is now playing!", player, 255, 0, 0)
end
addEvent("onRadio", true)
addEventHandler("onRadio", root, myradio)
	
Edited by skaruharu
Link to comment
addEventHandler("onClientResourceStart", root, function()
	mywindow = guiCreateWindow(681, 407, 378, 372, "Radio", false)
	guiWindowSetSizable(mywindow, false)
	
	hardstyleB = guiCreateButton(16, 31, 103, 43, "Hardstyle", false, mywindow )
	closeB = guiCreateButton(144, 330, 94, 32, "Close", false, mywindow )
	
	addEventHandler("onClientGUIClick", closeB, closewindow, false)
	addEventHandler("onClientGUIClick", hardstyleB, theradio, false)  
	
	guiSetVisible(mywindow,false)
end)
	
-- Your onclick button trigger
function theradio ()
	if (source == hardstyleB) then
		triggerServerEvent("onRadio", resourceRoot, localPlayer)
    end
end    

local hardstyle
-- Make a new 3D sound
function startClientRadio(x,y,z, player)
    -- destroy the last sound if exist
	if (isElement(hardstyle)) 
    	destroyElement(hardstyle)
    end
    hardstyle = playSound3D("http://listen.hardstyle.nu/listen.pls", x, y, z) 
    setSoundMaxDistance(hardstyle, 40)
    attachElements(hardstyle, player);
end
addEvent("startClientRadio", true)
addEventHandler("startClientRadio", root, startClientRadio)



Server:
 

-- Start the radio for everyone
function startRadio (player)
  local radioX, radioY, radioZ = getElementPosition(player)
	outputChatBox("Radio is now playing!", player, 255, 0, 0)
	triggerClientEvent(root, "startClientRadio", root, radioX, radioY, radioZ, player)
end
addEvent("onRadio", true)
addEventHandler("onRadio", root, startRadio)

Note: newly joined players are not hearing the sound

Edited by denny199
Better lua code - Whoops didnt program lua for 1 year
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...