Eht1 Posted December 18, 2011 Posted December 18, 2011 I Try create music script, when you join then need play random music on internet all time when you play game. I try with this but not work. function addSound ( link ) addSound ( "http://www.mysound1.com/sound1" ) addSound ( "http://www.mysound1.com/sound2" ) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() playSound(sounds[math.random(1, addSound)]) end ) Link is not real this is for example.
novo Posted December 18, 2011 Posted December 18, 2011 function links (link) local link1 = ( "http://www.mysound1.com/sound1" ) local link2 = ( "http://www.mysound1.com/sound2" ) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() playSound(sounds[math.random(1, links)]) end ) EDIT: The Handler, starts the music when resource starts, you must change if want music on join.
Eht1 Posted December 18, 2011 Author Posted December 18, 2011 Not work function links (link) local link1 = ( "jutjub.comze.com/Music/Mc%20Hush%20-%20Fired%20Up.mp3" ) local link2 = ( "jutjub.comze.com/Music/Rock%20-%20I%20Am%20Rock.mp3" ) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() playSound(sounds[math.random(1, links)]) end ) In meta.xml is on client side. EDIT: I want like when you join music need play all time widauth stop. But random.
novo Posted December 18, 2011 Posted December 18, 2011 addEventHandler('onClientPlayerJoin', root, function() local link1 = ( "http://www.mysound1.com/sound1" ) local link2 = ( "http://www.mysound1.com/sound2" ) randomlinks = math.random(link1,link2) playSound ( randomlinks ) end )
Eht1 Posted December 18, 2011 Author Posted December 18, 2011 not work I need make maybe and server side?
Scripting Moderators Sarrum Posted December 18, 2011 Scripting Moderators Posted December 18, 2011 client: local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() playSound(sounds[math.random(1, #sounds)]) end )
Eht1 Posted December 18, 2011 Author Posted December 18, 2011 BUt now is one problem, this play one song and nothing more. I need for play all time random music.
Eht1 Posted December 18, 2011 Author Posted December 18, 2011 playSound(sounds[math.random(1, #sounds)]) i change this to playSound(sounds[math.random(#sounds)]) I think this will be ok Thanks all
Scripting Moderators Sarrum Posted December 18, 2011 Scripting Moderators Posted December 18, 2011 I have everything working.
Eht1 Posted December 18, 2011 Author Posted December 18, 2011 After first song play second song and second song is difrend of first song?
Evil-Cod3r Posted December 18, 2011 Posted December 18, 2011 local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } addEventHandler("onClientPlayerJoin", getResourceRootElement(getThisResource()), function() playSound(sounds[math.random(2, #sounds)]) end )
Al3grab Posted December 18, 2011 Posted December 18, 2011 if you know the first sound length , then you can set timer after the song is finished to play the next one local sound1 = "http://www.mysound1.com/sound1" local sound2 = "http://www.mysound1.com/sound2" addEventHandler("onClientPlayerJoin", getResourceRootElement(getThisResource()), function() playSound(sound1) local sound1Length = 60 -- in seconds setTimer(playSound,sound1Length*1000,1,sound2) end )
BinSlayer1 Posted December 18, 2011 Posted December 18, 2011 local sound1 = "http://www.mysound1.com/sound1" local sound2 = "http://www.mysound1.com/sound2" addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() playSound(sound1) setTimer(playSound,getSoundLength(sound1)*1000,1,sound2) end ) No need to input the sound length, MTA has functions for these things @ Al3grab
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