[NodeMod Core]
/ .. / default
Class: default
Defined in: src/core/sound.ts:91
Enhanced sound system providing comprehensive audio functionality for the game server. Handles sound emission, validation, and management with improved defaults and error handling.
Example
// Play a weapon sound
nodemodCore.sound.emitSound({
entity\: player,
channel\: SoundChannel.weapon,
sound\: 'weapons/ak47/ak47-1.wav',
volume\: 0.8,
pitch\: 110
});
// Broadcast ambient sound to all players
nodemodCore.sound.broadcastSound('ambient/music/track1.wav', {
volume\: 0.5,
attenuation\: 0.5
});
// Play client-side sound command
nodemodCore.sound.emitClientSound(player, 'ui/buttonclick');
Constructors
Constructor
new default(
utilService
):NodemodSound
Defined in: src/core/sound.ts:100
Creates a new NodemodSound instance.
Parameters
utilService
Utility service for entity operations
Returns
NodemodSound
Properties
util
private
util:default
Defined in: src/core/sound.ts:93
Utility service for entity operations
Methods
emitSound()
emitSound(
options
):boolean
Defined in: src/core/sound.ts:130
Emits a sound with enhanced validation and default values. Provides better parameter validation and clamping than the basic engine function.
Parameters
options
Sound emission configuration
Returns
boolean
True if sound was emitted successfully, false otherwise
Example
// Basic sound emission
nodemodCore.sound.emitSound({
sound\: 'weapons/ak47/ak47-1.wav'
});
// Advanced sound with all options
nodemodCore.sound.emitSound({
entity\: player,
channel\: SoundChannel.weapon,
sound\: 'weapons/ak47/ak47-1.wav',
volume\: 0.8,
attenuation\: 1.5,
flags\: 0, // Normal playback
pitch\: 110
});
emitClientSound()
emitClientSound(
entity
,soundName
,extension
):boolean
Defined in: src/core/sound.ts:178
Sends a client-side sound command to a specific player.
Uses the client's spk
command to play sounds locally.
Parameters
entity
Target player entity or index
number
| Entity
soundName
string
Name of the sound file (with or without extension)
extension
string
= 'wav'
File extension to append if not present in soundName
Returns
boolean
True if command was sent successfully, false otherwise
Example
// Play UI sound to player
nodemodCore.sound.emitClientSound(player, 'ui/buttonclick');
// Play custom sound with specific extension
nodemodCore.sound.emitClientSound(player, 'custom/notification', 'mp3');
emitAmbientSound()
emitAmbientSound(
position
,sound
,volume
,attenuation
,flags
,pitch
):boolean
Defined in: src/core/sound.ts:222
Emits an ambient sound at a specific 3D position. Useful for environmental sounds, explosions, or location-based audio.
Parameters
position
number
[]
3D coordinates [x, y, z] where the sound originates
sound
string
Path to the sound file
volume
number
= 1.0
Volume level (0.0 to 1.0)
attenuation
number
= 1.0
How quickly sound fades with distance
flags
number
= 0
Sound transmission flags
pitch
number
= 100
Pitch adjustment (1-255, 100 = normal)
Returns
boolean
True if sound was emitted successfully, false otherwise
Example
// Explosion sound at coordinates
nodemodCore.sound.emitAmbientSound(
[100, 200, 50],
'weapons/explode1.wav',
0.9,
2.0
);
// Ambient environmental sound
nodemodCore.sound.emitAmbientSound(
[0, 0, 0],
'ambient/wind/wind1.wav',
0.3,
0.5,
nodemod.SND.SPAWNING
);
broadcastSound()
broadcastSound(
sound
,options
):boolean
Defined in: src/core/sound.ts:261
Broadcasts a sound to all players on the server. Convenient wrapper for playing sounds that everyone should hear.
Parameters
sound
string
Path to the sound file
options
Partial
<EmitSoundOptions
> = {}
Optional sound configuration overrides
Returns
boolean
True if sound was broadcast successfully, false otherwise
Example
// Simple server announcement sound
nodemodCore.sound.broadcastSound('admin/announcement.wav');
// Round start music with custom settings
nodemodCore.sound.broadcastSound('music/roundstart.wav', {
volume\: 0.7,
channel\: SoundChannel.stream,
attenuation\: 0.1
});
stopSound()
stopSound(
entity
,channel
,sound
):boolean
Defined in: src/core/sound.ts:294
Attempts to stop a sound on a specific entity. Uses a workaround by playing a very quiet sound since direct stop may not be available.
Parameters
entity
Target entity or entity index
number
| Entity
channel
number
= SoundChannel.auto
Audio channel to stop
sound
string
= ''
Specific sound to stop (empty for all sounds on channel)
Returns
boolean
True if stop attempt was successful, false otherwise
Example
// Stop all sounds on entity
nodemodCore.sound.stopSound(player);
// Stop weapon channel sounds
nodemodCore.sound.stopSound(player, SoundChannel.weapon);
isValidSound()
isValidSound(
soundPath
):boolean
Defined in: src/core/sound.ts:326
Validates whether a sound file path is valid. Checks for supported file extensions and proper format.
Parameters
soundPath
string
Path to the sound file to validate
Returns
boolean
True if the sound path is valid, false otherwise
Example
// Valid sound files
console.log(nodemodCore.sound.isValidSound('weapons/ak47-1.wav')); // true
console.log(nodemodCore.sound.isValidSound('music/track.mp3')); // true
// Invalid sound files
console.log(nodemodCore.sound.isValidSound('invalid.txt')); // false
console.log(nodemodCore.sound.isValidSound('')); // false
emitMultipleSounds()
emitMultipleSounds(
soundConfigs
):SoundResult
[]
Defined in: src/core/sound.ts:360
Emits multiple sounds in batch with individual result tracking. Useful for playing multiple sounds simultaneously or handling bulk operations.
Parameters
soundConfigs
Array of sound configurations to emit
Returns
Array of results indicating success/failure for each sound
Example
const sounds = [
{ sound\: 'weapons/ak47/ak47-1.wav', entity\: player1, volume\: 0.8 },
{ sound\: 'weapons/deagle/deagle-1.wav', entity\: player2, volume\: 0.9 },
{ sound\: 'items/ammopickup2.wav', volume\: 0.5 }
];
const results = nodemodCore.sound.emitMultipleSounds(sounds);
results.forEach((result, i) => {
if (result.success) {
console.log(`Sound ${i} played successfully`);
} else {
console.log(`Sound ${i} failed\: ${result.error}`);
}
});