High Scripts

Documentation

Client Side Exports

These functions should be used in the client script files.

Client-side exports

API for playing audio

Play3DPos(uniqueId, position, distance, sound, volume, looped)

local sound = exports["high_3dsounds"]:Play3DPos(
  "firstSound",                    -- uniqueId
  vector3(123.0, 123.0, 123.0),     -- position
  50.0,                              -- distance
  "https://www.youtube.com/watch?v=dQw4w9WgXcQ", -- sound URL or file name
  1.0,                               -- volume
  true                               -- looped
)

Arguments

Can't be empty – *

Argument numberArgument nameExample value
1uniqueId*"uniqueName"
2position*vector3(123.0, 123.0, 123.0)
3distance50.0
4sound*"fileName" OR [YouTube URL](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
5volume (0.0–1.0)1.0
6loopedfalse

This export function plays a sound at a specified position.

Play3DEntity(entityNetId, distance, sound, volume, looped)

local sound = exports["high_3dsounds"]:Play3DEntity(
  NetworkGetNetworkIdFromEntity(PlayerPedId()), -- entity net id
  50.0,                                         -- distance
  "fileName",                                  -- sound URL or file name
  1.0,                                          -- volume
  true                                          -- looped
)

Arguments

Can't be empty – *

Argument numberArgument nameExample value
1entityNetId*NetworkGetNetworkIdFromEntity(PlayerPedId())
2distance50.0
3sound*"fileName" OR [YouTube URL](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
4volume (0.0–1.0)1.0
5loopedfalse

This export function plays a sound on a specified entity.

Returned data from Play3D* functions

FieldDescriptionType
idSound unique id / namestring/number
entityEntity IDentity
urlThe source/URL of the soundstring
playingIs the sound playing & loadedboolean
volumeSound volume (0.0–1.0)number
distanceMax distance of the soundnumber
positionPosition of the sound playervector3
vehicleIs entity a vehicleboolean
loopLooped or notboolean
timeStampCurrent timestamp of the videonumber
durationAudio duration in secondsnumber
destroyOnFinishWill the sound element be destroyed on finishboolean
isConvertibleIf entity is a vehicle, is it a convertibleboolean
vehicleClassIf entity is a vehicle, returns its classnumber
doorCountIf entity is a vehicle, returns its door countnumber

Fields highlighted in yellow represent player-related data.

Audio manipulation API

soundVar.addEventListener(event, callback)

local sound = exports["high_3dsounds"]:Play3DPos(...) -- your arguments
sound.addEventListener("onPlay", function()
  print("Playing " .. sound.id)
end)

Arguments

Can't be empty – *

Argument numberArgument nameExample value
1event*"onPlay"
2callback*function() return true end

Events

Event nameDescription
onPlayTriggered when the sound is fully loaded and starts playing.
onFinishedTriggered when the sound finishes playing.
onCreatedTriggered right after the sound is created.
onPauseTriggered when the sound gets paused.
onResumeTriggered when the sound gets resumed.

This export function adds event listeners to the audio element.

soundVar.modify(field, newValue, secondValue)

local sound = exports["high_3dsounds"]:Play3DPos(...) -- your arguments
sound.modify("volume", 1.0)

Arguments

Can't be empty – *

Argument numberArgument nameExample value
1field*"volume"
2newValue*1.0
3secondValue500 (fade time in ms)

Modifiable fields

FieldTypeDescription
volumenumber (0.0–1.0)Volume level (fade time optional)
distancenumberMaximum audible distance
positionvector3Sound position
loopbooleanLooping toggle
timeStampnumber (seconds)Seek position
destroyOnFinishbooleanAuto-destroy toggle

This export function modifies the given sound value.

soundVar.destroy()

local sound = exports["high_3dsounds"]:Play3DPos(...)
sound.destroy()

This export function destroys the sound element.

soundVar.replay()

local sound = exports["high_3dsounds"]:Play3DPos(...)
sound.replay()

This export function replays the audio from the beginning.

Other API functions

getSound(uniqueId)

local sound = exports["high_3dsounds"]:getSound("mySound")
sound.modify("volume", 1.0)

This export function retrieves the sound object.

getSoundData(uniqueId, field)

local volume = exports["high_3dsounds"]:getSoundData("mySound", "volume")
print("Sound volume: " .. volume)

This export function fetches a specific data field from the sound object.

Last updated on