Tokio Posted March 23, 2019 Posted March 23, 2019 This is the code: requestBrowserDomains({"www.convertmp3.io"}) local browser = createBrowser( 0, 0, false ) local currentSound = {} function start(_,link) fetch(link) end addCommandHandler("play",start) function fetch(url) if (url) then fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback) end end function callback(data, error) if (error ~= 0) then return outputChatBox(error) end if (data == "ERROR") then return outputChatBox("data error") end local data = fromJSON("["..data.."]") if (data) then outputChatBox("Title: "..data.title) outputChatBox("Length: "..data.length) outputChatBox("Link: "..data.link) loadBrowserURL( browser, data.link ) end end addEventHandler( "onClientBrowserNavigate", browser, function( link ) if not link:find("www.convertmp3.io") then local vehicle = getPedOccupiedVehicle ( localPlayer ) local x, y, z = getElementPosition(vehicle) currentSound[localPlayer] = playSound3D( link, x, y, z ) attachElements(currentSound[localPlayer],vehicle) setSoundMaxDistance(currentSound[localPlayer],30) setSoundVolume(currentSound[localPlayer],50) end end ) How to synchronise to all players? My servers: Fun: Derby(DD):
Sorata_Kanda Posted March 23, 2019 Posted March 23, 2019 You could create a server event that includes a loop where it triggers a client event playing the sound file for each player.
Tokio Posted March 23, 2019 Author Posted March 23, 2019 2 minutes ago, Sorata_Kanda said: You could create a server event that includes a loop where it triggers a client event playing the sound file for each player. I tried with server trigger, but then play the sound for every players vehicle.. My servers: Fun: Derby(DD):
Tokio Posted March 23, 2019 Author Posted March 23, 2019 Anyone can help? My servers: Fun: Derby(DD):
KillerX Posted March 24, 2019 Posted March 24, 2019 Try -- Client -- function start (_ , link ) triggerServerEvent( 'play' , localPlayer , link ) end addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) fetch( link ) end ) -- Server -- addEvent( 'play' , true ) addEventHandler( 'play' , root , function( link ) triggerClientEvent( root , 'Play' , client , link ) end ) هل ساعدتك في شئ ؟؟؟؟ KillerX#9078
Tokio Posted March 24, 2019 Author Posted March 24, 2019 10 hours ago, KillerX said: Try -- Client -- function start (_ , link ) triggerServerEvent( 'play' , localPlayer , link ) end addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) fetch( link ) end ) -- Server -- addEvent( 'play' , true ) addEventHandler( 'play' , root , function( link ) triggerClientEvent( root , 'Play' , client , link ) end ) When i play the music, the song start in every players vehicle too.. :s And when i play music in my car, then it is not heard by others My servers: Fun: Derby(DD):
Mr.Loki Posted March 24, 2019 Posted March 24, 2019 Post the changes you made using the triggers. you are probably using localPlayer and not source from the play event [REL]Cinema Experience Beta 2.0 [TUT]Object offsets with OOP. [TUT] Adding a Discord bot to your server. Discord: Loki#7355
Tokio Posted March 24, 2019 Author Posted March 24, 2019 1 minute ago, Mr.Loki said: Post the changes you made using the triggers. you are probably using localPlayer and not source from the play event Client side: requestBrowserDomains({"www.convertmp3.io"}) local browser = createBrowser( 0, 0, false ) local currentSound = {} function start (_ , link ) triggerServerEvent( 'play' , localPlayer , link ) end addCommandHandler("p",start) addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) fetch( link ) end ) function fetch(url) if (url) then fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback) end end function callback(data, error) if (error ~= 0) then return outputChatBox(error) end if (data == "ERROR") then return outputChatBox("data error") end local data = fromJSON("["..data.."]") if (data) then outputChatBox("Title: "..data.title) outputChatBox("Length: "..data.length) outputChatBox("Link: "..data.link) loadBrowserURL( browser, data.link ) end end addEventHandler( "onClientBrowserNavigate", browser, function( link ) if not link:find("www.convertmp3.io") then local vehicle = getPedOccupiedVehicle ( localPlayer ) local x, y, z = getElementPosition(vehicle) currentSound[localPlayer] = playSound3D( link, x, y, z ) attachElements(currentSound[localPlayer],vehicle) setSoundMaxDistance(currentSound[localPlayer],30) setSoundVolume(currentSound[localPlayer],50) end end ) Server side: addEvent( 'play' , true ) addEventHandler( 'play' , root , function( link ) triggerClientEvent( root , 'Play' , client , link ) end ) My servers: Fun: Derby(DD):
Mr.Loki Posted March 24, 2019 Posted March 24, 2019 requestBrowserDomains({"www.convertmp3.io"}) local browser = createBrowser( 1, 1, false ) local currentSound = {} addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) local vehicle = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition(vehicle) currentSound[source] = playSound3D( link, x, y, z ) attachElements(currentSound[source],vehicle) setSoundMaxDistance(currentSound[source],30) setSoundVolume(currentSound[source],50) end ) function fetch(_,url) if url and url ~= "" then fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback) end end addCommandHandler("p",fetch) function callback(data, error) if (error ~= 0) then return outputChatBox(error) end if (data == "ERROR") then return outputChatBox("data error") end local data = fromJSON("["..data.."]") if (data) then outputChatBox("Title: "..data.title) outputChatBox("Length: "..data.length) outputChatBox("Link: "..data.link) loadBrowserURL( browser, data.link ) end end addEventHandler( "onClientBrowserNavigate", browser, function( link ) if not link:find("www.convertmp3.io") then triggerServerEvent( 'play' , localPlayer , link ) -- trigger the event when the script actially gets the playable link! end end ) 1 [REL]Cinema Experience Beta 2.0 [TUT]Object offsets with OOP. [TUT] Adding a Discord bot to your server. Discord: Loki#7355
Tokio Posted March 24, 2019 Author Posted March 24, 2019 6 minutes ago, Mr.Loki said: requestBrowserDomains({"www.convertmp3.io"}) local browser = createBrowser( 1, 1, false ) local currentSound = {} addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) local vehicle = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition(vehicle) currentSound[source] = playSound3D( link, x, y, z ) attachElements(currentSound[source],vehicle) setSoundMaxDistance(currentSound[source],30) setSoundVolume(currentSound[source],50) end ) function fetch(_,url) if url and url ~= "" then fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback) end end addCommandHandler("p",fetch) function callback(data, error) if (error ~= 0) then return outputChatBox(error) end if (data == "ERROR") then return outputChatBox("data error") end local data = fromJSON("["..data.."]") if (data) then outputChatBox("Title: "..data.title) outputChatBox("Length: "..data.length) outputChatBox("Link: "..data.link) loadBrowserURL( browser, data.link ) end end addEventHandler( "onClientBrowserNavigate", browser, function( link ) if not link:find("www.convertmp3.io") then triggerServerEvent( 'play' , localPlayer , link ) -- trigger the event when the script actially gets the playable link! end end ) Thank you! My servers: Fun: Derby(DD):
Tokio Posted March 24, 2019 Author Posted March 24, 2019 50 minutes ago, Mr.Loki said: requestBrowserDomains({"www.convertmp3.io"}) local browser = createBrowser( 1, 1, false ) local currentSound = {} addEvent( 'Play' , true ) addEventHandler( 'Play' , root , function( link ) local vehicle = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition(vehicle) currentSound[source] = playSound3D( link, x, y, z ) attachElements(currentSound[source],vehicle) setSoundMaxDistance(currentSound[source],30) setSoundVolume(currentSound[source],50) end ) function fetch(_,url) if url and url ~= "" then fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback) end end addCommandHandler("p",fetch) function callback(data, error) if (error ~= 0) then return outputChatBox(error) end if (data == "ERROR") then return outputChatBox("data error") end local data = fromJSON("["..data.."]") if (data) then outputChatBox("Title: "..data.title) outputChatBox("Length: "..data.length) outputChatBox("Link: "..data.link) loadBrowserURL( browser, data.link ) end end addEventHandler( "onClientBrowserNavigate", browser, function( link ) if not link:find("www.convertmp3.io") then triggerServerEvent( 'play' , localPlayer , link ) -- trigger the event when the script actially gets the playable link! end end ) But why not remove the music, when player quit? Client: addEvent( 'Stop' , true ) addEventHandler( 'Stop' , root , function() local vehicle = getPedOccupiedVehicle ( source ) destroyElement(currentSound[source]) detachElements ( currentSound[source], vehicle ) end ) Server: function quitPlayer () triggerClientEvent( root , 'Stop' , client ) end addEventHandler ( "onPlayerQuit", root, quitPlayer ) My servers: Fun: Derby(DD):
Mr.Loki Posted March 24, 2019 Posted March 24, 2019 client is only predefined when calling a custom event from the client. Change it to source. Also you are destroying the element before detaching it which will cause an error. 1 [REL]Cinema Experience Beta 2.0 [TUT]Object offsets with OOP. [TUT] Adding a Discord bot to your server. Discord: Loki#7355
Tokio Posted March 24, 2019 Author Posted March 24, 2019 3 minutes ago, Mr.Loki said: client is only predefined when calling a custom event from the client. Change it to source. Also you are destroying the element before detaching it which will cause an error. thanks My servers: Fun: Derby(DD):
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