Jump to content

PlaySound3D


dewu

Recommended Posts

Posted

Hi guys.

Im trying to add 3D sound to plane airdrop.

Server side:

drop = createObject(2903, xpvq,ypvq,zpvq, 0, 0, 0) 
triggerClientEvent("airdropSound",root) 

Client side:

addEvent("airdropSound", true) 
addEventHandler("airdropSound", root 
function ( ) 
    getit = getElementPosition( drop ) 
    local sound = playSound3D("drop.mp3", getit) 
    setSoundMaxDistance(sound, 200) 
   end 
  ) 

and it's not working, no errors.

What i'm doing wrong?

Posted (edited)

Server

  
drop = createObject(2903, xpvq,ypvq,zpvq, 0, 0, 0) 
addEventHandler("onResourceStart",resourceRoot, 
function() 
 for _, player in ipairs(getElementsByType("player")) do 
triggerClientEvent(player,"airdropSound",player) 
end) 
  
  

Client:

addEvent("airdropSound", true) 
addEventHandler("airdropSound", root 
function ( ) 
    x,y,z = getElementPosition( source ) 
    local sound = playSound3D("drop.mp3", x,y,z) 
    setSoundMaxDistance(sound, 200) 
   end 
  ) 

@Edit,

This should also work

addCommandHandler("music", 
function () 
    x,y,z = getElementPosition( localPlayer ) 
    local sound = playSound3D("drop.mp3", x,y,z) 
    setSoundMaxDistance(sound, 200) 
   end 
  ) 

Edited by Guest
Posted
Server
  
drop = createObject(2903, xpvq,ypvq,zpvq, 0, 0, 0) 
addEventHandler("onResourceStart",resourceRoot, 
 for _, player in ipairs(getElementsByType("player")) do 
triggerClientEvent(player,"airdropSound",player) 
end) 
  
  

Client:

addEvent("airdropSound", true) 
addEventHandler("airdropSound", root 
function ( ) 
    x,y,z = getElementPosition( source ) 
    local sound = playSound3D("drop.mp3", x,y,z) 
    setSoundMaxDistance(sound, 200) 
   end 
  ) 

@Edit,

This should also work

addCommandHandler("music", 
function () 
    x,y,z = getElementPosition( localPlayer ) 
    local sound = playSound3D("drop.mp3", x,y,z) 
    setSoundMaxDistance(sound, 200) 
   end 
  ) 

  
ERROR: Loading script failed: drop\avia.lua:596: unexpected symbol near 'for' 
  

Posted
Copy my code again.

Still it's not working.

Also you forgot end to close for.

That won't work, since the client side will surely load slower than the server side.

There must be some way to do that.

Posted

Like that?

addEventHandler("onResourceStart",resourceRoot, 
function() 
  
triggerClientEvent(resourceRoot,"airdropSound",resourceRoot) 
  
end) 

Still not working.

Posted

Can you tell us , what are you trying to do. Instead of using a trigger , you could play the music on client side for everybody when the resource start or with a command.

Posted

I trying to add flying plane sound to aidropping plane (object).

This is moving plane object:

function sbros() 
drop = createObject(1683, xpvq,ypvq,zpvq, 0, 0, 0)  
moveObject(drop, 15000, xpsq,ypsq,zpsq) 
end 

and i want to add them 3D sound, hearable to every players on distance 200 meters.

I don't want any command, my script is auto dropping every 2 hours.

Posted

Dewu, read the wiki pages about triggerClientEvent and triggerServerEvent more thoroughly.

For example, if you create a object via the server, and you want a client(or more than one) to do something with this element - you need to pass the data, like this;

triggerClientEvent(whoToSendTo, "TheEventName", resourceRoot, Data1, Data2) 

For example you can use either root or resourceRoot as the first argument, this will trigger the event for all players currently on the server.

Or, you could specify specific player elements.

Then client-side you have to fetch this data, and you do that via the function;

function exampleCode(Argument1, Argument2, Argument3) 

Here, Argument1 will be whatever Data1 is. Argument2 will be whatever Data2 is - and Argument3 will return nil.

I'm sure you can figure the rest out by yourself from here on. :)

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