Jump to content

If anyone has.


Jason1337

Recommended Posts

Didn't wan't to finish the title because i wanted people to read what i say (cheeky of me hehe :) )

Anyways,does anyone have or are kindly willing to share a .lua for music on a map,iv'e just finished mapping a dd map (destruction derby) and I'm playing in a server with other professional map creators and on all of their maps they have music,yea music isn't really a professional thing but,I need it to impress the map selectors,(yes they have a group of people who select maps lol)

So as I said,if anyone is kindly willing to share the file or at least the code and tell me what to do with it.Thank you :)

Edit:iv'e searched on this before but I didn't find a script that worked :/

Link to comment

but do I make a seperate .lua or do i add it into my meta? oh and do i place my mp3 into the dd map folder?

Sorry im such a noob when it comes to .lua and scripting xD

EDIT:Sorry for editing if you already answerd but when i test my map,it shows a help menu and it tells you that you can press f1 to customize your car etc,like in free roam,ugh does that go away in the actual server? cuz like i dont need people flying around getting tanks and such,ive already prepared the spawns,and im using Race as the "gamemode" there is no DD gamemode. :/

And another edit,lol im so forgetful.:Iv'e played in your server :D its really nice.

Edited by Guest
Link to comment

You create 2 files; meta.xml and client.lua. In your client.lua you'll script the functions and the addEventHandler. In your meta you'll say that you have 1 script and 1 file ( search the wiki for this ). And you place the .mp3 in the same map ( create a new one for all the files ofc ) as your client.lua and meta.xml. That's all.

Link to comment
but do I make a seperate .lua or do i add it into my meta? oh and do i place my mp3 into the dd map folder?

Sorry im such a noob when it comes to .lua and scripting xD

EDIT:Sorry for editing if you already answerd but when i test my map,it shows a help menu and it tells you that you can press f1 to customize your car etc,like in free roam,ugh does that go away in the actual server? cuz like i dont need people flying around getting tanks and such,ive already prepared the spawns,and im using Race as the "gamemode" there is no DD gamemode. :/

And another edit,lol im so forgetful.:Iv'e played in your server :D its really nice.

If you are on the map editor, then it must be the freeroam, and no, it won't show on the actual server, unless you start "freeroam" resource, obviously.

Link to comment
You create 2 files; meta.xml and client.lua. In your client.lua you'll script the functions and the addEventHandler. In your meta you'll say that you have 1 script and 1 file ( search the wiki for this ). And you place the .mp3 in the same map ( create a new one for all the files ofc ) as your client.lua and meta.xml. That's all.

dudee im a noob i know nothing about this lol,not a single clue,that does not help me a single bit.

Link to comment
addEventHandler ( "onClientResourceStart", resourceRoot, -- Attach a 'onClientResourceStart' event to the function. 
    function ( ) -- Define the function. 
        playSound ( "mySoundFile.mp3" ) -- Play a sound file. 
    end -- End the function. 
) 

so on the "Function ()" do i type (StartMusic.mp3)

and on the top i have no idea what to add,if you are trying to make me learn lua,fat chance lol,im not going to get it :/ ""Attach a 'onClientResourceStart' event to the function."" attach what? lol

Link to comment
That's just a comment, that script is ready to work, all you have to do is copy the script to a .lua file, change "mySoundFile.mp3" to your file name, and add the recently created .lua to the meta.xml of your map, like this:

right and this is where the problem comes in ,where in the meta xml do i add the script? at what part?

this is what i mean :

    "race" type="map" name="[DD]Jason Are you Ready?" author="|T1|Jason" version="1.0.0" description="My 1st one.Enjoy ">
    "DDJason.map" dimension="0">
    
        "#skins" value='[ "random" ]'>
        "#maxplayers" value="[ 32 ]">
        "#useLODs" value="[ false ]">
        "#gamespeed" value="[ 1 ]">
        "#ghostmode" value='[ "false" ]'>
        "#time" value="22:0">
        "#vehicleweapons" value='[ "true" ]'>
        "#minplayers" value="[ 1 ]">
        "#weather" value="[ 13 ]">
        "#gravity" value="[ 0.008000 ]">
        "#waveheight" value="[ 0 ]">
        "#respawntime" value="[ 999999 ]">
        "#locked_time" value="[ true ]">
        "#duration" value="[ 720 ]">
        "#respawn" value='[ "none" ]'>
    
    "music.mp3">
    
    
    

  
  

where in there do i add it?

EDIT : Ive added it next to the other

Link to comment

Feel free to use my code below if you'd like, it features a volume control so players can decrease/increase the volume of the song that is played.

Remember the re-name the mp3 file either in the script or the file itself!

Music.lua

local isMusicPlaying = false 
local isMusicMuted = false 
local radioOff = false 
local mapMusic = nil 
  
local currentVolume = 1 
  
function onMapStartPlayMusic() 
    if(isMusicPlaying == false) then 
        if(radioOff == false) then 
            setRadioChannel(0) 
            radioOff = true 
        end 
        mapMusic = playSound("Music.mp3", true) 
        isMusicPlaying = true 
    end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onMapStartPlayMusic) 
  
function muteMapMusic() 
    if(isMusicMuted == false) then 
        setSoundVolume(mapMusic, 0) 
        outputChatBox("#696969[Map]: #FFD700You've muted the music!", 255, 255, 255, true) 
        isMusicMuted = true 
    else 
        setSoundVolume(mapMusic, currentVolume) 
        outputChatBox("#696969[Map]: #FFD700You've unmuted the music!", 255, 255, 255, true) 
        isMusicMuted = false 
    end 
end 
bindKey("m", "down", muteMapMusic) 
  
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("#696969[Map]: #FFD700You'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("#696969[Map]: #FFD700You've muted the music!", 255, 255, 255, true) 
        end 
    end 
end 
addEventHandler("onClientKey", getRootElement(), changeMapMusicVolume) 
  
function onPlayerChangeRadio() 
    cancelEvent() 
end 
addEventHandler("onClientPlayerRadioSwitch", getRootElement(), onPlayerChangeRadio) 

Edit:

If your map doesn't show up, it might be that the Editor is bugged. It happens sometimes, try to restart MTA and open the editor again, see if it shows up. :)

Link to comment
Feel free to use my code below if you'd like, it features a volume control so players can decrease/increase the volume of the song that is played.

Remember the re-name the mp3 file either in the script or the file itself!

Music.lua

local isMusicPlaying = false 
local isMusicMuted = false 
local radioOff = false 
local mapMusic = nil 
  
local currentVolume = 1 
  
function onMapStartPlayMusic() 
    if(isMusicPlaying == false) then 
        if(radioOff == false) then 
            setRadioChannel(0) 
            radioOff = true 
        end 
        mapMusic = playSound("Music.mp3", true) 
        isMusicPlaying = true 
    end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onMapStartPlayMusic) 
  
function muteMapMusic() 
    if(isMusicMuted == false) then 
        setSoundVolume(mapMusic, 0) 
        outputChatBox("#696969[Map]: #FFD700You've muted the music!", 255, 255, 255, true) 
        isMusicMuted = true 
    else 
        setSoundVolume(mapMusic, currentVolume) 
        outputChatBox("#696969[Map]: #FFD700You've unmuted the music!", 255, 255, 255, true) 
        isMusicMuted = false 
    end 
end 
bindKey("m", "down", muteMapMusic) 
  
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("#696969[Map]: #FFD700You'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("#696969[Map]: #FFD700You've muted the music!", 255, 255, 255, true) 
        end 
    end 
end 
addEventHandler("onClientKey", getRootElement(), changeMapMusicVolume) 
  
function onPlayerChangeRadio() 
    cancelEvent() 
end 
addEventHandler("onClientPlayerRadioSwitch", getRootElement(), onPlayerChangeRadio) 

Edit:

If your map doesn't show up, it might be that the Editor is bugged. It happens sometimes, try to restart MTA and open the editor again, see if it shows up. :)

so all i have to do is make a new lua file paste that in and do nothing to the meta??

Link to comment

so all i have to do is make a new lua file paste that in and do nothing to the meta??

New or replace the existing one it is up to you. Whether you need to add it to the meta file or not is up to you - whether you add it as a new file or replace the old one.

Either way, it has to be in the Meta. Remember that it's case-sensitive!

Link to comment

can someone actualy post everything i have to do and not say its up to me,im not sure you guys understand me I KNOW NOTHING ABOUT LUA.. saying its up to me whats up to me?? dafuq do i add?? al you guys are doing is posting scripts and expect me to know what to do ..no i dont know what to do

Link to comment
Save it as Music.lua.

Add this to the Meta.xml


dealman.where do i put that next to in the meta? this is my meta :

    "race" type="map" name="[DD]Jason Are you Ready?" author="|T1|Jason" version="1.0.0" description="My 1st one.Enjoy ">
    "DDJason.map" dimension="0">
    
        "#skins" value='[ "random" ]'>
        "#maxplayers" value="[ 32 ]">
        "#useLODs" value="[ false ]">
        "#gamespeed" value="[ 1 ]">
        "#ghostmode" value='[ "false" ]'>
        "#time" value="22:0">
        "#vehicleweapons" value='[ "true" ]'>
        "#minplayers" value="[ 1 ]">
        "#weather" value="[ 13 ]">
        "#gravity" value="[ 0.008000 ]">
        "#waveheight" value="[ 0 ]">
        "#respawntime" value="[ 999999 ]">
        "#locked_time" value="[ true ]">
        "#duration" value="[ 720 ]">
        "#respawn" value='[ "none" ]'>
    
    
    

  

Link to comment
   "race" type="map" name="[DD]Jason Are you Ready?" author="|T1|Jason" version="1.0.0" description="My 1st one.Enjoy ">
    "DDJason.map" dimension="0">
    
    
    

Make sure the mp3 file is called exactly "Music.mp3" and the script is called "Music.lua". Unless you want to edit it in the script.

Link to comment
do you have teamviewer?lol this is just so confusing i did everything but now i cant find my map when i try to open it xD

Im gonna pm you my team viewer details..

okay maybe not now,im watching frankies 1h dayz ep 41 vid..umm yea xD

I do, but I'd have to help you later as I've got to go for a few hours now.

The meta I posted above is already fixed for you. All you have to do is copy and paste it. Copy my script into a text file and save it as Music.lua inside your map folder. Move the song you want to be played into your map folder and rename it Music.mp3(Make sure it's a mp3).

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...