# Opening Music

{% hint style="warning" %}
THIS PAGE IS NOT FINISHED!! Read ahead at your own discretion.
{% endhint %}

## File Location

Opening Music uses the file located in:\
**scripts/vscripts/client/cl\_gamestate.gnut**

## What To Do

Because of the location we write our opening music code in, we need to force it to only run our code one time, because the area we put it in is repeatedly run during the prematch gamestate.\
To do this, at the top we'll establish our integer. In this example we'll call it **startopening** and set it to 0.

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2FAVnO5qhOJ8VY3eJXaWCa%2Fbandicam%202021-09-20%2012-52-37-061.png?alt=media&#x26;token=7f20f06d-4ad0-40d1-85e4-7b0d52581331" alt=""><figcaption></figcaption></figure>

Next, scroll down until you get to **case eGameState.Prematch:**, which should be around line 227.

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2F1Yv4HCqRdSWvNZL8Emy4%2Fbandicam%202021-09-20%2012-55-07-500.png?alt=media&#x26;token=1ae625f8-15a3-498d-8df5-e559f4817610" alt=""><figcaption></figcaption></figure>

In this case, we're going to write an if-statement to check if **startopening** is still **0**.\
At the end of this if statement, we'll change **startopening** to **1**, so it won't run again.

```
                if ( startopening==0 )
                {
                    int musicnumber=RandomInt([number])
                    GetLocalClientPlayer().ClientCommand("opening"+musicnumber)
                    startopening=1
                }
```

Replace **\[number]** with however many opening tracks you're going to have.

Your code should look something like this. Remember to write this stuff **ABOVE** the **break** line.

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2FXSH8SQ9Xey21Fqjj83Ug%2Fassets_-MbT6A_iN6z35klmSlMZ_-Mk3OS9ReDLhvQ1-QQTP_-Mk3PYcChtgCPFtqh6XJ_bandicam%202021-09-20%2013-13-54-300.webp?alt=media&#x26;token=f50e4b19-2e1d-4803-97f3-5e97a3829d15" alt=""><figcaption></figcaption></figure>

## How to Specify/Exclude Game Modes

GAMETYPE specifies what gamemode you're currently playing. Using this we can have music play for specific modes. Below is all the GAMETYPE names on the left and actual mode names on the right for each playable gamemode.

`AI_TDM = Attrition`\
`ATTRITION = Bounty Hunt`\
`CAPTURE_POINT = Amped Hardpoint`\
`LAST_TITAN_STANDING = Last Titan Standing`\
`CAPTURE_THE_FLAG = Capture The Flag`\
`PILOT_SKIRMISH = Pilots VS Pilots`\
`SPEEDBALL = Live Fire`\
`TITAN_BRAWL = Titan Brawl`\
`COLISEUM = Coliseum`\
`MARKED_FOR_DEATH = Marked For Death`

For example, I want specific opening music to be played during LTS and Live Fire, otherwise play something else instead.\
To do that I write 2 if-statements, one checking if the mode *isn't* Live Fire and *isn't* LTS, and one checking if the mode *is* Live Fire or LTS. Squirrel uses **&** for **and**, and **|** for **or**.\
Your checks should look something like this:

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2F4xQYZ6TNhEZFWrx9Hqid%2Fassets_-MbT6A_iN6z35klmSlMZ_-Mkh2-i5s-gruSQBmhPX_-Mkh26VzCsISUxVls_Hf_bandicam%202021-09-28%2010-35-01-174.webp?alt=media&#x26;token=ab3700b7-8f9f-4bec-8674-05bf87cdb461" alt=""><figcaption></figcaption></figure>

## media and autoexec.cfg

As always, put your bik files in the media folder.

<div><figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2FvmmKtwGqNiUNiZCrVHcn%2Fspaces_-MbT6A_iN6z35klmSlMZ_uploads_hfmJcMLmxxuXGCU0Zx9w_bandicam%202021-10-10%2012-29-07-157.webp?alt=media&#x26;token=c5b0a20d-f620-4ba2-bfb6-c3d73d3cbb13" alt=""><figcaption></figcaption></figure> <figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2FikTTm58a6IoFOUzLF4z2%2Fbandicam%202021-10-10%2012-30-33-108.png?alt=media&#x26;token=cf91cf66-a5fd-4889-80ff-96ccf38753c3" alt=""><figcaption></figcaption></figure></div>

The way it's written in autoexec is the same as most sound mods.

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2F9QxOZmLGHeCCwawtjKNp%2Fbandicam%202021-10-10%2012-33-17-910.png?alt=media&#x26;token=f653a18e-a3f8-4ab2-b2e1-f67550265d59" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3229178430-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzWpbBNlNErdKoq8n9DL%2Fuploads%2FwF3Z6agu34ZNoXmj0MaM%2Fbandicam%202021-10-10%2012-32-58-698.png?alt=media&#x26;token=23315ca6-7233-49e5-9064-4c32506942b0" alt=""><figcaption></figcaption></figure>

[Follow this guide for more info about the autoexec and how to properly set it up.](https://captaindiqhedd.gitbook.io/caps-archive-space/caps-titanfall-2-mods-v1/how-to-guides/autoexec.cfg)
