Jump to content

playSound3D


LT Uranus

Recommended Posts

Posted

server side

  
function zalu1 () 
triggerClientEvent ( "ads1", getRootElement() ) 
end  
addCommandHandler ( "c1", zalu1 ) 
  

client side

  
function copythat ( player ) 
            local player = getLocalPlayer ( ) 
        local Zx,Zy,Zz = getElementPosition( player ) 
                local ef3 = playSound3D("sounds/copythat.wav", Zx, Zy, Zz, false) 
        setSoundMaxDistance(ef3, 15) 
                setSoundVolume(ef3, 0.5)                  
end 
addEvent( "ads1", true ) 
addEventHandler( "ads1", getRootElement(), copythat ) 
  

hey everyone ,

so i want to make "voice commands" with typing /.. ;

anyway i got this - i can hear it 3D sound myself but the people next to me - can't hear it in 3D , also it plays same sound for all players while it should be only 3D in specific location,idkn should it be attached to that player somehow or saving then uplaoding player's cordinates data would help, how it could be realy 3D like this only attached to command using players ( moving or idle ) location ? =

  
function onResourceStart() 
    local sound = playSound3D("sounds/song.mp3", 373.14, -125.21, 1001, true)  
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart) 
  

thanks :)

in game nick [LT]Daros

real join date 2007 ~

Posted (edited)

I don't get what do you want, you want to play a sound around the player who typed /c1 command? if so try this:

-- client side:

local sounds = {} 
  
addEvent("createNewSound",true) 
addEventHandler("createNewSound",root, 
function (player) 
      local x, y, z = getElementPosition(player) 
      sounds[player] = playSound3D("sounds/copythat.wav", x, y, z, false) 
end) 
  
function updateSoundPositions() 
     for player, sound in pairs(sounds) do 
           if isElement(player) and isElement(sound) then 
                setElementPosition(sound, getElementPosition(player)) 
           end 
     end 
end 
setTimer(updateSoundPositions,2000,0) 

-- server side:

addCommandHandler("c1", 
function (player) 
     triggerClientEvent("createNewSound",getRootElement(),player) 
end) 

Edited by Guest

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

yes i want this effect like someone is talking etc and people next to him can hear it ; with ur scripts i dont have any sounds playng at all when i type /c1 nothing happens :)

in game nick [LT]Daros

real join date 2007 ~

Posted
local sounds = {} 
  
addEvent("createNewSound",true) 
addEventHandler("createNewSound", root, 
function (player) 
      local x, y, z = getElementPosition(player) 
      sounds[player] = playSound3D("sounds/copythat.wav", x, y, z, false) 
      setTimer(updateSoundPositions,100,0) 
end) 
  
function updateSoundPositions() 
     for player, sound in pairs(sounds) do 
           if isElement(player) and isElement(sound) then 
                setElementPosition(sound, getElementPosition(player)) 
           end 
     end 
end 

CiTLh.png
Posted

Yep, I forgot to add the updateSoundPositions timer, but you shouldn't add it every time a sound creates.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

yep true, but you forgot a thing :D

addEventHandler("createNewSound", 

should be

addEventHandler("createNewSound", root, 

also less timer would be more better :roll:

CiTLh.png
Posted

You're welcome :D.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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