Skip to content

Placed speakers ​

An output only speaker has no library and no control point. A player connects a device to it from Play on and plays through it. It is how placeable objects (a boombox, a speaker on a stand) become music outputs without tm_music knowing about them.

A resource that places objects registers a speaker when one is placed, moves it with the object, and removes it when the object is picked up. Speakers a resource registered also go when that resource stops.

lua
-- when the object is placed
local name = exports.tm_music:RegisterSpeaker({
    id = placeableId,                 -- any string or number, unique among speakers
    label = 'Boombox',
    coords = vec3(-1037.0, -2737.0, 20.0),   -- a fixed speaker, or netId = entityNetId for one that follows an entity
    distance = 15.0,                  -- how far it carries, in meters
    volume = 60,
    connectRange = 6.0,               -- how close a player must be to connect
    ownerIdentifier = ownerCharId,    -- optional: only this character can connect
    groups = { police = 0 },          -- optional: a job, gang or group filter
})

-- when it is moved
exports.tm_music:UpdateSpeaker(placeableId, { coords = newCoords })

-- when it is picked up
exports.tm_music:RemoveSpeaker(placeableId)

RegisterSpeaker returns the deck name (speaker:<id>) or nil and a reason. Registering an id twice returns the existing name.

A speaker is controlled by one player at a time like a booth, can be linked as an extra speaker to a device's connection, and can be lent to a script with AttachSource.

Check for the feature before calling it from a resource that may meet an older tm_music:

lua
local features = GetResourceMetadata('tm_music', 'music_features', 0) or ''
local hasSpeakers = features:find('speakers', 1, true) ~= nil