jingzhi Posted February 9, 2015 Posted February 9, 2015 setRadioChannel(0) song = playSound ([url=http://www.181.fm/stream/asx/181-power.asx]http://www.181.fm/stream/asx/181-power.asx[/url], true) Hey guys please help me with this , how can make the script that the radio can be turned on or off by using commands or buttons?(like /radioon, /radiooff) Thank you!
Vision Posted February 9, 2015 Posted February 9, 2015 local radioOn = false function turnRadio ( command ) if ( command == 'radioon' and not radioOn ) then setRadioChannel ( 0 ); song = playSound ( 'http://www.181.fm/stream/asx/181-power.asx', true ); radioOn = true; elseif ( command == 'radiooff' and radioOn ) then stopSound ( song ); radioOn = false; end end addCommandHandler ( 'radioon', turnRadio ); addCommandHandler ( 'radiooff', turnRadio );
jingzhi Posted February 9, 2015 Author Posted February 9, 2015 local radioOn = false function turnRadio ( command ) if ( command == 'radioon' and not radioOn ) then setRadioChannel ( 0 ); song = playSound ( 'http://www.181.fm/stream/asx/181-power.asx', true ); radioOn = true; elseif ( command == 'radiooff' and radioOn ) then stopSound ( song ); radioOn = false; end end addCommandHandler ( 'radioon', turnRadio ); addCommandHandler ( 'radiooff', turnRadio ); Thank you very much, it works But can you also tell me how to make it be able to let player switch between channels?
Dealman Posted February 9, 2015 Posted February 9, 2015 Store the URLs in a table, for example; local radioChannels = { [1] = "www.example.com/listen.pls", [2] = "www.example.com/listen.pls", [3] = "www.example.com/listen.pls", [4] = "www.example.com/listen.pls", [5] = "www.example.com/listen.pls" } Then you can play the sound like this; local currentRadio = playSound(radioChannels[1])
jingzhi Posted February 10, 2015 Author Posted February 10, 2015 Store the URLs in a table, for example; local radioChannels = { [1] = "www.example.com/listen.pls", [2] = "www.example.com/listen.pls", [3] = "www.example.com/listen.pls", [4] = "www.example.com/listen.pls", [5] = "www.example.com/listen.pls" } Then you can play the sound like this; local currentRadio = playSound(radioChannels[1]) Hey thank you very much but can you put then in the whole script? Because im noob and I am not sure how to put this table thing, thank you again
Ryancit2 Posted February 11, 2015 Posted February 11, 2015 Put this: local radioChannels = { ["name"] = "www.example.com/listen.pls", ["name2"] = "www.example.com/listen.pls", ["name3"] = "www.example.com/listen.pls", ["name4"] = "www.example.com/listen.pls", ["name5"] = "www.example.com/listen.pls" } function startRadio(cmd, name) local channel = radioChannels[name] if (not channel) then outputChatBox("No channel found with name: "..name, 200, 0, 0) return end startChannel = playSound(channel) end addCommandHandler("playradio", startRadio) function stopRadio() if (not startChannel) then outputChatBox("No radio channel is currently on, start by /playradio ", 200, 0, 0) return end stopSound(startChannel) end addCommandHandler("stopradio", stopRadio)
jingzhi Posted February 11, 2015 Author Posted February 11, 2015 Put this: local radioChannels = { ["name"] = "www.example.com/listen.pls", ["name2"] = "www.example.com/listen.pls", ["name3"] = "www.example.com/listen.pls", ["name4"] = "www.example.com/listen.pls", ["name5"] = "www.example.com/listen.pls" } function startRadio(cmd, name) local channel = radioChannels[name] if (not channel) then outputChatBox("No channel found with name: "..name, 200, 0, 0) return end startChannel = playSound(channel) end addCommandHandler("playradio", startRadio) function stopRadio() if (not startChannel) then outputChatBox("No radio channel is currently on, start by /playradio ", 200, 0, 0) return end stopSound(startChannel) end addCommandHandler("stopradio", stopRadio) Thank you, now i got a clue
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