---
name: "setMusicEventHandler"
type: command
status: deprecated
replaced_by: ["addMusicEventHandler"]
groups: ["Event Handlers", "Sounds"]
arma3_since: "1.02"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/setMusicEventHandler
revid: 319639
updated: 2022-05-13T09:24:37Z
---

# setMusicEventHandler

*Command · Event Handlers, Sounds · Arma 3 v1.02*

> [!WARNING]
> This command is deprecated. Use [addMusicEventHandler](../commands/addMusicEventHandler.md) instead.

## Description

Sets given music track event handler. Will overwrite other music event handlers.

> [!CAUTION]
> This information is **obsolete**. Use [addMusicEventHandler](../commands/addMusicEventHandler.md) instead as it can stack music event handlers.

## Syntax

```sqf
setMusicEventHandler [type, function]
```

**Parameters:**

- `type`: [String](../topics/String.md) - "MusicStart" or "MusicStop"
- `function`: [String](../topics/String.md) - script to be executed. Passes params array 0: class name of the sound in [CfgMusic](../topics/Description.ext.md#music), 1: event handler id

**Returns:** [Number](../topics/Number.md) - id of the event handler

## Examples

### Example 1

```sqf
_ehID = setMusicEventHandler ["MusicStart", "hint str _this"];
```

### Example 2

```sqf
_ehID = setMusicEventHandler ["MusicStop", "hint str _this"];
```

## See also

[addMusicEventHandler](../commands/addMusicEventHandler.md) · [removeMusicEventHandler](../commands/removeMusicEventHandler.md) · [playMusic](../commands/playMusic.md) · [removeAllMusicEventHandlers](../commands/removeAllMusicEventHandlers.md)

<sub>Source: [BI Community Wiki — setMusicEventHandler](https://community.bistudio.com/wiki/setMusicEventHandler) (revision 319639).</sub>
