Development
Sound Events
SoundEvent lets plugins emit game sound events with custom parameters and recipient filters.
Creating Sound Events
You can create a sound event with either constructor.
using var soundEvent = new SoundEvent();
soundEvent.Name = "Weapon_AK47.Single";Or initialize name, volume, and pitch directly:
using var soundEvent = new SoundEvent("Weapon_AK47.Single", volume: 0.8f, pitch: 1.0f);Configuring Core Properties
SoundEvent exposes these primary properties:
Name: sound event nameVolume: volume scalarPitch: pitch scalarSourceEntityIndex: index of the source entity (-1means recipient location)
soundEvent.Name = "Weapon_AK47.Single";
soundEvent.Volume = 0.6f;
soundEvent.Pitch = 1.15f;
soundEvent.SourceEntityIndex = -1;If you already have an entity instance, use the helper method:
soundEvent.SetSourceEntity(sourceEntity);Setting Custom Sound Fields
Use typed setters to write custom sound fields:
soundEvent.SetBool("public.some_flag", true);
soundEvent.SetInt32("public.team", 2);
soundEvent.SetUInt32("public.seed", 123u);
soundEvent.SetFloat("public.volume_override", 0.7f);
soundEvent.SetFloat3("public.position", 100.0f, 200.0f, 300.0f);You can also set vectors directly:
soundEvent.SetFloat3("public.position", position);And read values back when needed:
bool someFlag = soundEvent.GetBool("public.some_flag");
int team = soundEvent.GetInt32("public.team");
uint seed = soundEvent.GetUInt32("public.seed");
float volumeOverride = soundEvent.GetFloat("public.volume_override");
Vector pos = soundEvent.GetFloat3("public.position");Configuring Recipients
Recipients are managed through CRecipientFilter on soundEvent.Recipients.
// Broadcast to everyone
soundEvent.Recipients.AddAllPlayers();
// Or target specific players
soundEvent.Recipients.RemoveAllPlayers();
soundEvent.Recipients.AddRecipient(0);
soundEvent.Recipients.AddRecipient(1);Emitting Sound Events
Use Emit() on main thread contexts.
uint guid = soundEvent.Emit();Use EmitAsync() for non-main-thread contexts.
uint guid = await soundEvent.EmitAsync();Emit() is thread-unsafe. Use EmitAsync() when you are not sure execution is on the main thread.
Reference
See SoundEvent for class details.
See CRecipientFilter for recipient helper methods.