Jump to content

playSound3D


WhoAmI

Recommended Posts

Posted

I got this

addCommandHandler("zaczep", 
    function ( ) 
        if (isPedInVehicle(localPlayer)) then 
            local veh = getPedOccupiedVehicle(localPlayer) 
            local x, y, z = getElementPosition(veh) 
            local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) 
            setSoundVolume(sound1, 0.7) 
            setSoundMaxDistance( sound1, 30 ) 
             
            attachElements(sound1, veh) 
        end 
    end 
) 
  
addCommandHandler("odczep", 
    function ( ) 
        if (isPedInVehicle(localPlayer)) then 
            local veh = getPedOccupiedVehicle(localPlayer) 
             
            local elements = getAttachedElements(veh) 
            if (#elements > 0) then 
                for _,sound in ipairs(elements) do 
                    if (getElementType(sound) == "sound") then 
                        destroyElement(sound) 
                    end 
                end 
            end 
        end 
    end 
) 
  

How i can do that all people can hear the sound? Couse only client can hear it.

Posted

That's all?

addCommandHandler("hardbasson", 
    function (player) 
        triggerClientEvent(player, "bassOn", root) 
    end 
) 
  
addCommandHandler("hardbassoff", 
    function (player) 
        triggerClientEvent(player, "bassOff", root) 
    end 
) 

@EDIT: It doesn't work.

Posted

Post the client side, I take it that you have added "bassOn" and "bassOff" events?

Also, if you put "player" at triggerClientEvent, it'll only trigger it to the player who used the command.

Posted
addCommandHandler("hardbasson", 
    function (player) 
        local veh = getPedOccupiedVehicle(player) 
        triggerClientEvent("bassOn", root, veh) 
    end 
) 
  
addCommandHandler("hardbassoff", 
    function (player) 
        local veh = getPedOccupiedVehicle(player) 
        triggerClientEvent("bassOff", root, veh) 
    end 
) 

Client

local sound 
  
addEvent("bassOn", true) 
addEventHandler("bassOn", root, 
    function (veh) 
        if (isPedInVehicle(localPlayer)) then 
            local x, y, z = getElementPosition(veh) 
            local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) 
            setSoundVolume(sound1, 0.7) 
            setSoundMaxDistance( sound1, 30 ) 
             
            attachElements(sound1, veh) 
        end 
    end 
) 
  
addEvent("bassOff", true) 
addEventHandler("bassOff", root, 
    function (veh) 
        if (isPedInVehicle(localPlayer)) then            
            local elements = getAttachedElements(veh) 
            if (#elements > 0) then 
                for _,sound in ipairs(elements) do 
                    if (getElementType(sound) == "sound") then 
                        destroyElement(sound) 
                    end 
                end 
            end 
        end 
    end 
) 
  

It's only for 1 player.

Posted

Well, It works, but it doesn't attach sound to vehicle.

addEvent("bassOn", true) 
addEventHandler("bassOn", root, 
    function () 
        local veh = getPedOccupiedVehicle(localPlayer) 
        local x, y, z = getElementPosition(veh) 
        local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) 
        setSoundVolume(sound1, 0.7) 
        setSoundMaxDistance( sound1, 40 ) 
             
        attachElement(sound1, veh) 
    end 
) 
  
addEvent("bassOff", true) 
addEventHandler("bassOff", root, 
    function (veh) 
        local veh = getPedOccupiedVehicle(localPlayer)   
        local elements = getAttachedElements(veh) 
        if (#elements > 0) then 
            for _,sound in ipairs(elements) do 
                if (getElementType(sound) == "sound") then 
                    destroyElement(sound) 
                end 
            end 
        end 
    end 
) 

Server

addCommandHandler("hardbasson", 
    function (player) 
        triggerClientEvent("bassOn", root) 
    end 
) 
  
addCommandHandler("hardbassoff", 
    function (player) 
        triggerClientEvent("bassOff", root) 
    end 
) 

Posted

Ah yea.

Client:

addEvent("bassOn", true) 
addEventHandler("bassOn", root, 
    function () 
        local veh = getPedOccupiedVehicle(localPlayer) 
        local x, y, z = getElementPosition(veh) 
        local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) 
        setSoundVolume(sound1, 0.7) 
        setSoundMaxDistance( sound1, 40 ) 
             
        attachElements(sound1, veh) 
    end 
) 
  
addEvent("bassOff", true) 
addEventHandler("bassOff", root, 
    function (veh) 
        local veh = getPedOccupiedVehicle(localPlayer)   
        local elements = getAttachedElements(veh) 
        if (#elements > 0) then 
            for _,sound in ipairs(elements) do 
                if (getElementType(sound) == "sound") then 
                    destroyElement(sound) 
                end 
            end 
        end 
    end 
) 
  

Server:

addCommandHandler("hardbasson", 
    function (player) 
        triggerClientEvent("bassOn", root) 
    end 
) 
  
addCommandHandler("hardbassoff", 
    function (player) 
        triggerClientEvent("bassOff", root) 
    end 
) 
  

And know other can't hear this. Only me.

Posted

-- client side:

addEvent ( "bassOn", true ) 
addEventHandler ( "bassOn", root, 
    function ( veh ) 
        local x, y, z = getElementPosition ( veh ) 
        local sound1 = playSound3D ( "sounds/sound.mp3", x, y, z, true ) 
        setSoundVolume ( sound1, 0.7 ) 
        setSoundMaxDistance ( sound1, 40 ) 
        attachElements ( sound1, veh ) 
    end 
) 
  
addEvent ( "bassOff", true ) 
addEventHandler ( "bassOff", root, 
    function ( veh ) 
        local elements = getAttachedElements ( veh ) 
        if ( #elements > 0 ) then 
            for _, sound in ipairs ( elements ) do 
                if ( getElementType ( sound ) == "sound" ) then 
                    destroyElement ( sound ) 
                end 
            end 
        end 
    end 
) 

-- server side:

addCommandHandler ( "hardbasson", 
    function ( player ) 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( veh ) then 
            triggerClientEvent( "bassOn", root, veh ) 
        end 
    end 
) 
  
addCommandHandler ( "hardbassoff", 
    function ( player ) 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( veh ) then 
            triggerClientEvent ( "bassOff", root, veh ) 
        end 
    end 
) 

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