Jump to content

setRadioChannel not working? Da faq


12p

Recommended Posts

Pretty simple. I just wanted to enable the player to "save" its radio station once it enables the map music, and "load" this saved station when it disables the map music.

By some reason there's a line that doesn't want to work.

pl = true --Is map music playing? 
radio = getRadioChannel( ) 
setRadioChannel( 0 ) 
music = playSound( "music.mp3", true ) 
  
bindKey( "m", "down", 
    function( ) 
        --if not isElement( music ) then return end 
        setSoundPaused( music, pl ) 
        pl = not pl 
        if pl then --When music is playing, the radio shall be saved and set to OFF. 
            radio = getRadioChannel( ) 
            setRadioChannel( 0 ) --This line doesn't work. 
        else setRadioChannel( radio ) end --When music is stopped by user, the radio is turned ON with the latest station used 
    end ) 

Link to comment

use standart code

function startMusic() 
    setRadioChannel(0) 
    song = playSound("song.mp3",true) 
    outputChatBox("Toggle the music on/off with 'm'") 
end 
  
function makeRadioStayOff() 
    setRadioChannel(0) 
    cancelEvent() 
end 
  
function toggleSong() 
    if not songOff then 
        setSoundVolume(song,0) 
        songOff = true 
        removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
    else 
        setSoundVolume(song,1) 
        songOff = false 
        setRadioChannel(0) 
        addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
    end 
end 
  
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) 
addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) 
addCommandHandler("music",toggleSong) 
bindKey("m","down","music") 

Link to comment
use standart code
function startMusic() 
    setRadioChannel(0) 
    song = playSound("song.mp3",true) 
    outputChatBox("Toggle the music on/off with 'm'") 
end 
  
function makeRadioStayOff() 
    setRadioChannel(0) 
    cancelEvent() 
end 
  
function toggleSong() 
    if not songOff then 
        setSoundVolume(song,0) 
        songOff = true 
        removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
    else 
        setSoundVolume(song,1) 
        songOff = false 
        setRadioChannel(0) 
        addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
    end 
end 
  
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) 
addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) 
addCommandHandler("music",toggleSong) 
bindKey("m","down","music") 

This is not standard code. This is copied code.

Anyway, I don't see any error on your code, GamerKiin.

Link to comment
Pretty simple. I just wanted to enable the player to "save" its radio station once it enables the map music, and "load" this saved station when it disables the map music.

By some reason there's a line that doesn't want to work.

pl = true --Is map music playing? 
radio = getRadioChannel( ) 
setRadioChannel( 0 ) 
music = playSound( "music.mp3", true ) 
  
bindKey( "m", "down", 
    function( ) 
        --if not isElement( music ) then return end 
        setSoundPaused( music, pl ) 
        pl = not pl 
        if pl then --When music is playing, the radio shall be saved and set to OFF. 
            radio = getRadioChannel( ) 
            setRadioChannel( 0 ) --This line doesn't work. 
        else setRadioChannel( radio ) end --When music is stopped by user, the radio is turned ON with the latest station used 
    end ) 

Your code is working fine in my local server ;p

Link to comment

Can you Try This,

pl = true 
radio = getRadioChannel( ) 
setRadioChannel( 0 ) 
music = playSound( "music.mp3") 
  
bindKey( "m", "down", 
    function( ) 
        setSoundPaused( music, pl ) 
        pl = not pl 
        if pl then 
            setRadioChannel( 0 ) 
        else 
         setRadioChannel( radio )  
         end  
end ) 

Link to comment
Can you Try This,
pl = true 
radio = getRadioChannel( ) 
setRadioChannel( 0 ) 
music = playSound( "music.mp3") 
  
bindKey( "m", "down", 
    function( ) 
        setSoundPaused( music, pl ) 
        pl = not pl 
        if pl then 
            setRadioChannel( 0 ) 
        else 
         setRadioChannel( radio )  
         end  
end ) 

Dude, GamerKiin code is correct.

Yours is wrong, not language error but it does not do what GamerKiin wants anymore.

Link to comment
Pretty simple. I just wanted to enable the player to "save" its radio station once it enables the map music, and "load" this saved station when it disables the map music.

By some reason there's a line that doesn't want to work.

pl = true --Is map music playing? 
radio = getRadioChannel( ) 
setRadioChannel( 0 ) 
music = playSound( "music.mp3", true ) 
  
bindKey( "m", "down", 
    function( ) 
        --if not isElement( music ) then return end 
        setSoundPaused( music, pl ) 
        pl = not pl 
        if pl then --When music is playing, the radio shall be saved and set to OFF. 
            radio = getRadioChannel( ) 
            setRadioChannel( 0 ) --This line doesn't work. 
        else setRadioChannel( radio ) end --When music is stopped by user, the radio is turned ON with the latest station used 
    end ) 

Your code is working fine in my local server ;p

Cuz this? And I tested it too, it works fine.

Link to comment

setRadioChannel is a little bugged. I haven't tested it deeply but I know for a fact that if you want to use setRadioChannel you first have to enter a vehicle but I presume you are in a vehicle if you're saying radio station 0 fails. What does setRadioChannel return?

Link to comment

I got stressed trying to make this damn code work, so I just took the previous posted one and modified it my way (who's the original author of that code? does someone know it?).

However, since my map is made for Race, the player is always inside a car, so that wouldn't be the problem, 50p.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...