Chrissi2812 Posted April 15, 2011 Share Posted April 15, 2011 This is the script i I only changed some things to it function startMusic() setRadioChannel(0) song = playSound("song2.ogg",true) outputChatBox("Toggle the music on/off with 'm'", 255, 0, 255 ) outputChatBox("Change Song with 'n'", 255, 0, 255 ) 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(1) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) end function selectSong() stopSound(song) song2 = playSound("song.ogg",true) outputChatBox("Changed Song", 255, 0, 255 ) end end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addCommandHandler("music",toggleSong) addCommandHandler("sel",selectSong) bindKey("m","down","music") bindKey("n","down","sel") If the player presses "n" The song should be changed but nothing happens Link to comment
Castillo Posted April 15, 2011 Share Posted April 15, 2011 Your bindKey function is wrong. function startMusic() setRadioChannel(0) song = playSound("song2.ogg",true) outputChatBox("Toggle the music on/off with 'm'", 255, 0, 255 ) outputChatBox("Change Song with 'n'", 255, 0, 255 ) 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(1) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) end function selectSong() stopSound(song) song2 = playSound("song.ogg",true) outputChatBox("Changed Song", 255, 0, 255 ) end end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addCommandHandler("music",toggleSong) addCommandHandler("sel",selectSong) bindKey("m","down",toggleSong) bindKey("n","down",selectSong) Btw, this is a dissaster.. i recommend learning the basics than copyng a code made by someone else 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