Sound In Code: Difference between revisions
m (Nesciuse moved page Sound In Code/en to Sound In Code without leaving a redirect: Move en subpage to basepage) |
Ninjaofsauce (talk | contribs) (Added code for inserting sound into the Sounds List) |
||
Line 28: | Line 28: | ||
</source> | </source> | ||
== Inserts sounds == | |||
<source lang="cpp"> | |||
#include "soundent.h" | |||
CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_PISTOL, 0.2, GetOwner() ); | |||
</source> | |||
''InsertSound(TYPE OF SOUND, Origin of noise, Volume Level, Duration, owner)'' | |||
'''Type of Sound''' is used to control how sounds are heard in the world. ''ex:'' SOUND_COMBAT allows '''AI/NPCs''' to react to sounds. | |||
* {{ent|ai_sound}} | |||
* {{ent|soundent}} | |||
[[Category:Sound System]] | [[Category:Sound System]] | ||
[[Category:Programming]] | [[Category:Programming]] |
Revision as of 13:25, 27 October 2024
Emit sound from entity
Use EmitSound
to emit a sound from a base entity:
EmitSound( "soundscript.file" );
The sound will follow whichever entity it is assigned to, based on the entity index provided to EmitSound
. If an entity index is provided, the position overload argument will not affect the position of the sound; to override this behaviour and have the sound play at the desired point in space, pass in -1 as the entity index:
EmitSound( filter, -1, "Weapon_ProxyBomb.LeadIn", &soundPosition );
See the CSoundEmitterSystem
class in SoundEmitterSystem.cpp for overloads and implementation details.
Play sounds anywhere
To play a sound on the client and without spatialisation (i.e. as an "ambient" sound), use the following code:
enginesound->EmitAmbientSound( "link/to/soundfile", 1.0f );
You may need to include #include "engine/ienginesound.h"
in order to get access to the interface.
Play sounds via VGUI interface
#include "vgui/ISurface.h"
#include "vgui_controls/Controls.h"
using namespace vgui;
surface()->PlaySound( "common/talk.wav" ); // Starts from the 'sound' folder
Inserts sounds
#include "soundent.h"
CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_PISTOL, 0.2, GetOwner() );
InsertSound(TYPE OF SOUND, Origin of noise, Volume Level, Duration, owner)
Type of Sound is used to control how sounds are heard in the world. ex: SOUND_COMBAT allows AI/NPCs to react to sounds.