skaruharu Posted January 24, 2017 Posted January 24, 2017 (edited) 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 January 24, 2017 by skaruharu
Dimos7 Posted January 24, 2017 Posted January 24, 2017 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
skaruharu Posted January 24, 2017 Author Posted January 24, 2017 Sorry but my friend can still not hear me play any music when i go close to him
Dimos7 Posted January 24, 2017 Posted January 24, 2017 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
ShayF2 Posted January 24, 2017 Posted January 24, 2017 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.
skaruharu Posted January 25, 2017 Author Posted January 25, 2017 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..
denny199 Posted January 25, 2017 Posted January 25, 2017 You need to make a trigger to the server to sync it with all the players. https://wiki.multitheftauto.com/wiki/TriggerServerEventhttps://wiki.multitheftauto.com/wiki/TriggerClientEvent Flow: Click on button -> Make call to server -> Server makes call to the client to play the hardstyle stream. (Nice music taste btw)
skaruharu Posted January 26, 2017 Author Posted January 26, 2017 (edited) 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 January 26, 2017 by skaruharu
denny199 Posted January 26, 2017 Posted January 26, 2017 (edited) 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 January 26, 2017 by denny199 Better lua code - Whoops didnt program lua for 1 year
skaruharu Posted January 26, 2017 Author Posted January 26, 2017 Oh i see.. Thanks alot for the help!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now