12p Posted July 3, 2012 Share Posted July 3, 2012 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
12p Posted July 4, 2012 Author Share Posted July 4, 2012 BUMP. I need help with this one, I don't get the problem. Please. Link to comment
TwiX! Posted July 4, 2012 Share Posted July 4, 2012 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
12p Posted July 4, 2012 Author Share Posted July 4, 2012 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. Link to comment
Anderl Posted July 4, 2012 Share Posted July 4, 2012 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
12p Posted July 4, 2012 Author Share Posted July 4, 2012 Anyway, I don't see any error on your code, GamerKiin. Indeed. But setRadioChannel( 0 ) isn't working there. Link to comment
robhol Posted July 5, 2012 Share Posted July 5, 2012 You could try including a minimum of helpful information - for example, what does debugscript show when running the code? Link to comment
SpUnKyMe Posted July 5, 2012 Share Posted July 5, 2012 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
X-SHADOW Posted July 5, 2012 Share Posted July 5, 2012 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
Anderl Posted July 5, 2012 Share Posted July 5, 2012 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
X-SHADOW Posted July 5, 2012 Share Posted July 5, 2012 if his code correct why it dosn't work ? Link to comment
Anderl Posted July 5, 2012 Share Posted July 5, 2012 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
12p Posted July 5, 2012 Author Share Posted July 5, 2012 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 Link to comment
50p Posted July 6, 2012 Share Posted July 6, 2012 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
12p Posted July 6, 2012 Author Share Posted July 6, 2012 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
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