BlackS Posted August 22, 2011 Share Posted August 22, 2011 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
JR10 Posted August 22, 2011 Share Posted August 22, 2011 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
BlackS Posted August 22, 2011 Author Share Posted August 22, 2011 Thanks for the fast response! META: <?xml version="1.0"?> -type="script" version="1" author="BlackS"/> "music.mp3"/> Link to comment
JR10 Posted August 22, 2011 Share Posted August 22, 2011 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
BlackS Posted August 22, 2011 Author Share Posted August 22, 2011 Still didn't worked, I don't know it! Did I selected the correct area? and can I upload this 1 also in MTA 1.1? Link to comment
JR10 Posted August 22, 2011 Share Posted August 22, 2011 You are outputting debug messages, you should see it. Use /debugscript 3 The lua file name must be: client.lua Link to comment
BlackS Posted August 22, 2011 Author Share Posted August 22, 2011 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
BlackS Posted August 22, 2011 Author Share Posted August 22, 2011 Decided to make it a stream script. I've added my radio channel but it says there are illegal characters on it? Its a listen2myradio client so I copied the url. its like: radio.listen2myradio.com Link to comment
BlackS Posted August 23, 2011 Author Share Posted August 23, 2011 None can help me out with this 1? Link to comment
Arran Posted August 23, 2011 Share Posted August 23, 2011 You need to set the min and max distance of the 3d sound using: https://wiki.multitheftauto.com/wiki/SetSoundMinDistance https://wiki.multitheftauto.com/wiki/SetSoundMaxDistance Link to comment
BlackS Posted August 23, 2011 Author Share Posted August 23, 2011 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
Arran Posted August 23, 2011 Share Posted August 23, 2011 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))" Link to comment
Jaysds1 Posted August 23, 2011 Share Posted August 23, 2011 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
BlackS Posted August 23, 2011 Author Share Posted August 23, 2011 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 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
SDK Posted August 24, 2011 Share Posted August 24, 2011 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
CapY Posted August 24, 2011 Share Posted August 24, 2011 Is it possible to play more sounds with that script ? Link to comment
CapY Posted August 24, 2011 Share Posted August 24, 2011 can you give me a function(s) ? Link to comment
CapY Posted August 24, 2011 Share Posted August 24, 2011 but what syntax do i need to play more sounds , like one after second. Link to comment
JR10 Posted August 24, 2011 Share Posted August 24, 2011 Use playSound several times. Link to comment
CapY Posted August 24, 2011 Share Posted August 24, 2011 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
CapY Posted August 24, 2011 Share Posted August 24, 2011 Okay fixed , but still all the songs starts in the same time - 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