M MY Multiplayer: Wiki
Side
Kind

playSound3D

Client

Plays a sound at a position in the world, on this client only. Its volume falls with distance between setSoundMinDistance (5 m) and setSoundMaxDistance (20 m). Fires onClientSoundStarted with play.

Also exists on the server, with its own implementation: playSound3D

sound|false playSound3D(string sound, float x, y, z [, bool looped = false, bool throttled = true])

Parameters

NameTypeDescription
soundstringA name registered with engineAddSound, the path of a file in the resource (@other/file.mp3 for another resource) or the bytes of an audio file themselves.
x, y, zfloatThe sound's position in the world, as three numbers or one vec3.
loopedboolPlay the sound again from the start when it reaches the end.default false
throttledboolAccepted for MTA compatibility and ignored.default true

Returns

The created sound element, or false if the sound could not be opened.

The sound streams out (onClientElementStreamOut) when the camera is more than 40 m beyond its max distance or in another dimension, and streams back in (onClientElementStreamIn) within 20 m of it.

Example

local pos = getElementPosition(localPlayer)
local radio = playSound3D("sounds/radio.ogg", pos, true)
setSoundMaxDistance(radio, 40)
Coming from MTAInternet addresses (http, ftp) are not accepted. Another resource is named with @resource/, not :resource/.

See also