Jump to content

3d sound in weapons


BorderLine

Recommended Posts

hi again people of forums :D

well im try to make this script

i want sound in weapons but with some distannce.

my bug is.. dont sound like 3d sound..

if you are away from others players.. you can hear the others weapons sounds..

so im do this.. i dont know what is wrong.. the sounds are good..

but dont wokr the 3d sound

Clientside

  
function onClientPlayerWeaponFire ( weapon ) 
    local Zx, Zy, Zz = getPedWeaponMuzzlePosition ( getLocalPlayer() ) 
     
    if weapon == 22 then--colt45 
            local sound = playSound3D("sounds/Colt45.mp3", Zx, Zy, Zz, false) 
        setSoundMaxDistance(sound, 30) 
    end  
end 
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFire ) 
  
  

The resource is more bigger.. but this is the example :)

thanks

Link to comment
hi again people of forums

well im try to make this script

i want sound in weapons but with some distannce.

my bug is.. dont sound like 3d sound..

if you are away from others players.. you can hear the others weapons sounds..

so im do this.. i dont know what is wrong.. the sounds are good..

but dont wokr the 3d sound

i think he explain you the sound is begin played but you can hear it from distance i took a quick look at the script and look's fine you tryed whit that scirpt ?

Link to comment
i think he explain you the sound is begin played but you can hear it from distance i took a quick look at the script and look's fine you tryed whit that scirpt ?

Nevermind.

  
local function playGunfireSound(weaponID) 
    local muzzleX, muzzleY, muzzleZ = getPedWeaponMuzzlePosition(source) 
    if weaponID == 22 then --colt45 
        local sound = playSound3D("sounds/Colt45.mp3", muzzleX, muzzleY, muzzleZ, false) 
        setSoundMaxDistance(sound, 30) 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", root, playGunfireSound) 
  

1 - This function does not need to be global, so make it local.

2 - It is not a good practice to have function names the same as event names.

3 - You want to find the muzzle position of the source player (the player who shot the weapon), not the local player. If the local player does shoot, however, source will be the local player. So use source.

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