Jump to content

[TUT] Create a simple music script


Ab-47

Recommended Posts

Hello guys, today I'll be showing you how to create your very own music script. Well first of all, we'd need a link to a working .mp3 sound, or any song from your personal files. We'll then need to open Notepad++ and begin with our work.

Step 1;

Open Notepad++ and set out 2 new pages, 1 for the meta.xml & 2nd for the client functions

Step 2;

Find a link or a sound file in your personal directory. Link should be in an .mp3 page else it'd not work.

I chose the radio station power 181.fm; http://www.181.fm/winamp.pls?station=18 ... 0(Top%2040)&file=181-power.pls

Step 3;

Create a function and add valid arguments, in this case we use "local sound = playSound3D", where sound is the name we're defining the function. And of-course, 'playSound3D', is the function. Then we add arguments within the function itself.

addEventHandler( 'onClientResourceStart', resourceRoot, 
        function( ) 
        local sound = playSound3D( 'Your Link here', x, y, z ) 
end 
) 
  

Say for example your would like to set this sound in an interior or dimension, we could use;

setElementInterior 

setElementDimension 

for example;

setElementInterior ( sound, 17 ) 

and

setElementDimension ( sound, 200 ) 

also if you'd want to add a sound from your personal folders, use;

local sound = playSound("sound.mp3",false) 

and include this in your meta;

"sound.mp3" /> 

Step 4;

Now lets be more specific, lets add the maximum distance for the sound to reach, using;

setSoundMaxDistance 

for example;

setSoundMaxDistance ( sound, 400 ) 

Step 5;

So we're finally done with the client sided, you don't neccesarrily need the server sided.

Lets get an overview example of this script, shall we..

addEventHandler( 'onClientResourceStart', resourceRoot, 
        function( ) 
        local sound = playSound3D( 'http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls', 485.87612915039, -11.931990623474, 1000.679687 ) 
        setSoundMaxDistance(sound, 600 ) 
        setElementInterior ( sound, 17 ) 
end 
) 

Which creates a sound, using a defined URL, in interior 17 with the maximum distance as 600 at the x, y, z position. You can also change the event handler to a command handler to start the sound whenever you like and if you'd like to stop the music, simple create a new function defining the valid arguments and add this;

stopSound 

Thanks for reading.

P.s; I think you'll know how to construct your meta.xml, if you're using custom sounds from your personal files, be sure to add this to your meta.xml;

"sound.mp3" /> 

Link to comment
This is too easy, in my opinion it wasn't needed. It was well explained, though.

Aha, many people don't really know how to script. So I made this just for the newbies. Well stay tuned I'll introduce more upcoming tutorials much more harder than this. Thanks for the positive feedback though ;)

Link to comment
  • 2 weeks later...
  • Recently Browsing   0 members

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