[M]ister Posted December 11, 2013 Share Posted December 11, 2013 Hello I want to create a table with musics, When a song ends, another begins, but I do not know how I could be doing this, I created the following script below (don't work) local randoms = { 'http://1in.kz/s/music/1313125085_one-direction-what-makes-you-beautiful.mp3', 'http://promodj.com/source/3080390/Eiffel_65_Blue_DJ_Pasha_Lee_DJ_Vitaco_remix.mp3' } function setRandomMusic () local theSound = randoms[math.random(#randoms)] end setTimer(setRandomMusic, 10000, 1) function setMusicPlay () local sound = playSound3D(theSound, -2631, 1377, 7, true) setSoundVolume(sound, 1.0) setSoundMaxDistance(sound, 50) end addEventHandler( "onClientResourceStart", getRootElement( ), setMusicPlay) Link to comment
TAPL Posted December 11, 2013 Share Posted December 11, 2013 local randoms = { 'http://1in.kz/s/music/1313125085_one-direction-what-makes-you-beautiful.mp3', 'http://promodj.com/source/3080390/Eiffel_65_Blue_DJ_Pasha_Lee_DJ_Vitaco_remix.mp3' } function setRandomMusic() if isElement(sound) then destroyElement(sound) end sound = playSound3D(randoms[math.random(#randoms)], -2631, 1377, 7, true) setSoundVolume(sound, 1.0) setSoundMaxDistance(sound, 50) end setTimer(setRandomMusic, 10000, 1) addEventHandler("onClientResourceStart", resourceRoot, setRandomMusic) Link to comment
[M]ister Posted December 11, 2013 Author Share Posted December 11, 2013 (edited) thanks very much, is working . Do you know if there is any way to find out if a song ends to get another? Edited December 11, 2013 by Guest Link to comment
TAPL Posted December 11, 2013 Share Posted December 11, 2013 Not sure what you mean. Maybe this? https://wiki.multitheftauto.com/wiki/OnClientSoundStopped Edit: Maybe you mean the timer? Change 1 to 0 for infinite repetitions. Link to comment
Desaster Posted December 11, 2013 Share Posted December 11, 2013 use a web radio link like 181-power Link to comment
[M]ister Posted December 11, 2013 Author Share Posted December 11, 2013 I prefer to use only the songs that I like. Is there any way to play the songs one after another, without being randomly? Link to comment
TAPL Posted December 11, 2013 Share Posted December 11, 2013 Try this: local randoms = { 'http://1in.kz/s/music/1313125085_one-direction-what-makes-you-beautiful.mp3', 'http://promodj.com/source/3080390/Eiffel_65_Blue_DJ_Pasha_Lee_DJ_Vitaco_remix.mp3' } function setRandomMusic() if isElement(sound) then destroyElement(sound) end index = #randoms > (index or 0) and (index or 0) + 1 or 1 sound = playSound3D(randoms[index], -2631, 1377, 7, true) setSoundVolume(sound, 1.0) setSoundMaxDistance(sound, 50) end addEventHandler("onClientResourceStart", resourceRoot, setRandomMusic) addEventHandler("onClientSoundStream", root, function(suc, length) if suc and length > 0 then setTimer(setRandomMusic, length*1000, 1) else setRandomMusic() end end) Link to comment
[M]ister Posted December 12, 2013 Author Share Posted December 12, 2013 Thanks TAPL, is working the way I wanted! Link to comment
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