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

357ac0078264.jpg

- Working on [php/HTML/Mysql/Lua/Java Scripts/Web Design/3D Modeling]

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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?

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

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 ) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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

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