s&box

Sound Events

Why Sound Events

You just want to play a sound and are annoyed that you have to create a sound event to do it. Here's some of the things sound events can do for you.

  • Define whether sound is 2D or 3D
  • Define how far away you should be able to hear the sound
  • Define the volume
  • Randomly choose between multiple sounds each play
  • Randomly adjust pitch each play
  • Can be fired from animations

Creating Sound Events In Code

You can define a sound event as a static field in any class in your addon. The class doesn't have to be an entity, it could be an empty class made especially to define sound events.

class MyClassName { static SoundEvent AttackSound = new ( "sounds/weapons/gunshot.vsnd" ); }

This will create a sound event called MyClassName.AttackSound.

The VDC describes how to create sound events using the sdk tools. You can ignore this. We're wrapping it like this to make it easier.

Using Sound Events

As stated above, you can trigger sound events from animations. You can also play them in game, through entities.

player.EmitSound( MyClassName.AttackSound ); // play using the SoundEvent directly player.EmitSound( "MyClassName.AttackSound" ); // play using the name

TODO

Add more complicated creation examples once it's coded

Page Links


Special Pages


Wikis

?

Render Time: 16ms

DB GetPage 4
Generate Html 0
SaveChanges (1) 9
Render Body 0
Render Sidebar 0