mody Posted November 17, 2013 Share Posted November 17, 2013 Hi guys i need a little help . Can any one tell me step by step how to add/put a song for my race map ? Link to comment
Driggero Posted November 17, 2013 Share Posted November 17, 2013 create a file called music.lua and add this to it function startMusic() setRadioChannel(0) song = playSound("music.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("mkmap1_racetheme",toggleSong) bindKey("m","down","mkmap1_racetheme") Place your music file in the same folder as the map and call it music.mp3. Next you need to add these 2 lines into the meta: <file src="music.mp3"></file> <script src="music.lua" type="client"></script> Then you're done Link to comment
mody Posted November 18, 2013 Author Share Posted November 18, 2013 create a file called music.lua and add this to it function startMusic() setRadioChannel(0) song = playSound("music.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("mkmap1_racetheme",toggleSong) bindKey("m","down","mkmap1_racetheme") Place your music file in the same folder as the map and call it music.mp3. Next you need to add these 2 lines into the meta: <file src="music.mp3"></file> <script src="music.lua" type="client"></script> Then you're done I did the same but i can't here the song when i'm playing the map at map editor is that normal ? Link to comment
Driggero Posted November 18, 2013 Share Posted November 18, 2013 It should work in the map editor too. Are you sure the music file is in mp3 format and placed inside the map folder? If so then there may be a syntax error. Open up the debugstring with /debugscript 3 and see if the resource loaded correctly. Link to comment
mody Posted November 18, 2013 Author Share Posted November 18, 2013 It should work in the map editor too. Are you sure the music file is in mp3 format and placed inside the map folder? If so then there may be a syntax error. Open up the debugstring with /debugscript 3 and see if the resource loaded correctly. the file you said i should name it music.lua i made it as text document and copy same code and added the 2 lines inside meta after i opened it as a notepad and i'm sure the the music file inside my map folder and named it music.mp3 Link to comment
Price. Posted November 18, 2013 Share Posted November 18, 2013 well here is a better choice create a speaker anywhere and it will play the song. Client function onResourceStart() local sound = playSound3D("song.mp3",X,Y,Z, true) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart) Server createObject ( 2232, 2495.1, -1689.9, 17.2, 0, 2, 182 ) create same file of the music .mp3 or whatever Link to comment
Dealman Posted November 18, 2013 Share Posted November 18, 2013 In what way is that a better way of doing it? It is miles worse, that created a sound element in a 3D Environment. Only people close to it will be able to hear it unless you use setSoundMaxDistance. Which is a big inconvenience if you want the song to play for everyone when the map is being played. I made a improved music script for maps a while ago, I'll see if I still have it around. I'll edit this reply if I do. Edit: Found it, copy and paste this to a file. You can name it whatever you want. I would suggest "Music.mp3" to simplify things. Code; -------------------------------------- -- Written by [F*A*G]Dealman -- -- For use on DDAS Servers -- -------------------------------------------- -- Released as Open-Source -- -- You're free to make changes -- -- You're free to re-distribute -- -- Please, do not remove credits. -- -------------------------------------------- local isMusicPlaying = false local isMusicMuted = false local radioOff = false local mapMusic = nil local currentVolume = 1 -- For playing the music when the map is started. function onMapStartPlayMusic() if(isMusicPlaying == false) then if(radioOff == false) then setRadioChannel(0) radioOff = true end mapMusic = playSound("Music.mp3", true) -- This is the music file itself. You can rename it to what your MP3 is called. --mapMusic = playSound("Sound/Music.mp3", true) -- This is just an example for what it would look like if your MP3 is in another folder. isMusicPlaying = true outputChatBox("[Map]: Map Music Started!", 255, 255, 255, true) outputChatBox("[Map]: Press to Mute or Un-Mute the music!", 255, 255, 255, true) outputChatBox("[Map]: Change the volume with NumPad <+> and <->!", 255, 255, 255, true) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onMapStartPlayMusic) -- For muting and un-muting the music. function muteMapMusic() if(isMusicMuted == false) then setSoundVolume(mapMusic, 0) outputChatBox("[Map]: You've muted the music!", 255, 255, 255, true) isMusicMuted = true else setSoundVolume(mapMusic, currentVolume) outputChatBox("[Map]: You've unmuted the music!", 255, 255, 255, true) isMusicMuted = false end end bindKey("m", "down", muteMapMusic) -- For changing the volume, NumPad + and NumPad -. function changeMapMusicVolume(pressedButton, keyState) if((pressedButton == "num_add") and (keyState == true)) then currentVolume = ((currentVolume)+0.1) currentVolume = (tonumber(currentVolume) <= 0 and 0) or (tonumber(currentVolume) >= 1 and 1) or tonumber(currentVolume) setSoundVolume(mapMusic, currentVolume) if(currentVolume >= 1) then currentVolume = 1 outputChatBox("[Map]: You've reached maximum volume!", 255, 255, 255, true) end elseif((pressedButton == "num_sub") and (keyState == true)) then currentVolume = ((currentVolume)-0.1) currentVolume = (tonumber(currentVolume) <= 0 and 0) or (tonumber(currentVolume) >= 1 and 1) or tonumber(currentVolume) setSoundVolume(mapMusic, currentVolume) if(currentVolume <= 0) then setSoundVolume(mapMusic, 0) currentVolume = 0 outputChatBox("[Map]: You've muted the music!", 255, 255, 255, true) end end end addEventHandler("onClientKey", getRootElement(), changeMapMusicVolume) -- If you want to prevent the players from changing radio channel. function onPlayerChangeRadio() cancelEvent() end addEventHandler("onClientPlayerRadioSwitch", getRootElement(), onPlayerChangeRadio) If you need any help to make changes to it, don't hesitate to ask me. I'd be glad to help! Make sure you name the music file to the same as the script or the other way around. Also remember that it is case-sensitive! 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