Sticky: [TUT] How to add music in your map

Show here your self made maps!

Sticky: [TUT] How to add music in your map

Postby Jessie » Fri Nov 08, 2013 8:07 am

Hello,

In this tutorial i will show you how to put music your map.

First you need to finish your map before you insert the music.

After you finished the map you need to insert the music script.

You need to open a .txt file and copy and past this code in it:
Code: Select all
function startMusic()
    setRadioChannel(0)
    song = playSound("song.mp3",true)
   outputChatBox("Press M to turn Off or turn On the music")
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("musicmusic",toggleSong)
bindKey("m","down","musicmusic")
addEventHandler("onClientResourceStop",getResourceRootElement(getThisResource()),startMusic)

And save it as music.lua.

Now we have to add a line to the meta.xml for it to work.

You have to add this line:
Code: Select all
<script src="music.lua" type="client"></script>
 <file src="sound.mp3"></file>


And save the meta.xml, now it should work.

Now you have to drag the song you want into the .zip file and name it song.mp3.

If you have any questions/problems you can post it here.

Good luck and have fun!
Image
Image
User avatar
Jessie
MX Leader
MX Leader
 
Posts: 380
Joined: Sun May 12, 2013 8:28 pm
In-game: Jessye+

Re: Sticky: [TUT] How to add music in your map

Postby khalil15832 » Mon Nov 09, 2015 10:40 pm

Nice work keep it :)
Image
User avatar
khalil15832
 
Posts: 7
Joined: Mon Nov 09, 2015 9:47 pm
In-game: SpiRoo


Return to Maps

Who is online

Users browsing this forum: No registered users and 5 guests