Jump to content

stop playSound3D


Recommended Posts

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

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

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

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

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