Jump to content

PlaySound3D


dewu

Recommended Posts

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?

Link to comment

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
Link to comment
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' 
  

Link to comment

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.

Link to comment

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

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