Elmatus Posted October 21, 2012 Share Posted October 21, 2012 I want tha a sound get reproduced when i close or open the gate, this is my code function openMyGate () moveObject ( myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0 ) end addCommandHandler("opengate",openMyGate) Link to comment
hassan.k.s.a Posted October 21, 2012 Share Posted October 21, 2012 Did you mean this? function openMyGate () moveObject (myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0) sound = playSound ("sounds/opengate.mp3") setSoundVolume (sound, 0.5) end addCommandHandler ("opengate", openMyGate) Link to comment
Castillo Posted October 21, 2012 Share Posted October 21, 2012 @Elmatus: If your script is server side, then what hassan posted won't work, since playSound is client side only. You would need to use triggerClientEvent to trigger a client side event for then play the sound. Link to comment
hassan.k.s.a Posted October 21, 2012 Share Posted October 21, 2012 --Server Side function openMyGate () moveObject (myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0) triggerClientEvent ( "sound", getRootElement()) end addCommandHandler ("opengate", openMyGate) --Client Side function sound() sound = playSound ("sounds/opengate.mp3") setSoundVolume (sound, 0.5) end addEvent( "sound", true ) addEventHandler( "sound", getRootElement(),sound ) Link to comment
Renkon Posted October 21, 2012 Share Posted October 21, 2012 --Server Side function openMyGate (p) moveObject (myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0) triggerClientEvent ( "onGateOpening", p) end addCommandHandler ("opengate", openMyGate) --Client Side addEvent( "onGateOpening", true ) function sound() sound = playSound ("sounds/opengate.mp3") end addEventHandler( "onGateOpening", getRootElement(),sound ) Link to comment
Anderl Posted October 21, 2012 Share Posted October 21, 2012 --Server Side function openMyGate (p) moveObject (myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0) triggerClientEvent ( "onGateOpening", p) end addCommandHandler ("opengate", openMyGate) --Client Side addEvent( "onGateOpening", true ) function sound() sound = playSound ("sounds/opengate.mp3") end addEventHandler( "onGateOpening", getRootElement(),sound ) Small fixes on server side code: addCommandHandler('opengate', function(p) if (moveObject(myGate, 500, -781.20001220703, -2624.8000488281, 104.09999847412, 0, 0, 0)) then triggerClientEvent(p, 'onClientPlayerOpenGate', p) end end ) And client side code: addEvent('onClientPlayerOpenGate', true) addEventHandler('onClientPlayerOpenGate', root, function() playSound('sounds/opengate.mp3') end ) Link to comment
Tete omar Posted October 22, 2012 Share Posted October 22, 2012 Would be awesome if you used playSound3D this function would let the sound be issued in any position you like with the distance feature. Link to comment
Elmatus Posted October 22, 2012 Author Share Posted October 22, 2012 And if i use the playSound3D what its the code? Link to comment
Tete omar Posted October 22, 2012 Share Posted October 22, 2012 playSound3D ( string soundPath, float x, float y, float z, [ bool looped = false ] ) soundPath: the path for the sound you like , e.g. , "sound.mp3". float x , float y, float z : the position you like to run the sound in. looped: A boolean representing whether the sound will be looped. To loop the sound, use true. setSoundMaxDistance ( element sound, int distance ) sound: a sound element. distance: the default value for this is 10. Link to comment
Elmatus Posted October 24, 2012 Author Share Posted October 24, 2012 Like this: playSound3D ( gate.mp3, -756.82775878906, 2842.2609863281, 55.485198974609, [ bool looped = false ] ) setSoundMaxDistance ( gate.mp3, 10 ) ???? And i have to edit the lua and add: <script src="gate.mp3" type="server" /> ?????? Link to comment
Tete omar Posted October 24, 2012 Share Posted October 24, 2012 Like this: playSound3D ( gate.mp3, -756.82775878906, 2842.2609863281, 55.485198974609, [ bool looped = false ] ) setSoundMaxDistance ( gate.mp3, 10 ) ???? And i have to edit the lua and add: <script src="gate.mp3" type="server" /> ?????? local sound = playSound3D ( "gate.mp3", -756.82775878906, 2842.2609863281, 55.485198974609, true ) setSoundMaxDistance ( sound, 10 ) This should be client side. Link to comment
Elmatus Posted October 24, 2012 Author Share Posted October 24, 2012 But i want that when i use /opengate all the players near to me hear the sound, it works for that? Link to comment
Dev Posted October 24, 2012 Share Posted October 24, 2012 You can, use Anderl's code by replace the 'p' variable in the triggerClientEvent with 'getRootElement()' Link to comment
Tete omar Posted October 24, 2012 Share Posted October 24, 2012 But i want that when i use /opengate all the players near to me hear the sound, it works for that? Yes , and here's the code server addCommandHandler('opengate', function(p) if (moveObject(myGate, 500, -781.20001220703, -2624.8000488281, 104.09999847412, 0, 0, 0)) then triggerClientEvent(p, 'onClientPlayerOpenGate', p) end end ) client addEvent('onClientPlayerOpenGate', true) addEventHandler('onClientPlayerOpenGate', root, function() local sound = playSound3D ( "sounds/opengate.mp3", -756.82775878906, 2842.2609863281, 55.485198974609, true ) setSoundMaxDistance ( sound, 10 ) end ) Link to comment
Elmatus Posted October 24, 2012 Author Share Posted October 24, 2012 I used: function openMyGate () moveObject ( myGate1, 14000, -758.40002441406, 2843.1999511719, 50, 0, 0, 0 ) end addCommandHandler("opengate",openMyGate) function sound (p) if (moveObject(myGate, 500, -781.20001220703, -2624.8000488281, 104.09999847412, 0, 0, 0)) then triggerClientEvent(p, 'onClientPlayerOpenGate', p) end end addEvent('onClientPlayerOpenGate', true) But the sound dont get reproduced Link to comment
denny199 Posted October 24, 2012 Share Posted October 24, 2012 BTW, I don't see the element myGate, So i guess that you've got a object scripted in the serverside file. --server function openMyGate () moveObject ( myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0 ) triggerClientEvent ( "playsound", getRootElement()) end addCommandHandler("opengate",openMyGate) --client function sound() sound = playSound3D ("opengate.mp3", -781.20001220703, 2624.8000488281, 104.09999847412, false) setSoundMaxDistance ( sound, 10 ) end addEvent( "playsound", true ) addEventHandler( "playsound", getRootElement(),sound ) meta: <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> <file src="opengate.mp3" type="client" /> 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