wesleywillems17 Posted May 10, 2016 Share Posted May 10, 2016 Hello, I have made a little script but i can't stop the playSound3D It starts when you use the command start and it needs to stop when you use the command stop. But i get a error in debug Client: function startSiren() local sirenSound = playSound3D( 'siren.mp3', 2097.00, -1629.59, 18.79, true ) setSoundVolume(sirenSound,100) end addCommandHandler ( "start", startSiren ) function stopSiren() stopSound(sirenSound) end addCommandHandler ( "stop", stopSiren ) meta.xml Debug: WARNING: (SARS)Siren/client:8 Bad argument @ 'stopSound' [expected sound at argument 1, got nill] What did i do wrong? Link to comment
MACIEKW89 Posted May 10, 2016 Share Posted May 10, 2016 Hi, Try with that : local sirenSound function startSiren() sirenSound = playSound3D("siren.mp3", 2097.00, -1629.59, 18.79, true) setSoundVolume(sirenSound,100) end addCommandHandler("start", startSiren) function stopSiren() stopSound(sirenSound) end addCommandHandler("stop", stopSiren) Or try with that : addCommandHandler("start", function() local sirenSound = playSound3D("siren.mp3", 2097.00, -1629.59, 18.79, true) setSoundVolume(sirenSound,100) addCommandHandler("stop", function() stopSound(sirenSound) end) end) Link to comment
Walid Posted May 11, 2016 Share Posted May 11, 2016 Sorry i'm using the phone. function speaker(cmd) if cmd == "start" then sirenSound = playSound3D( 'siren.mp3', 2097.00, -1629.59, 18.79, true ) setSoundVolume(sirenSound,100) elseif cmd == "stop" then if isElement(sirenSound) then stopSound(sirenSound) end end addCommandHandler ( "start", speaker ) addCommandHandler ( "stop", speaker ) Link to comment
Abdul KariM Posted May 11, 2016 Share Posted May 11, 2016 Sorry i'm using the phone. function speaker(cmd) if cmd == "start" then sirenSound = playSound3D( 'siren.mp3', 2097.00, -1629.59, 18.79, true ) setSoundVolume(sirenSound,100) elseif cmd == "stop" then if isElement(sirenSound) then stopSound(sirenSound) end end addCommandHandler ( "start", speaker ) addCommandHandler ( "stop", speaker ) if wrote " start " and sound is started ?, will be sound repeated And minus " end " use : function speaker( cmd ) if cmd == "start" then if isElement ( sirenSound ) then destroyElement ( sirenSound ) end sirenSound = playSound3D( 'siren.mp3', 2097.00, -1629.59, 18.79, true ) setSoundVolume(sirenSound,100) elseif cmd == "stop" then if isElement( sirenSound ) then destroyElement ( sirenSound ) end end end addCommandHandler ( "start", speaker ) addCommandHandler ( "stop", speaker ) or : function speaker( cmd ) if cmd == "start" then if isElement ( sirenSound ) then return end sirenSound = playSound3D( 'siren.mp3', 2097.00, -1629.59, 18.79, true ) setSoundVolume(sirenSound,100) elseif cmd == "stop" then if isElement( sirenSound ) then destroyElement ( sirenSound ) end end end addCommandHandler ( "start", speaker ) addCommandHandler ( "stop", speaker ) Good luck Link to comment
wesleywillems17 Posted May 11, 2016 Author Share Posted May 11, 2016 Thx for the help! This code works: addCommandHandler("start", function() local sirenSound = playSound3D("siren.mp3", 2097.00, -1629.59, 18.79, true) setSoundVolume(sirenSound,100) addCommandHandler("stop", function() stopSound(sirenSound) end) end) 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