Creating a Music Playlist

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
Warning

These scripts need to be tested, if you tested these scripts, please leave your comment at the discussion page, thanks.


Introduction[edit | edit source]

This tutorial will explain how to create a spell or object that gives you the ability to select a track from a playlist and play it. Our goal is: To be able to play oblivion on our own (sound)track(s) whenever we want, at the end of this tutorial.

Note that this tutorial uses only the vanilla sound function StreamMusic for playing music files. This will probably not work completely in combination with music extensions or overhauls like SoundCommands, Enhanced Music Controls or Better Music System. Refer to the tutorial articles linked in the "See also..." section below to learn how to make this compatible with such mods.

The Music Box[edit | edit source]

How things work: first we need to have some good music. The best format for your music is (probably) .mp3, convert them to .mp3 if they don’t have the .mp3-format. Then we are going to create a new file in this directory:

C:\Program Files\Bethesda Softworks\Oblivion\Data\Music

Create a new file and name it ’’’MyMusic’’’. Now you’re going to select 5 tracks you want to be able to play in-game and place them in your new file. Now we only need to create a script that plays the tracks in this file. We are going to do this with the StreamMusic function. It’s also possible to place tracks in the music files without a script but then you don’t know when Oblivion plays your track because it’s selected randomly.

The scripts[edit | edit source]

Spell Script[edit | edit source]

Scn MusicSpell

Short Choosing
Short Choice
Short MusicChoice

begin OnScriptEffectStart
     if Choosing == 0
          set Choosing to -1
     endif
end

begin Gamemode
     If (Choosing == -1)
          MessageBox "What would you like to do?", "Select Music", "Done"
          set Choosing to 1
          set Choice to GetButtonPressed
     elseif (Choosing == 1)
          if (Choice == -1)
               set Choice to GetButtonPressed
          elseif (Choice == 0)
               Set Choosing to -2
          elseif (Choice == 1)
               Set Choosing to 0
          endif
     Endif

     If (Choosing == -2)
          MessageBox "Wich music would you like to play?", "Name 1", "Name 2", "Name 3", "Name 4", "Name 5", "Back", "Cancel"
          set Choosing to 2
          set MusicChoice to GetButtonPressed
     elseif (Choosing == 2)
          if (MusicChoice == -1)
               set MusicChoice to GetButtonPressed
          elseif (MusicChoice == 0)
               StreamMusic "Data\Music\Name_1.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 1)
               StreamMusic "Data\Music\Name_2.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 2)
               StreamMusic "Data\Music\Name_3.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 3)
               StreamMusic "Data\Music\Name_4.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 4)
               StreamMusic "Data\Music\Name_5.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 5)
               Set Choosing to -1
          elseif (MusicChoice == 6)
               Set Choosing to 0
          endif
     Endif
End

Object Script[edit | edit source]

If you prefer to use it as an object (some kind of Ipod or mp3-player) rather than a spell. The object could be used in the inventory of the player and in-game so the script adds the possibility to drop it or take it.

Scn ObjectSpell

Short Choosing
Short Choice
Short Choice2
Short MusicChoice
Short MusicChoice2

Begin onActivate player
     if Choosing == 0
          set Choosing to -1
     endif
end

Begin onEquip player
     if Choosing == 0
          set Choosing to -3
     endif
end

Begin gameMode
     If (Choosing == -1)
          MessageBox "What would you like to do?", "Take", "Select Music", "Done"
          set Choosing to 1
          set Choice to GetButtonPressed
     elseif (Choosing == 1)
          if (Choice == -1)
               set Choice to GetButtonPressed
          elseif (Choice == 0)
               Activate
               Set Choosing to 0
          elseif (Choice == 1)
               Set Choosing to -2
          elseif (Choice == 2)
               Set Choosing to 0
          endif
     Endif

     If (Choosing == -2)
          MessageBox "Wich music would you like to play?", "Name 1", "Name 2", "Name 3", "Name 4", "Name 5", "Back", "Cancel"
          set Choosing to 2
          set MusicChoice to GetButtonPressed
     elseif (Choosing == 2)
          if (MusicChoice == -1)
               set MusicChoice to GetButtonPressed
          elseif (MusicChoice == 0)
               StreamMusic "Data\Music\Name_1.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 1)
               StreamMusic "Data\Music\Name_2.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 2)
               StreamMusic "Data\Music\Name_3.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 3)
               StreamMusic "Data\Music\Name_4.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 4)
               StreamMusic "Data\Music\Name_5.mp3"
               Set Choosing to -1
          elseif (MusicChoice == 5)
               Set Choosing to -1
          elseif (MusicChoice == 6)
               Set Choosing to 0
          endif
     Endif
End

Begin menuMode
     If (Choosing == -3)
          MessageBox "What would you like to do?", "Drop", "Select Music", "Done"
          set Choosing to 3
          set Choice2 to GetButtonPressed
     elseif (Choosing == 3)
          if (Choice2 == -1)
               set Choice2 to GetButtonPressed
          elseif (Choice2 == 0)
               DropMe
               Set Choosing to 0
          elseif (Choice2 == 1)
               Set Choosing to -4
          elseif (Choice2 == 2)
               Set Choosing to 0
          endif
     Endif
	
     If (Choosing == -4)
          MessageBox "Wich music would you like to play?", "Name 1", "Name 2", "Name 3", "Name 4", "Name 5", "Back", "Cancel"
          set Choosing to 4
          set MusicChoice2 to GetButtonPressed
     elseif (Choosing == 4)
          if (MusicChoice2 == -1)
               set MusicChoice2 to GetButtonPressed
          elseif (MusicChoice2 == 0)
               StreamMusic "Data\Music\Name_1.mp3"
               Set Choosing to -3
          elseif (MusicChoice2 == 1)
               StreamMusic "Data\Music\Name_2.mp3"
               Set Choosing to -3
          elseif (MusicChoice2 == 2)
               StreamMusic "Data\Music\Name_3.mp3"
               Set Choosing to -3
          elseif (MusicChoice2 == 3)
               StreamMusic "Data\Music\Name_4.mp3"
               Set Choosing to -3
          elseif (MusicChoice2 == 4)
               StreamMusic "Data\Music\Name_5.mp3"
               Set Choosing to -3
          elseif (MusicChoice2 == 5)
               Set Choosing to -3
          elseif (MusicChoice2 == 6)
               Set Choosing to 0
          endif
     Endif
End

Troubleshooting[edit | edit source]

It’s also possible to convert the tracks into wav format and play them with the PlaySound function but then there are some problems: If you play a track, you still will be able to hear the original music of TES4 Oblivion. I don’t know how to shut it off so will hear 2 tracks at the same time. Also, if you select another track before the previous track ends, it’s possible you can hear 3 songs or more at the same time, so it’s better if we use the StreamMusic function.

Notes[edit | edit source]

Now you’re able to create your own music file and you know how to create a token or spell to select and play music, you can try creating other things now, eg. a shuffle function to randomly select a track or other functions you would like to add.

See also...[edit | edit source]

Playing custom background music (tutorial about different methods of streaming background music)