Jump to content

Sound plays multiple times


Recommended Posts

Client:

function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, x, y, z, hitElement) 
    if (weapon == 23) then  
     
   triggerServerEvent ( "playit", getLocalPlayer(), x, y, z )  
  
    end 
end 
addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc) 
  
  
  
function soundplay (x, y, z) 
  
    local sound = playSound3D("Taser.wav", x, y, z, false) 
    setSoundVolume(sound, 1) 
    setSoundMaxDistance(sound, 10) 
  
   setSoundVolume(sound, 3) 
   setSoundMaxDistance(sound, 100) 
   setElementInterior ( sound, 0 ) 
   setElementDimension ( sound, 0 ) 
    
end 
addEvent( "playSound", true ) 
addEventHandler( "playSound", getRootElement(), soundplay ) 

Server:

function playAlarm (x, y, z) 
  
    triggerClientEvent ( "playSound", getRootElement(), x, y, z ) 
end 
addEvent( "playit", true ) 
addEventHandler( "playit", getRootElement(), playAlarm ) 

Basically, I am trying to to play Tazer.wav whenever someone shoots a silenced pistol, but I want the sound to be played to everyone who is within a certian radius of the xyz of the person who shot.

It currently works, but it seems to play the sound for as many people who can hear it.

EG: If I stand by 3 other people and shoot the weapon, the sound will be played 4 times, when it should only play once.

Thanks!

Link to comment
function onClientPlayerWeaponFireFunc ( weapon, ammo, ammoInClip, x, y, z, hitElement ) 
    if ( weapon == 23 ) then 
        local sound = playSound3D ( "Taser.wav", x, y, z, false ) 
        setSoundVolume ( sound, 1 ) 
        setSoundMaxDistance ( sound, 10 ) 
        setSoundVolume ( sound, 3 ) 
        setSoundMaxDistance ( sound, 100 ) 
        setElementInterior ( sound, 0 ) 
        setElementDimension ( sound, 0 ) 
    end 
end 
addEventHandler ( "onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc ) 

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