cobalt_sound
Server-authoritative 2D and 3D audio from files and URLs.
| Export | Side | What it does |
|---|---|---|
Play | Server, Client | Starts a sound with exactly one of coords, entity or player. |
PlayFrontend | Server, Client | Plays a 2D sound for one player. |
PlayAt | Server, Client | Plays a 3D sound at a world position. |
PlayOnEntity | Server, Client | Plays a 3D sound that follows a networked entity. |
Stop | Shared | Stops a sound; on the client only sounds that player started. |
Pause | Shared | Pauses a sound. |
Resume | Shared | Resumes a paused sound. |
Seek | Shared | Moves a sound's playhead. |
SetVolume | Shared | Sets a sound's volume. |
SetLoop | Shared | Turns looping on or off. |
Play
ServerStarts a sound with exactly one of coords, entity or player.
exports.cobalt_sound:Play(data)| Parameter | Type | Optional | Description |
|---|---|---|---|
data | SoundData | No |
| Returns | Description |
|---|---|
integer? | id |
string? | error |
local id, error = exports.cobalt_sound:Play(
{ sound = 'cash_register', coords = vector3(25.7, -1347.3, 29.5), volume = 0.8, distance = 15.0 }
)Client
Asks the server to start a sound; the target must be near or be the local player, and a coords sound plays in the player's routing bucket. distance is capped at ClientRange. The sound stops when the calling resource stops, and a world sound also after ClientLifetime seconds.
exports.cobalt_sound:Play(data)| Parameter | Type | Optional | Description |
|---|---|---|---|
data | SoundData | No |
| Returns | Description |
|---|---|
integer | false | id |
string? | error |
local id, error = exports.cobalt_sound:Play(
{ sound = 'cash_register', coords = vector3(25.7, -1347.3, 29.5), volume = 0.8, distance = 15.0 }
)PlayFrontend
ServerPlays a 2D sound for one player.
exports.cobalt_sound:PlayFrontend(target, sound, volume)| Parameter | Type | Optional | Description |
|---|---|---|---|
target | integer | No | server id, or -1 for everyone |
sound | string | No | |
volume | number | Yes | 0 to 1 |
| Returns | Description |
|---|---|
integer? | id |
string? | error |
local id, error = exports.cobalt_sound:PlayFrontend(source, 'cash_register', 0.5)Client
Plays a file from sounds/ locally with no id.
exports.cobalt_sound:PlayFrontend(sound, volume)| Parameter | Type | Optional | Description |
|---|---|---|---|
sound | string | No | file in sounds/, as name or name.ogg |
volume | number | Yes | 0 to 1 |
exports.cobalt_sound:PlayFrontend('cash_register', 0.5)PlayAt
ServerPlays a 3D sound at a world position.
exports.cobalt_sound:PlayAt(coords, sound, volume, distance)| Parameter | Type | Optional | Description |
|---|---|---|---|
coords | vector3 | No | |
sound | string | No | |
volume | number | Yes | 0 to 1 |
distance | number | Yes | meters |
| Returns | Description |
|---|---|
integer? | id |
string? | error |
local id, error = exports.cobalt_sound:PlayAt(
vector3(215.8, -810.1, 30.7),
'cash_register',
0.5,
10.0
)Client
Asks the server to play a 3D sound at a world position.
exports.cobalt_sound:PlayAt(coords, sound, volume, distance)| Parameter | Type | Optional | Description |
|---|---|---|---|
coords | vector3 | No | |
sound | string | No | |
volume | number | Yes | 0 to 1 |
distance | number | Yes | meters |
| Returns | Description |
|---|---|
integer | false | id |
string? | error |
local id, error = exports.cobalt_sound:PlayAt(
vector3(215.8, -810.1, 30.7),
'cash_register',
0.5,
10.0
)PlayOnEntity
ServerPlays a 3D sound that follows a networked entity.
exports.cobalt_sound:PlayOnEntity(netId, sound, volume, distance)| Parameter | Type | Optional | Description |
|---|---|---|---|
netId | integer | No | |
sound | string | No | |
volume | number | Yes | 0 to 1 |
distance | number | Yes | meters |
| Returns | Description |
|---|---|
integer? | id |
string? | error |
local id, error = exports.cobalt_sound:PlayOnEntity(
NetworkGetNetworkIdFromEntity(vehicle),
'cash_register',
0.5,
10.0
)Client
Asks the server to play a 3D sound that follows a networked entity.
exports.cobalt_sound:PlayOnEntity(netId, sound, volume, distance)| Parameter | Type | Optional | Description |
|---|---|---|---|
netId | integer | No | |
sound | string | No | |
volume | number | Yes | 0 to 1 |
distance | number | Yes | meters |
| Returns | Description |
|---|---|
integer | false | id |
string? | error |
local id, error = exports.cobalt_sound:PlayOnEntity(
NetworkGetNetworkIdFromEntity(vehicle),
'cash_register',
0.5,
10.0
)Stop
SharedStops a sound; on the client only sounds that player started.
exports.cobalt_sound:Stop(id)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:Stop(1)Pause
SharedPauses a sound.
exports.cobalt_sound:Pause(id)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:Pause(1)Resume
SharedResumes a paused sound.
exports.cobalt_sound:Resume(id)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:Resume(1)Seek
SharedMoves a sound's playhead.
exports.cobalt_sound:Seek(id, seconds)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No | |
seconds | number | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:Seek(1, 30.0)SetVolume
SharedSets a sound's volume.
exports.cobalt_sound:SetVolume(id, volume)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No | |
volume | number | No | 0 to 1 |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:SetVolume(1, 0.5)SetLoop
SharedTurns looping on or off.
exports.cobalt_sound:SetLoop(id, loop)| Parameter | Type | Optional | Description |
|---|---|---|---|
id | integer | No | |
loop | boolean | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_sound:SetLoop(1, true)