Jump to content

[Help] playSound3D


Recommended Posts

Hello everyone,

I'm making a K9 script and so far everything is working well besides that I can't seem to get the barking part working for everyone thats near the K9, it's only playing the sound for the player that executes the command. Any idea whats wrong here?

function Bark() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local int = getElementInterior(getLocalPlayer()) 
    local dim = getElementDimension(getLocalPlayer()) 
    local px, py, pz = getElementPosition(getLocalPlayer()) 
    if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
        local sound = playSound3D("Barking.wav", x, y, z) 
        setSoundMaxDistance(sound, 40) 
        setElementDimension(sound, dim) 
        setElementInterior(sound, int) 
        attachElements ( sound, getLocalPlayer() ) 
         
        if (isPedInVehicle(getLocalPlayer())) then 
            setSoundVolume(sound, 0.5) 
        else 
            setSoundVolume(sound, 1.0) 
        end 
    end 
end 
addCommandHandler("bark", Bark) 

Link to comment

You have to get player serverside and trigger server event for everyone.

It should look like

-- server 
    addCommandHandler ( "bark", 
        function ( player ) 
            triggerClientEvent ( "barkEvent", player ) 
        end 
    ) 

-- client 
    function Bark () 
        local x, y, z = getElementPosition(source) 
        local int = getElementInterior(source) 
        local dim = getElementDimension(source) 
        local px, py, pz = getElementPosition(source) 
        if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
            local sound = playSound3D("Barking.wav", x, y, z) 
            setSoundMaxDistance(sound, 40) 
            setElementDimension(sound, dim) 
            setElementInterior(sound, int) 
            attachElements ( sound, source ) 
            
            if (isPedInVehicle(source)) then 
                setSoundVolume(sound, 0.5) 
            else 
                setSoundVolume(sound, 1.0) 
            end 
        end 
    end 
    addEvent ( "barkEvent", true ) 
    addEventHandler ( "barkEvent", root, Bark ) 

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