lfnetwork.com mark read register faq members calendar

Thread: Changing Music
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 09-29-2005, 05:39 PM   #1
Fred Tetra
@Fred Tetra
Kotor Tool Guy
Fred Tetra's Avatar
Join Date: Jan 2004
Location: What a creepy photo, eh? Had to use it!
Posts: 947
10 year veteran!  Hot Topic Starter  LFN Staff Member  Helpful! 
Changing Music

Setting music tracks for a new area

(original thread for discussion: http://www.lucasforums.com/showthread.php?t=153072 )

The values you need to set are in the module's .GIT file's AreaProperties structure

The AmbientSnd fields (day and night) are indices into ambientsnd.2da
Here we see that the sound specified for both is "204tel Ambient Bed".
     AmbientSndDay         Field- Type: int           Value: 17
     AmbientSndNight       Field- Type: int           Value: 17
     AmbientSndDayVol      Field- Type: int           Value: 127
     AmbientSndNitVol      Field- Type: int           Value: 127
The EnvAudio field is an index into soundeax.2da. It sets the overall module acoustic model.
Here the default model is specified.
    EnvAudio              Field- Type: int           Value: 0
The music fields are indices into ambientmusic.2da.
Here we see that "Citadel Station" is specified for day and night music, and "Citadel Station Battle" for the battle music.
     MusicBattle           Field- Type: int           Value: 41
     MusicDay              Field- Type: int           Value: 15
     MusicNight            Field- Type: int           Value: 15

Kotor Tool Developer

"You want to help everyone who asks for aid, answer all of their questions, write that crucial bit of code for which they're searching, and be the hero who saves the day (and their job), but there comes a point when you realize that sleep is sometimes necessary."
—Stephen Toub

Visit the Kotor Tool Forum

Last edited by Darth333; 09-30-2005 at 10:49 AM.
Fred Tetra is offline   you may: quote & reply,
Old 09-30-2005, 10:49 AM   #2
Darth333's Avatar
Status: Administrator
Join Date: Feb 2004
Location: In my secret dungeon...
Posts: 8,295
10 year veteran! 
Changing music in an area or during a certain event

( this post summarizes the discussion of this thread: http://lucasforums.com/showthread.php?t=150387 )

1. Adding your custom track to the game:

It is as simple as adding a line to ambientmusic.2da and dropping the new track in .mp3 format in the streammusic folder. It is also possible to replace an existing track. (more details to come)

2. Changing the ambient music and battle music tracks in an area:

It is possible to edit the .git file of an area as described above by Fred Tetra with K-GFF (make sure you are using this gff editor made especially for Kotor and TSL as other editors will corrupt the file) and repack the module with Kotor tool's ERF builder. However, this method is considered overkill when not creating a custom area but simply editing an existing area. When editing the music of an existing area, we recommend using scripts.

(example by stoffe -mbk- )
void main() {
    object oArea = GetArea(OBJECT_SELF);
    // Index in ambientmusic.2da
    int nAmbientMusic = 3;
    int nBattleMusic = 47;
    MusicBattleChange(oArea, nBattleMusic);

    MusicBackgroundChangeDay(oArea, nAmbientMusic);
    MusicBackgroundChangeNight(oArea, nAmbientMusic);
The above script changes the ambient (non-combat) music in the current area to Darth Sion's theme, and the battle music to the Dxun Jungle battle track. Use MusicBackgroundPlay() to play the background new music or MusicBattlePlay() to play the battle music again.

The numbers you specify are indexes in the ambientmusic.2da file (for both ambient and combat music).

You can use those functions to set the ambient and battle music to play the same track in the AreaEnter script or somewhere else suitable. Note that using the AreaEnter event will only change the music until the first battle finishes: after the battle, the music will revert back to the original area tracks.

To avoid reverting back to the old tracks, a script like this one could be inserted in the OnHeartbeat event of the area:
(example by Darth333)
void main()
int nTrack= MusicBackgroundGetDayTrack(oArea);
if nTrack!= 3
	MusicBackgroundChangeDay(oArea, 3, FALSE));
The Heartbeat is an event that usually triggers once every round (every 6 seconds) for some types of objects. The Module, areas, placeables, creatures, triggers, doors etc all have Heartbeat events, while some objects, like items, waypoints and stores/merchants, do not. Heartbeat scripts are useful for things that must be done (or checked for) continually. The creature AI uses them for playing ambient animations (looking around, scratching head etc) and for following you around, for example.

3. Changing the music temporarily during a cutscene or other event:

The music played during a cinematic can be specified in the AmbientTrack field of the .dlg or using a script. If you modify the sound file, the music should change in the cinematics as well.

Here is a sample script that will change the music after 3 seconds and revert back to the original track after 45 seconds:
(by Darth333)
void main()
//Check what's currently playing - lazy method but it's usable in any module 
// and there is no need to manuallt check what's playing
    int nTrack = MusicBackgroundGetDayTrack(oArea);

//Play the desired track - replace number 4 by the ambientmusic.2da row corresponding the the track:: 
    DelayCommand(3.0,MusicBackgroundChangeDay(oArea, 4, FALSE));

// Back to the old track:
    DelayCommand(45.0,MusicBackgroundChangeDay(oArea, nTrack)); 

Want to go fancy and add some fade in/out effect during your cutscene?
Here is an example provided by stoffe -mbk-
void main() {
    SetGlobalFadeOut(0.0, 5.0);
    DelayCommand(5.0, MusicBackgroundStop(GetArea(OBJECT_SELF)));
    SetGlobalFadeIn(6.0, 0.5);  
That should fade to black for 5 seconds. When it reaches black after 5 seconds, it stops the ambient music and fades back in.

You'd have to tweak the timing for when the music stops manually, since there is no way of checking in a script if the music has stopped yet.
Darth333 is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Star Wars Gamer > Community > The Star Forge > Knights of the Old Republic series > Holowan Laboratories > Tutorials > Tutorials: General Tutorials + Tools > Changing Music

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 07:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.