Tutorial: Scripting music for a cell

Post » Fri Apr 08, 2011 3:14 am

I've seen a lot of questions on asking for special music without interruptions from the vanilla music for specific areas. This is a tutorial for that, which I tasked ShadowLance to create for a mod. The scripting was created by ShadowLance and TheNiceOne, originally used in Underdark.

So.. you're wondering, "How can I place a specific piece of music in this cell without messing up the entire default folder and making sure that only this song plays?" I don't mean sticking a CD in the pc and listening to something else. What I intend to do here is show how modders can create a way to play a specific song in specific place. How?

Easily! First you need the song, then a quest and a little scripting. As most modders know - cells, regions and worldspaces are where we create our music settings. They are set to either "Default, Dungeon, or Public". However, modders also know that you cannot just make one song play in a certain area alone unless the original songs are erased. This should never be done.
One can always add to this list of songs and place them in the folders but there's never a guarantee that you'll get the certain song you want in a specific spot YOU have designed for.
So, you have this perfect place you created, and you want the players to hear only this song. Well, here's how you can do it.

Example: The name of the song will be Ancients.mp3 http://www.mikseri.net/playsong.php?id=158777

1) First, make sure it's an .mp3 and place it in the /Data/Music/Special folder. Don't use any other folder, because dungeon music belongs in the dungeon folder. Special music belongs in the Special folder for Special reasons. Think about it, you don't want anyone to hear that music piece until they get to a certain place, time or whatever it may be.

2) Find out how long the song is in seconds. This is important.

3) Use the following script to create your script , then save the esp. For this example the script name is temporarily aaAKBling01Script.


ScriptName aaAKBling01Scriptfloat fQuestDelayTimefloat timershort wasInCombatbegin gamemode; Makes the script run every 0.5 second to ensure that the music starts to play pretty fast    set fQuestDelayTime to .5; If the player is not in this cell, just return    if (player.getInCell 000AKBlingdenstone==0); your cell you want the music in        set timer to -1        return    endif; Timer counts the time left to start the music again.    set timer to (timer - getSecondsPassed)    ; At the instant the player leaves combat, set timer to -1 to start the music again    if (player.IsInCombat)        if (wasInCombat == 0)            set wasInCombat to 1        endif    elseif (wasInCombat)        set wasInCombat to 0        set timer to -1    endif; If timer  0, the music is still playing, so do nothing    if (timer > 0)        return    endif    ; Start music, and set timer equal to music length in seconds    Streammusic "data\music\special\Ancients.mp3"    set timer to 161;Length of music, in seconds goes hereend; This part is to make sure it continues the music while in menu mode; The code is mostly the same, but with no combat check.begin menumode; If the player is not in this cell, just return    if (player.getInCell 000AKBlingdenstone==0)        set timer to -1        return    endif; If timer  0, the music is still playing, so do nothing    set timer to (timer - getSecondsPassed)    if (timer > 0)        return    endif; Start music, and set timer equal to music length in seconds    Streammusic "data\music\special\Ancients.mp3";your song of choice    set timer to 161end


Don't forget to save!

4) Now open your quest window and right click in the far left column where the quests are listed and choose "New", give the quest an editor ID name and press ok.

5) Highlight the quest you just created if it isn't already. The first 3 boxes that you will see below the tabs are - "Quest Name, Priority, and Script". You don't need a name, but give the quest priority a value of 0. In the Script box, you'll have to find your script you made above and place it as the script being used. For this example, that will be ScriptName aaAKBling01Script.

6) In the same window, check "Start Game Enabled", save the esp.

Now start the game and go check it out.

Note: Even though the construction set has already defined the cell, region or worldspace a default, this script will always override. Yes, it will not stop playing until you remove the script from the mod or the player leaves the area. So be aware of where you place a song at. I recommend that this type use of music is not overly played and placed in a frequently accessed location. Types of locations that would be ideal for this would be BOSS fights, altars, accessible locations only available through quests, or less traveled areas. This use of the scripting is very unique in that it will not alter any cell, regional or worldspace settings in anyway except as it is defined to do in the scripts, and that will be in the area you have defined.

And that's it.

Originally scripted by ShadowLance and TheNiceOne for Underdark.

User avatar
Guy Pearce
 
Posts: 3499
Joined: Sun May 20, 2007 3:08 pm

Post » Fri Apr 08, 2011 2:33 am

Thanks =] Very helpful
User avatar
phil walsh
 
Posts: 3317
Joined: Wed May 16, 2007 8:46 pm


Return to IV - Oblivion