Sign in to follow this  
jingzhi

Please help me with online radio system

Recommended Posts

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!

Share this post


Link to post
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 ); 

Share this post


Link to post
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 :D But can you also tell me how to make it be able to let player switch between channels?

Share this post


Link to post

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]) 

Share this post


Link to post
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 :D

Share this post


Link to post

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) 

Share this post


Link to post
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 :)

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.