High Scripts

Documentation

Server Side Exports

These functions should be used in the server script files.

Server-side exports

API for playing audio

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

AddEventHandler("event", function()
  local sound = exports["high_3dsounds"]:Play3DPos(
    source,                            -- player source *
    "firstSound",                     -- uniqueId *
    vector3(123.0, 123.0, 123.0),      -- position *
    50.0,                              -- distance
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ",  -- sound URL/file name *
    1.0,                               -- volume (0.0–1.0)
    true                               -- looped
  )
end)
#ArgumentExample
1source *1
2uniqueId *"uniqueName"
3position *vector3(123.0, 123.0, 123.0)
4distance50.0
5sound *"fileName" OR "https://youtu.be/dQw4w9WgXcQ"
6volume1.0
7loopedfalse

This export function plays a sound at a specified position.


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

AddEventHandler("event", function()
  local sound = exports["high_3dsounds"]:Play3DEntity(
    source,                                         -- player source *
    NetworkGetNetworkIdFromEntity(PlayerPedId()),    -- entityNetId *
    50.0,                                           -- distance
    "fileName",                                    -- sound URL/file name *
    1.0,                                            -- volume
    true                                            -- looped
  )
end)
#ArgumentExample
1source *1
2entityNetId *NetworkGetNetworkIdFromEntity(PlayerPedId())
3distance50.0
4sound *"fileName" OR "https://youtu.be/dQw4w9WgXcQ"
5volume1.0
6loopedfalse

This export function plays a sound on a specified entity.


Returned data from Play3D* functions

FieldDescriptionType
idSound unique id / namestring/number
entityEntity ID (if used)entity
urlSource URL of the soundstring
volumeCurrent volume (0.0–1.0)number
distanceMax audible distancenumber
positionPlayback positionvector3
loopIs loopedboolean
playedAtCurrent timestamp (seconds)number
destroyOnFinishAuto-destroy on finishboolean

Entity fields appear when using Play3DEntity; position fields when using Play3DPos.


Audio manipulation API

soundVar.modify(source, field, newValue, secondValue)

AddEventHandler("event", function()
  local src   = source
  local sound = exports["high_3dsounds"]:Play3DPos(...)  -- your args
  sound.modify(src, "volume", 1.0)  -- change volume
end)
#ArgumentExample
1source *1
2field *"volume"
3newValue *1.0
4secondValue500 (fade time in ms)

This export function modifies a specified sound property.


soundVar.destroy(source)

AddEventHandler("event", function()
  local src   = source
  local sound = exports["high_3dsounds"]:Play3DPos(...)
  sound.destroy(src)
end)
#ArgumentExample
1source *1

This export function destroys the sound element.


soundVar.replay(source)

AddEventHandler("event", function()
  local src   = source
  local sound = exports["high_3dsounds"]:Play3DPos(...)
  sound.replay(src)
end)
#ArgumentExample
1source *1

This export function replays the sound 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 for further operations.

getSoundData(uniqueId, field)

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

This export function fetches a specific data field (e.g., volume, distance) from the sound object.

Last updated on