Jump to content

Music in area


BlackS

Recommended Posts

Hello all, I'm trying to make a script to play music when you enter the beach area, but It wont play any music.

gRoot = getRootElement() 
gResRoot = getResourceRootElement(getThisResource()) 
x = 253.234375 
y = -1784.283203125 
z = 4.2362642288208 
  
function soundStart() 
    if x and y and z then 
        sound = playSound3D("music.mp3", x, y, z, true) 
        if sound then 
            outputDebugString("3D Created successful", 3) 
        else 
            outputDebugString("Error creating 3D", 1) 
        end 
    end 
end 
addEventHandler("onClientResourceStart", gResRoot, soundStart) 
  
function stopSound() 
    if sound then 
        destroyElement(sound) 
        outputDebugString("3D destroyed.", 3) 
    else 
        return 
    end 
end 
addEventHandler("onClientResourceStop", gResRoot, stopSound) 

Second: I've got a shoutcast radio station, Am I able to put it also at that area?

In MTA 1.1 is that possible I heard

Link to comment

Did you add music.mp3 to the meta?

And there is already a stopSound function, you can use it to stop the sound, you don't need to make your own.

stopSound 

In MTA 1.1 you can play a live radio.

playSound3D ( "http://radio.com/radio" , 0 , 0 , 0 ) 

Just an example.

Link to comment

Try:

meta:

<meta> 
<info type="script" version="1" author="BlackS"/> 
<script src = "client.lua" type = "client" /> 
<file src = "music.mp3" /> 
</meta> 

client.lua:

function soundStart() 
   sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 

Use /debugscript 3.

Link to comment
You are outputting debug messages, you should see it.

Use /debugscript 3

The lua file name must be: client.lua

Oh okay that way, It was named: Untitled 1.lua

Second: I'm using a listen2myradio client.

URLs are like myradio.listen2myradio.com

those works also?

EDIT: Renamed and tested, Still nothing.

Link to comment

This is what I've got now: I've added the 2 new parts.

I've heard a little sound and I think it will working, need to check the soundfile first.

function soundStart() 
   sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 
  
local sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
  
function distanceFunc(command, param) 
  setSoundMinDistance(sound, (10)(param)) 
end 
addCommandHandler("setdistance", distanceFunc) 
  
local sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
  
function maxdistanceFunc(command, param) 
  setSoundMaxDistance(sound, (50)(param)) 
end 
addCommandHandler("setmaxdistance", maxdistanceFunc) 

But my next question: Will this work in MTA 1.1? I couldn't start this 1 in the local server: It contain illegal charachters

function soundStart() 
   sound = playSound3D("myradio.listen2myradio.com", 253.234375, -1784.283203125, 4.2362642288208, true) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 
  
local sound = playSound3D("myradio.listen2myradio.com", 253.234375, -1784.283203125, 4.2362642288208, true) 
  
function distanceFunc(command, param) 
  setSoundMinDistance(sound, (10)(param)) 
end 
addCommandHandler("setdistance", distanceFunc) 
  
local sound = playSound3D("myradio.listen2myradio.com", 253.234375, -1784.283203125, 4.2362642288208, true) 
  
function maxdistanceFunc(command, param) 
  setSoundMaxDistance(sound, (50)(param)) 
end 
addCommandHandler("setmaxdistance", maxdistanceFunc) 

Link to comment
Dear me... you were meant to add those functions just where its created not create 3 different sounds and 2 unecessary commands and functions.

Also what the hell is "setSoundMinDistance(sound, (10)(param))"

Calm down arran, He's new and where suppose to help him

Link to comment
Dear me... you were meant to add those functions just where its created not create 3 different sounds and 2 unecessary commands and functions.

Also what the hell is "setSoundMinDistance(sound, (10)(param))"

Calm down arran, He's new and where suppose to help him

Nah I understand, Smacked my head to, Stupid fault.

I guess I've got to add it this way?

PS: Glad there is a MTA forum for help :D

function soundStart() 
   sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
     setSoundMinDistance(sound, tonumber(param)) 
     setSoundMaxDistance(sound, tonumber(param)) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
  
  
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 

Link to comment

Almost, param doesn't exist in your script (you just copied it from the wiki)

function soundStart() 
   sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   setSoundMinDistance(sound, 10) 
   setSoundMaxDistance(sound, 20) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 

You're confused by the wiki example, it could be also done this way:

mindistance = 10 
maxdistance = 20 
function soundStart() 
   sound = playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   setSoundMinDistance(sound, mindistance ) 
   setSoundMaxDistance(sound, maxdistance ) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 

Link to comment

I already tried this , but dont work.

I messed up it alot and all sounds starts in the same time -.-

Here :

mindistance = 5 
maxdistance = 50 
function soundStart() 
   if sound == playSound3D("music.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) then 
   sound1 = playSound3D("music1.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   else 
   sound2 = playSound3D("music2.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   else 
   sound3 = playSound3D("music3.mp3", 253.234375, -1784.283203125, 4.2362642288208, true) 
   end 
   setSoundMinDistance(sound, sound1, sound2,sound3, mindistance ) 
   setSoundMaxDistance(sound, sound1, sound2, sound3, maxdistance ) 
   if sound then 
        outputDebugString("3D Created successful", 3) 
   else 
        outputDebugString("Error creating 3D", 1) 
   end 
end 
addEventHandler("onClientResourceStart", resourceRoot, soundStart) 

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...