Skip to content

Integration contracts ​

np_audio is a framework-neutral np_addon host at API 1. It uses no framework money/job/player-data API. Server resources supply their own approved policy through cue authorization callbacks and audience filters.

Restart-safe consumer ​

Declare np_addon 'np_audio' in the consumer's manifest and vendor the workspace np_addon library. A consumer which requires audio may instead include shared_script '@np_audio/bridge/np_addon.lua' and explicitly declare dependency 'np_audio'.

lua
npAddon.attach('np_audio', function()
    exports.np_audio:registerCue('machine', {
        file = 'sounds/machine.ogg', -- the consumer's own manifest declares this file
        durationMs = 2400, loop = true, category = 'ambience',
        effects = { occlusion = true, vehicle = true, water = true },
    })
    exports.np_audio:createBus('master', { volume = 0.8 })
    exports.np_audio:createBus('machines', { parent = 'master' })
    -- Recreate world emitters here from the consumer's authoritative world state.
end, { api = 1, label = 'Machine audio' })

On consumer stop, np_audio removes its registrations, buses, scenes, sources, and channels. On host restart, attach runs again. Audio source lifetime is session state; there is no database persistence. A caller using a catalog/asset from a stopped resource also loses that active source rather than keeping a dead file reference. Callback hooks must not yield or enumerate the whole world.

Server-authorized gameplay cue ​

lua
npAddon.attach('np_audio', function()
    exports.np_audio:registerCue('doorbell', {
        file = 'sounds/bell.ogg', durationMs = 2000,
        refDistance = 3, maxDistance = 25,
        request = { enabled = true, cooldownMs = 1500 },
    }, function(player)
        -- Read server-owned interaction/job/permission state here.
        return MyServerInteraction.canUseDoorbell(player)
    end)
end, { api = 1 })

Client: exports.np_audio:requestCue('my_resource:doorbell', callback). This request uses the player's authoritative ped as its source. A stationary doorbell should instead be played from that door's server interaction handler using a server-known coordinate/entity; never send a client coordinate in an unvalidated event to reproduce the server export example.

Music decks and mixers ​

lua
npAddon.attach('np_audio', function()
    local audio = exports.np_audio
    audio:createBus('music', { volume = 0.8 })
    local pa = {
        { coords = vec3(-1600, -3010, 30), refDistance = 8, maxDistance = 50 },
        { coords = vec3(-1615, -3010, 30), refDistance = 8, maxDistance = 50 },
    }
    for _, deck in ipairs({ 'deckA', 'deckB' }) do
        audio:createChannel(deck, { emitters = pa, bucket = 0, bus = 'music' })
    end
end, { api = 1 })

-- Registered file/approved HTTPS cue IDs, not URLs from player input:
exports.np_audio:channelLoad('deckA', 'my_resource:song1')
exports.np_audio:channelQueueAdd('deckA', 'my_resource:song2')
exports.np_audio:crossfadeChannels('deckA', 'deckB', 'my_resource:song3', 4000)

np_screens (optional) ​

Producer: a running np_screens version exposing Audio Channels API 1. Consumer: server/channels.lua. Verified interface sources in this workspace: np_screens-anticheat/server/audio_channels.lua, shared/playback.lua, and config/audio_channels.lua. The main np_screens checkout was on feat/live-channels and had no createAudioChannel API at implementation time; the resource name alone is therefore not a capability claim.

The adapter calls getServerTime, createAudioChannel, destroyAudioChannel, setChannelEmitters, setChannelOptions, channelLoad, channelResume, channelPause, channelSeek, channelStop, and channelSetVolume. It preserves host volume units 0..100 and translates scheduled ramp timestamps into the host clock. Every host channel belongs to np_audio; consumer identities are mapped to separate internal IDs, and consumer stop destroys only that mapping.

np_audio retains the approved catalog and queue clock. Host autoplay/duration probing are disabled so listeners cannot advance np_audio's queue. Two hosts do not run queues for the same channel. getServerTime is checked through a protected export call. A missing host/API gives a clear failure for forced screens and an eligible direct-audio fallback for automatic channels.

preferForMusic = false keeps full np_audio local preferences/effects by default. Set it true to automatically delegate approved URL music when the API exists, or use channel backend = 'screens' / cue backend = 'screens' explicitly. Use web for bundled music, effects, streamer control, HRTF, targeted players, and audience filters. Delegation offers the host's YouTube/media support, queues remain owned here, and host local volume/mute controls remain owned there. The host currently has no public per-channel client gain adapter, so np_audio does not reach into private NPSPrefs/Audio globals. Bus changes reach delegated channels on the server routing interval; ordinary fades use host ramps.

When np_screens stops, direct automatic tracks fall back at their anchored position. Forced/YouTube tracks become unavailable and are restored when its addon ready state or startup signal says the API is available. Old timers check channel identity and generation before changing a restarted or replaced track. Already playing built-in tracks are not interrupted solely because a host starts.

xSound (optional) ​

Producer contract: Xogy/xsound documented client exports. Consumer: client/backends.lua. Configure the resource name in integrations.xsound. Only cues explicitly selecting backend='xsound' use it; other running sounds are untouched. It uses PlayUrl, setTimeStamp, setSoundLoop, setVolume, Pause, Resume, and Destroy, with an isolated np_audio: name prefix. The library's player is nonspatial because np_audio computes listener gain; there is no duplicated distance falloff or claim of HRTF/DSP on this adapter. Missing/restarted backends fall back to Web Audio for direct URLs/files. Each client may have different backend availability; check client capabilities.

InteractSound assets (optional) ​

Producer layout: plunkettscott/interact-sound client API. Consumer: catalog registration and the built-in player. Register a cue with backend='interact_sound', file='client/html/sounds/name.ogg', and duration. np_audio reads the original packaged asset through cfx-nui-<resource> and owns the playback node itself. This preserves stop/seek/loop/mixer/effect control. It never invokes the legacy broadcast events, which cannot return an owned stop handle. Existing callers of those events continue independently.

Other np_* and third-party resources ​

Resources such as housing, entertainment, machines, doors, fire, and NPC dialogue may adopt the stable API through the same consumer pattern. This initial repo does not rewrite their existing sound integrations or assume undocumented exports. NPC dialogue consumers should choose one playback owner to prevent duplicate native and np_audio cues. Voice capture, phone/radio calls and Mumble submixes remain owned by their voice resource; a sound source is not a mic bridge.

For additional audio backends, register a client adapter through registerBackend and a server-approved cue naming it. Your adapter receives an already scoped source plus local gain/effect/position frames, and must report capability limits honestly. Changing event names or units requires a new documented API level.