Snoop.Cat Posted March 24, 2013 Share Posted March 24, 2013 hey guys i have a problem , when i start this music script the other music from the map resources keep playing , my question is how i can mute the music from every map that start so players can only hear the music from my resource? here is my resource: function startMusic() setRadioChannel(0) song = playSound("song.mp3",true) 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
MIKI785 Posted March 24, 2013 Share Posted March 24, 2013 Something like this will do the magic: for i, sound in ipairs(getElementsByType("sound")) do setSoundVolume(sound, 0) end Start your music after applying this loop. Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 im srry im noob on scripting , where i should put that code? and also do i should use a setTimer so when a new race map start then it mutes it again? Link to comment
MIKI785 Posted March 24, 2013 Share Posted March 24, 2013 Put it before any music you want to be the only one heard, that's playSound. Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 soo code should be like for i, sound in ipairs(getElementsByType("sound")) do setSoundVolume(sound, 0) end function startMusic() setRadioChannel(0) song = playSound("song.mp3",true) 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") and then only this sound of this specific script will play and others from maps will be muted always? Link to comment
MIKI785 Posted March 24, 2013 Share Posted March 24, 2013 Yep, this will mute any other sounds when the resource (map) is started. Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 it mutes the music but when a new map load the music from new map starts anyway Link to comment
MIKI785 Posted March 24, 2013 Share Posted March 24, 2013 What? What do you exactly want? Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 start the script and mute every music from every race map that loads a new music.. Link to comment
MIKI785 Posted March 24, 2013 Share Posted March 24, 2013 Oh... My bad... function muteSounds () for i, sound in ipairs(getElementsByType("sound")) do if not sound == song then setSoundVolume(sound, 0) end end end addEventHandler("onClientResourceStart", root, function () setTimer(muteSounds, 1000, 1) --To make sure that the sound is already playing end) OR You could simply use timer.. function muteSounds () for i, sound in ipairs(getElementsByType("sound")) do if not sound == song then setSoundVolume(sound, 0) end end end setTimer(muteSounds, 1000, 0) Link to comment
EstrategiaGTA Posted March 24, 2013 Share Posted March 24, 2013 Is "WITH", not "WHIT". Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 miki no one of those codes works , it doesnt not even mute any sound Link to comment
Snoop.Cat Posted March 24, 2013 Author Share Posted March 24, 2013 im srry but i need help Link to comment
iPrestege Posted March 24, 2013 Share Posted March 24, 2013 You want that no one can play music i mean hear music from any map! or any resource? Link to comment
codeluaeveryday Posted March 25, 2013 Share Posted March 25, 2013 You need to use onClientResourceStart. I recommend you do not mute the sound, this can cause lag as it still uses background CPU. Example: -- This script requires mapmanager to be running! addEventHandler('onClientResourceStart', getRootElement(), function(that) if that ~= this and exports.mapmanager:isMap(that) then for i, v in ipairs(getElementsByType("sound")) do stopSound(v) end startMusic() end end ) function startMusic() setRadioChannel(0) song = playSound("song.mp3",true) 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("onClientPlayerRadioSwitch",getRootElement(), makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(), makeRadioStayOff) addCommandHandler("music", toggleSong) bindKey("m","down","music") Link to comment
Snoop.Cat Posted March 25, 2013 Author Share Posted March 25, 2013 You need to use onClientResourceStart. I recommend you do not mute the sound, this can cause lag as it still uses background CPU.Example: -- This script requires mapmanager to be running! addEventHandler('onClientResourceStart', getRootElement(), function(that) if that ~= this and exports.mapmanager:isMap(that) then for i, v in ipairs(getElementsByType("sound")) do stopSound(v) end startMusic() end end ) function startMusic() setRadioChannel(0) song = playSound("song.mp3",true) 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("onClientPlayerRadioSwitch",getRootElement(), makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(), makeRadioStayOff) addCommandHandler("music", toggleSong) bindKey("m","down","music") it doesnt works it doesnt start music from resource and not mute the music from maps Link to comment
codeluaeveryday Posted March 26, 2013 Share Posted March 26, 2013 Sorry small mistake, its now working: addEventHandler('onClientResourceStart', getRootElement(), function(that) if that ~= this then for i, v in ipairs(getElementsByType("sound")) do stopSound(v) end startMusic() end end ) function startMusic() setRadioChannel(0) song = playSound("song.mp3",true) 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("onClientPlayerRadioSwitch",getRootElement(), makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(), makeRadioStayOff) addCommandHandler("music", toggleSong) bindKey("m","down","music") Link to comment
Snoop.Cat Posted March 27, 2013 Author Share Posted March 27, 2013 problem solved thx alot csmith Link to comment
codeluaeveryday Posted March 27, 2013 Share Posted March 27, 2013 No problem, it's my fault for making that dumb small mistake I actually feel bad for doing that. Have a lovely year. 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