NiceCrispPieceOfMeat Posted September 28, 2020 Share Posted September 28, 2020 I'm an absolute beginner modder (no scripting experience) and I need help on writing an audio script for my house mod. Basically there's a lute which players can activate and listen to some music, sort of like a music box. When it's activated, a menu pops up and you can choose which song to play. Numerous tutorials later I finally figured out the correct script to make it work as intended, but I still want to implement one function on the menu: a button that stops whatever music its playing. Is it possible? Are there any tutorials out there that can point me in the right direction? Thanks.Here's my script: Scriptname ActivateLute extends ObjectReference Message property LuteMusicMenu auto Sound property mySFX1 auto Sound property mySFX2 auto Sound property mySFX3 auto Sound property mySFX4 auto Sound property mySFX5 auto Sound property mySFX6 auto Event OnActivate(ObjectReference akActionRef) Menu() EndEvent Function menu(int aiButton = 0) aiButton = LuteMusicMenu.show() If aiButton == 0 ElseIf aiButton == 1 int instanceID = mySFX1.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 2 int instanceID = mySFX2.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 3 int instanceID = mySFX3.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 4 int instanceID = mySFX4.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 5 int instanceID = mySFX5.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 6 int instanceID = mySFX6.play(self) Sound.SetInstanceVolume(instanceID, 1.0) EndIf EndFunction Link to comment Share on other sites More sharing options...
Reneer Posted September 28, 2020 Share Posted September 28, 2020 You will want to use StopInstance for your script. Link to comment Share on other sites More sharing options...
dylbill Posted September 28, 2020 Share Posted September 28, 2020 What Reneer said. This is how I'd do it: Message property LuteMusicMenu auto Sound property mySFX1 auto Sound property mySFX2 auto Sound property mySFX3 auto Sound property mySFX4 auto Sound property mySFX5 auto Sound property mySFX6 auto Event OnActivate(ObjectReference akActionRef) Menu() EndEvent Int instanceID Function menu(int aiButton = 0) aiButton = LuteMusicMenu.show() If aiButton == 0 Else Sound.StopInstance(instanceID) If aiButton == 1 instanceID = mySFX1.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 2 instanceID = mySFX2.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 3 instanceID = mySFX3.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 4 instanceID = mySFX4.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 5 instanceID = mySFX5.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 6 instanceID = mySFX6.play(self) Sound.SetInstanceVolume(instanceID, 1.0) Endif EndIf EndFunctionWith this modification, it will stop the current song before playing another one. You can also add a button on the end and it will stop the current song without playing another one. Link to comment Share on other sites More sharing options...
NexusComa2 Posted September 28, 2020 Share Posted September 28, 2020 (edited) In my mod Enchanted Ship in a Bottle there is a phonograph that is doing just what your lute is doing. It runs 10 setup tracks and has 10 more (as loose files) that can be customized. Spent a lot of time perfecting the player. You are welcome to download the mod and take a look at it in the Creation Kit. Also there is a separate download for all the scripts in the mod. They are pretty extensive. I'm sure you will find a few things useful. The phonograph /player script is also with them. Edited September 28, 2020 by NexusComa2 Link to comment Share on other sites More sharing options...
NiceCrispPieceOfMeat Posted September 28, 2020 Author Share Posted September 28, 2020 (edited) You will want to use StopInstance for your script. What Reneer said. This is how I'd do it: Message property LuteMusicMenu auto Sound property mySFX1 auto Sound property mySFX2 auto Sound property mySFX3 auto Sound property mySFX4 auto Sound property mySFX5 auto Sound property mySFX6 auto Event OnActivate(ObjectReference akActionRef) Menu() EndEvent Int instanceID Function menu(int aiButton = 0) aiButton = LuteMusicMenu.show() If aiButton == 0 Else Sound.StopInstance(instanceID) If aiButton == 1 instanceID = mySFX1.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 2 instanceID = mySFX2.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 3 instanceID = mySFX3.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 4 instanceID = mySFX4.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 5 instanceID = mySFX5.play(self) Sound.SetInstanceVolume(instanceID, 1.0) ElseIf aiButton == 6 instanceID = mySFX6.play(self) Sound.SetInstanceVolume(instanceID, 1.0) Endif EndIf EndFunctionWith this modification, it will stop the current song before playing another one. You can also add a button on the end and it will stop the current song without playing another one.Thank you! Everything works as intended now. I've added another button on the end to stop music as well. Thanks for the help. Edited September 28, 2020 by NiceCrispPieceOfMeat Link to comment Share on other sites More sharing options...
NiceCrispPieceOfMeat Posted September 28, 2020 Author Share Posted September 28, 2020 In my mod Enchanted Ship in a Bottle there is a phonograph that is doing just what your lute is doing. It runs 10 setup tracks and has 10 more (as loose files) that can be customized. Spent a lot of time perfecting the player. You are welcome to download the mod and take a look at it in the Creation Kit. Also there is a separate download for all the scripts in the mod. They are pretty extensive. I'm sure you will find a few things useful. The phonograph /player script is also with them. Your house mod looks amazing! Definitely gonna add it onto my mod list. I'll take a look at the scripts as soon as it finishes downloading. Didn't know you could make music tracks customizable. I'll credit you if I end up using any scripts from your mod. Thanks for the help! Link to comment Share on other sites More sharing options...
dylbill Posted September 28, 2020 Share Posted September 28, 2020 No problem, happy modding! Link to comment Share on other sites More sharing options...
NexusComa2 Posted September 28, 2020 Share Posted September 28, 2020 (edited) Mine don't look anything like that. It looks as if you're playing sounds not music tracks. Or maybe playing music tracks as sounds. The way I went about it was to create music tracks then put them into a playlist with multiple tracks. Then I used the Skyrim music system to play the list(s). I used a XMarker to set the script flow and this is the script on the switch. This is a double fault script as in it corrects itself based on the state of the XMarker ... Meaning you can have more than one player script set up to be switches with a different playlists and they will all be able to work together (and they all use this same script). Short sweet and simple. Take a look at my mod to see how to set up the tracks. Scriptname _RGD_MusicPlayer extends ObjectReference;* Play Music * By: NexusComa * ; nexusmods.comObjectReference Property Marker AutoMusicType Property _MusicTrack AutoMusicType Property _NONE Auto;Event OnInit()Marker.Disable()GoToState("Switch")EndEvent;-----------------------State Switch Event OnActivate(ObjectReference akActionRef) If(Marker.IsDisabled()) _Enable() Else _Disable() EndIf EndEventEndState;-----------------------Function _Enable() Marker.Enable() _MusicTrack.Add() Utility.Wait(1.0) _NONE.Remove()EndFunction;-----------------------Function _Disable() Marker.Disable() _NONE.Add() Utility.Wait(1.0) _MusicTrack.Remove()EndFunction; You don't even really need the actual tracks as this whole thing can be set up by setting up a bunch of mock tracks (one second of silence) by known names. exp: track1, track2, track3 ... Then you can add the tracks in as loose files. The advantage of this is they can add their own tracks as long as they are named the same as the loose files.I messed around with this for a long time. To get that fade in and out effect the Skyrim music has.This isn't a workaround. This is actually how the game plays music. When you leave the area the music will change just as it normally would. The music is simply on a on/off switch(s) in this area. If you look at how it's set up in the mod it will all become clear. One little trick I stumbled on was: If you set the music file in the Creation Kit as a .wav file it will play both the .wav or .xvm version of the named music file. The .xvm version defaults over the .wav file if in the same folder. In the ship mod I created a .bsa using mock .wav tracks (as stated above) to create the defined playlist used for the script. Then for the playable version placed .xvm tracks by the same name in data\music\...This let me have multiple large tracks as "music pack(s)" without adding to the mod size. I was having fun with all this and did both versions in that mod. 10 defined and 10 customizable. This tool may be useful to you ... Skyrim Audio Converter. This method does not need to be so complicated. I was going for customizable tracks. The real trick is setting the music file up correctly in the Creation Kit. That can be done easy with a few tracks that are apart of the .bsa also. As for what you're going for both methods look like they would work. The script by Reneer would have its advantages ... It could be placed in a sound object (little green speaker marker in the CK) and that would give you a great real time 3d sound effect. It would also play over/with the background game music. That may or may not be an advantage depending on how you look at it or have it set up. Good Luck. Edited September 28, 2020 by NexusComa2 Link to comment Share on other sites More sharing options...
Recommended Posts