• How to play impact custom sounds?
    12 replies, posted
Hi guys, my SWEP applies some decals on the walls (like the paint tool) and I would like to add an impact sound. So the source should be the decal itself. In my code there are three functions: creation of decals, primary attack (automatic fire) and secondary attack. The impact sound should be different for each type of attack. Any suggestion or hint? Anyway I think EmitSound is kinda limited, should I use CreateSound? I like the possibility to change dynamically the pitch and the lenght (with a fadeout) of a custom file (it would be the next step). Thanks for the support
You can change pitch and volume, but not length.
[QUOTE=Robotboy655;43512443]You can change pitch and volume, but not length.[/QUOTE] Yeah, sorry... I mean the lenght of the fadeout.
Second argument of ChangeVolume.
Thanks! So no suggestions about the impact sound? I was thinking to get the position where I aim. But how? I need a vector, right?
Callback function of bullet or [url]http://wiki.garrysmod.com/page/WEAPON/DoImpactEffect[/url]
[QUOTE=Robotboy655;43525328]Callback function of bullet or [url]http://wiki.garrysmod.com/page/WEAPON/DoImpactEffect[/url][/QUOTE] Ok, with standard sounds it works, but with custom nope. I did not mention it, sorry.
It means your sound is either: 1) has incorrect sample rate, must 44100 Hz 2) is incorrectly installed 3) has incorrect format ( .wav, .mp3 and .ogg are supported )
[QUOTE=Robotboy655;43534476]It means your sound is either: 1) has incorrect sample rate, must 44100 Hz 2) is incorrectly installed 3) has incorrect format ( .wav, .mp3 and .ogg are supported )[/QUOTE] What do you mean by "incorrectly installed"? Custom sounds work in PrimaryAttack function, but in DoImpactEffect function no. To be more specific, the source is the player and not the decal. It is a problem on the code, not on the file; I am sure. If you want to place a sound where you aim, how could you do it? Thanks.
[url]http://wiki.garrysmod.com/page/Global/EmitSound[/url]
[CODE] function SWEP:DoImpactEffect( tr ) if( tr.Hit && !tr.HitSky ) then local tr = self.Owner:GetEyeTrace() local Pos1 = tr.HitPos + tr.HitNormal local Pos2 = tr.HitPos - tr.HitNormal util.Decal("PaintSplatGreen", Pos1, Pos2) EmitSound( PrimarySound, tr.HitPos, 1, 1, 1, 25, 1, 50) end return true end [/CODE] I am kinda stuck here. The source is not yet from the decal.
[code]sound.Play( PrimarySound, tr.HitPos, level, pitch, volume )[/code] EmitSound is overcomplicated for what you are trying to do.
[QUOTE=Kogitsune;43539930]EmitSound is overcomplicated for what you are trying to do.[/QUOTE] Thanks man, it works!
Sorry, you need to Log In to post a reply to this thread.