Jump to content

setRadioChannel not working? Da faq


12p

Recommended Posts

Posted

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 ) 

Posted

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

Posted

Heck no. That code doesn't work the way I want this to work.

However, what's the problem with my code? Just tell me what I'm doing wrong, please.

Posted
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.

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

Indeed. But setRadioChannel( 0 ) isn't working there.

Posted

You could try including a minimum of helpful information - for example, what does debugscript show when running the code?

Posted
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

Posted

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 ) 

Posted
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.

Posted
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.

Posted

Well... This seems like a MTA bug or software-related problem. This code doesn't work for me when I test it, but it doesn't throw errors nor I see any fail in the coding :/

Posted

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?

Posted

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.

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...