Cues & playback ​
A cue is approved server data describing an asset, its sound behavior and its
request policy. Server resources call registerCue(id, definition, authorize?)
and receive a namespaced cue ID. Files must exist in their owning resource and
be declared in that resource's manifest.
npAddon.attach('np_audio', function()
exports.np_audio:registerCue('machine', {
file = 'sounds/machine.ogg', durationMs = 2400,
loop = true, category = 'ambience', volume = 0.6,
refDistance = 3, maxDistance = 40,
effects = { occlusion = true, vehicle = true, water = true },
})
end, { api = 1 })
The file owner defaults to the registering resource. A cue may name another
resource explicitly, or use an approved url instead of file. backend='web'
is the default; backend contracts explain other choices.
Play and control ​
local ok, handle = exports.np_audio:play('machine', {
netId = NetworkGetNetworkIdFromEntity(machine),
bucket = GetEntityRoutingBucket(machine),
})
if ok then
exports.np_audio:setVolume(handle, 0.2, { rampMs = 1500 })
-- pause(handle), resume(handle), seek(handle, seconds), stop(handle)
end
play preserves the cue's loop setting. playOneShot forces it off. A caller
controls only its own handles. A copied active source does not change when its
catalog definition is later edited. Source lifetime ends on stop, completion,
owner/asset-resource loss, missing emitters, or the retention ceiling.
Nonspatial cues normally go to the selected bucket. Restrict private feedback
with players={serverId} or use client playLocal('confirm'), which accepts only
the default configured catalog. Loop/transport/volume support is backend-specific;
native soundsets return explicit errors for unsupported controls.
Client requests ​
Client-facing cues must opt into request.enabled. Set an ACE, cooldown and an
optional synchronous server authorization callback appropriate to the interaction.
Clients use requestCue(fullCueId, callback?); the server derives the player's
ped and bucket. Requests cannot contain coordinates, volume, URL, audience,
duration or queue controls. Nonspatial requests target the requester only.
A stationary doorbell should be played from the validated server interaction handler at the server-known door. The generic request path places the source at the player's authoritative ped. See the policy example.
Full cue and playback option schemas are on Exports & events.