Hypn0sef Posted January 29, 2021 Share Posted January 29, 2021 I know there are plenty of music boxes in existing mods, but I'm attempting to make one that can be kept in your inventory and used wherever. My scripting ability is very minimal, but I got the Stroti gramophone converted in NifSkope so you can pick it up. I tried using this script* I found in another forum, but it only worked when dropped and picked up and with the priority of the music track set as 1, the highest, and even then it doesn't stop. I assume it needs to be OnEquip or something rather than OnActivate. (I'm also not insulting this script, it works great on an activator but doesn't perfectly suit my need) Any help would be greatly appreciated and will get you a credit on the mod page *Scriptname AAMusicScript extends ObjectReference ;* Play Music * By: NexusComa * ; nexusmods.com ObjectReference 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 Link to comment Share on other sites More sharing options...
dylbill Posted January 29, 2021 Share Posted January 29, 2021 Since you're using an object that can be picked up, you can simplify the script. You're right, you do need to use the OnEquipped event. What I would do is use a Message form with 2 buttons to enable or disable the music. MusicType Property _MusicTrack Auto Message Property MusicBoxMsg auto Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() If MusicBoxMsg.Show() == 0 _MusicTrack.Remove() Else _MusicTrack.Add() Endif Endif EndEvent If you want to add more track selections, you can use an array and do something like this: MusicType[] Property _MusicTracks Auto Message Property MusicBoxMsg auto MusicType CurrentTrack Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() CurrentTrack.Remove() ;stop playing current track Int Button = MusicBoxMsg.Show() If Button <= 8 ;make Message button 9 as a Stop button. CurrentTrack = _MusicTracks[Button] CurrentTrack.Add() ;start playing new selected track Endif Endif EndEvent Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 Awesome thank you! I'm gonna try this out right now Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 Okay so the first script is ideal for me, but for some reason the music doesn't stop when I try and activate it a second time. Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 That's the same issue I ran into with the original script and you'd think since its an 'if xmarker is enabled or not' would fix that Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 I just tried * and it didn't even play the music so there goes that theory lol *MusicType Property _MusicTrack AutoObjectReference Property Marker Auto Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() If(Marker.IsDisabled()) _MusicTrack.Remove() Else _MusicTrack.Add() Endif EndifEndEvent Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 Scratch that, it does play the music, but still doesn't stop! I'm doomed to perpetual classical music Link to comment Share on other sites More sharing options...
dylbill Posted January 30, 2021 Share Posted January 30, 2021 It keeps playing because you're not disabling or enabling the marker in the script. Instead of using an marker in this case, I would use a bool instead: MusicType Property _MusicTrack Auto Bool Property Playing = False Auto Hidden Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() If Playing == True Playing = False _MusicTrack.Remove() Else Playing = True _MusicTrack.Add() Endif Endif EndEventEdit: The hidden tag just means the property won't show in the Creation kit. Link to comment Share on other sites More sharing options...
Hypn0sef Posted January 30, 2021 Author Share Posted January 30, 2021 I realized that after I posted and tried a variant with my attempt at having it enable and disable the marker but that also didn't work, likely due to my scripting ability and not any issue with the concept. Awesome I'll try that way, thanks again! Link to comment Share on other sites More sharing options...
dylbill Posted January 30, 2021 Share Posted January 30, 2021 No problem :) the enable / disable might not have worked if your property wasn't filled, but again for this I think using a bool would be better. I haven't ever used the MusicTrack.Add and remove functions before so I can't really say how well they work. Link to comment Share on other sites More sharing options...
Recommended Posts