Jump to content

Problem with Stop Sound


Boszor

Recommended Posts

Dear Community,

Where is my mistake here?

Once I enter this command again to stop the sound and another to play.

However, it happens nix and I'm also not so the brightest light in the lua topic.

Would appreciate help. This is for the Police Maverrick.

function speak (player,x,y,z) 
setWorldSoundEnabled 
sound = playSound3D ("song.mp3", x, y, z) 
car = getPedOccupiedVehicle ( player ) 
attachElements(sound,car) 
setSoundMaxDistance( sound, 150 ) 
elseif then 
       if isElement( sound ) then 
       stopSound( sound ) 
    sound = playSound3D ("landing.mp3", x, y, z) 
    setSoundMaxDistance( sound, 150 ) 
end 
  
addEvent ("Ansage", true) 
addEventHandler ("Ansage", getRootElement(), speak ) 

Link to comment

So is it right?

I have really no idea, unfortunately.

I let the way else, but then it works but I can not stop him yet

    function speak (player,x,y,z) 
    setWorldSoundEnabled 
    sound = playSound3D ("song.mp3", x, y, z) 
    car = getPedOccupiedVehicle ( player ) 
    attachElements(sound,car) 
    setSoundMaxDistance( sound, 150 ) 
    else 
        setSoundVolume(sound, 0) 
    end 
      
    addEvent ("Ansage", true) 
    addEventHandler ("Ansage", getRootElement(), speak ) 

Link to comment

What ? Is that your full code or you just removed some stuff from that function?

Here is the fixed code:

function speak (player,x,y,z) 
    setWorldSoundEnabled(!MISSING ARGUMENTS!) 
    sound = playSound3D ("song.mp3", x, y, z) 
    car = getPedOccupiedVehicle ( player ) 
    attachElements(sound,car) 
    setSoundMaxDistance( sound, 150 ) 
    if isElement(sound) then 
        stopSound(sound) 
    end 
    sound = playSound3D ("landing.mp3", x, y, z) 
    setSoundMaxDistance( sound, 150 ) 
end 
addEvent ("Ansage", true) 
addEventHandler ("Ansage", getRootElement(), speak ) 

On line 2 check setWorldSoundEnabled and put the missing arguments in!

Link to comment

Hi, what do you mean by that argument, I would like that it is no longer audible to the police helicopter Maverrick. , But when I enter the Vehicle ID, then I happened nichts.Wenn / announcement Enter H to start song.mp3 of sound and if I / announcement again to stop the sound Enter H song.mp3 and be executed for it landing.mp3.

Link to comment
Hi, what do you mean by that argument, I would like that it is no longer audible to the police helicopter Maverrick. , But when I enter the Vehicle ID, then I happened nichts.Wenn / announcement Enter H to start song.mp3 of sound and if I / announcement again to stop the sound Enter H song.mp3 and be executed for it landing.mp3.

I really can't understand what you want to tell me. If it's not working that's normal ... the arguments in setWorldSoundEnabled aren't set. Remove that line or put the right arguments! There is everything explained in the WIKI!

Link to comment

Assuming the files exist, both of them should work. The issue however, is that you replace the sound almost immediately. You create a sound, playing the song.mp3 file, then you check if this sound is an element - if true, you stop it. Then you start playing landing.mp3 under the same variable.

So basically what you're doing is stopping the sound right after you created it, and then play another one.

Link to comment

you need to send the song name from server side using "triggerClientEvent". Example

Server side

triggerClientEvent(client,"Ansage",client ,"song.mp3") 
-- or  
triggerClientEvent(client,"Ansage",client ,"loading.mp3") 

Client side

function speak (songName) 
    if not songName then return end  
    if (not isPedInVehicle(localPlayer)) then return end 
    if sound and isElement(sound) then 
        destroyElement(sound) 
        sound = nil 
        -- or stopSound(sound) 
    end  
    local theVehicle = getPedOccupiedVehicle (localPlayer) 
    local x,y,z = getElementPosition(theVehicle) 
    sound = playSound3D (songName, x, y, z) 
    attachElements(sound,theVehicle) 
    setSoundMaxDistance(sound, 95) 
end 
addEvent ("Ansage", true) 
addEventHandler ("Ansage", getRootElement(), speak ) 

Link to comment

Did it follow inserted

meta.xml

<meta> 
    <script src="client.lua" type="client"/> 
    <script src="server.lua" type="server"/> 
    <file src="song.mp3"></file> 
    <file src="landing.mp3"></file> 
</meta> 
  

Client - Side

    function speak (songName) 
        if not songName then return end 
        if (not isPedInVehicle(localPlayer)) then return end 
        if sound and isElement(sound) then 
            destroyElement(sound) 
            sound = nil 
            -- or stopSound(sound) 
        end 
        local theVehicle = getPedOccupiedVehicle (localPlayer) 
        local x,y,z = getElementPosition(theVehicle) 
        sound = playSound3D (songName, x, y, z) 
        attachElements(sound,theVehicle) 
        setSoundMaxDistance(sound, 100) 
    end 
    addEvent ("Ansage", true) 
    addEventHandler ("Ansage", getRootElement(), speak ) 

Server - Side

    triggerClientEvent(client,"Ansage",client ,"song.mp3") 
    -- or 
    triggerClientEvent(client,"Ansage",client ,"landing.mp3") 

However, the desired success because unfortunately still do not. Also you hear the normal sound of the helicopter.

It is still the first landing.mp3 played instead the start.mp3

Link to comment

Server Side

addCommandHandler("stop1", function(playerSource, cmd) 
    triggerClientEvent(playerSource, "Ansage", playerSource, "song.mp3"); 
end); 
  
addCommandHandler("stop2", function(playerSource, cmd) 
    triggerClientEvent(playerSource, "Ansage", playerSource, "landing.mp3"); 
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...