Jump to content

Reproduce a sound when the door opens


Elmatus

Recommended Posts

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

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

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

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

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