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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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

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

Try resourceRoot instead of player

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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.

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

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

Why you no use createProjectile to create the airbomb you want and attach that sound when air bomb hit somewhere?

createProjectile 
isElement 
bindKey 
playSound 
setSoundMaxDistance 

onClientProjectileCreation

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Your function is not retrieving the sent data;

function sbros(drop) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

just add a little delay dude (with setTimer)

Ingame Name: Arnold

If you need my help, contact me on Skype @bshr.ara

NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP

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

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Anytime buddy :)

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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