# Exports & Events

## Server Sided Exports

### Play Sound On Entity

> This export will play a sound on an entity, and regulate the volume based on your distance from it. It is dynamic and keeps following the entity.\
> \
> **Example:**
>
> ```lua
> ---@param entity integer
> ---@param id? string @Only needed if you want to manually stop the sound
> ---@param soundName string | string[] @Sound name, or list of them, will choose randomly from list every time PlaySound(JS) executes
> ---@param maxVolume number @0.0-1.0, the max volume for the sound, usually ~0.2
> ---@param maxDistance number @0.0-x, the max distance to hear your sound, usually ~2.0
> ---@param looped boolean | number | {[1]: number, [2]: number} @Basic looping, loop with time between, loop with random time between
> ---@param playCount? integer @If not looping, you can decide how many times the audio will play
> ---@return string @Sound id
> exports["zyke_sounds"]:PlaySoundOnEntity(entity, id, soundName, maxVolume, maxDistance, looped, playCount)
> ```

### Stop Sound

> Manually stop a sound playing. Allows you to fade it out or keep playing it until it ends. We do un-register the audio when fading or forcing the full to be played, so the same id can be re-used.\
> \
> **Example:**
>
> ```lua
> ---@param soundId string
> ---@param fade? number @In milliseconds, how long to fade the sound out for to avoid abrupt interruption
> ---@param forceFull? boolean @Force the audio to play out fully instead of cutting off, ignores fade
> exports["zyke_sounds"]:StopSound(soundId, fade, forceFull)
> ```

### Does File Exist

> Verify the existence of the sound file in zyke\_sounds. This is more expensive than DoesSoundExist since we are fetching the actual file instead of a quick table lookup.\
> \
> **Example:**
>
> ```lua
> ---@param fileName string
> ---@return boolean
> exports["zyke_sounds"]:DoesFileExist(fileName)
> ```

### Does Sound Exist

> Lightweight export to quickly validate if a sound has been loaded into memory on script start.\
> \
> **Example:**
>
> ```lua
> ---@param fileName string
> ---@return boolean
> exports["zyke_sounds"]:DoesSoundExist(fileName)
> ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zykeresources.com/free-resources/sounds/exports-and-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
