dewu Posted February 5, 2015 Share Posted February 5, 2015 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
xeon17 Posted February 5, 2015 Share Posted February 5, 2015 (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 February 5, 2015 by Guest Link to comment
Castillo Posted February 5, 2015 Share Posted February 5, 2015 That won't work, since the client side will surely load slower than the server side. Link to comment
dewu Posted February 5, 2015 Author Share Posted February 5, 2015 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
dewu Posted February 5, 2015 Author Share Posted February 5, 2015 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. Link to comment
-.Paradox.- Posted February 6, 2015 Share Posted February 6, 2015 Try resourceRoot instead of player Link to comment
dewu Posted February 6, 2015 Author Share Posted February 6, 2015 Like that? addEventHandler("onResourceStart",resourceRoot, function() triggerClientEvent(resourceRoot,"airdropSound",resourceRoot) end) Still not working. Link to comment
xeon17 Posted February 6, 2015 Share Posted February 6, 2015 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. Link to comment
dewu Posted February 6, 2015 Author Share Posted February 6, 2015 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
-.Paradox.- Posted February 6, 2015 Share Posted February 6, 2015 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 Link to comment
dewu Posted February 6, 2015 Author Share Posted February 6, 2015 I have already complete script contains dropping I just need attach 3D sound to object, that's it. Link to comment
Dealman Posted February 6, 2015 Share Posted February 6, 2015 Your function is not retrieving the sent data; function sbros(drop) Link to comment
Arnold-1 Posted February 6, 2015 Share Posted February 6, 2015 just add a little delay dude (with setTimer) Link to comment
Dealman Posted February 7, 2015 Share Posted February 7, 2015 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
dewu Posted February 7, 2015 Author Share Posted February 7, 2015 Okay, i do it Thank you so much, Dealman. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now