jingzhi Posted February 9, 2015 Share 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! Link to comment
Vision Posted February 9, 2015 Share 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 ); Link to comment
jingzhi Posted February 9, 2015 Author Share 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? Link to comment
jingzhi Posted February 9, 2015 Author Share Posted February 9, 2015 Please help guys Link to comment
Dealman Posted February 9, 2015 Share 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]) Link to comment
jingzhi Posted February 10, 2015 Author Share 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 Link to comment
Ryancit2 Posted February 11, 2015 Share 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) Link to comment
jingzhi Posted February 11, 2015 Author Share 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 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